Skip to content

Commit

Permalink
Merge pull request #102 from jahanvir/package-zip
Browse files Browse the repository at this point in the history
added zip function in textbase cli tool
  • Loading branch information
sammyCofactory authored Sep 8, 2023
2 parents 58fa7f3 + f15c0a5 commit ba237aa
Showing 1 changed file with 26 additions and 1 deletion.
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

0 comments on commit ba237aa

Please sign in to comment.