Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added zip function in textbase cli tool #102

Merged
merged 8 commits into from
Sep 8, 2023
27 changes: 26 additions & 1 deletion textbase/textbase_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from yaspin import yaspin
import importlib.resources
import re
import zipfile
import urllib.parse
from textbase.utils.logs import fetch_and_display_logs


CLOUD_URL = "https://us-east1-chat-agents.cloudfunctions.net/deploy-from-cli"
UPLOAD_URL = "https://us-east1-chat-agents.cloudfunctions.net/upload-file"

Expand Down Expand Up @@ -60,6 +60,30 @@ def test(path, port):
process_local_ui.kill()
click.secho("Server stopped.", fg='red')

#################################################################################################################
def fileExist(path):
if not os.path.exists(os.path.join(path, "main.py")):
click.echo(click.style(f"Error: main.py not found in {path} directory.", fg='red'))
return False
if not os.path.exists(os.path.join(path, "requirements.txt")):
click.echo(click.style(f"Error: requirements.txt not found in {path} directory.", fg='red'))
return False
return True

@cli.command()
@click.option("--path", prompt="Path to the directory containing main.py and requirements.txt file", required=True)
def compress(path):
click.echo(click.style(f"Creating zip file for deployment", fg='green'))
output_zip_filename = 'deploy.zip'
if fileExist(path):
with zipfile.ZipFile(output_zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(path):
for file in files:
if file != output_zip_filename:
file_path = os.path.join(root, file)
# Add the file to the zip archive
zipf.write(file_path, os.path.relpath(file_path, path))
click.echo(click.style(f"Files have been zipped to {output_zip_filename}", fg='green'))

#################################################################################################################
def validate_bot_name(ctx, param, value):
Expand All @@ -69,6 +93,7 @@ def validate_bot_name(ctx, param, value):
raise click.BadParameter(error_message)
return value


@cli.command()
@click.option("--path", prompt="Path to the zip folder", required=True)
@click.option("--bot_name", prompt="Name of the bot", required=True, callback=validate_bot_name)
Expand Down