-
Notifications
You must be signed in to change notification settings - Fork 22
Allow passing URLs and archive paths to --workspace and deprcecate --… #34
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| import json | ||
| import os | ||
| import shutil | ||
|
|
||
| import click | ||
| import requests | ||
| import six | ||
|
|
||
| from gradient import exceptions | ||
|
|
||
|
|
||
| def get_terminal_lines(fallback=48): | ||
| if six.PY3: | ||
|
|
@@ -32,4 +36,58 @@ def status_code_to_error_obj(status_code): | |
| message = 'unknown' | ||
| if status_code in requests.status_codes._codes: | ||
| message = requests.status_codes._codes[status_code][0] | ||
| return { 'error': True, 'message': message, 'status': status_code } | ||
| return { 'error': True, 'message': message, 'status': status_code } | ||
|
|
||
|
|
||
| class PathParser(object): | ||
| LOCAL_DIR = 0 | ||
| LOCAL_FILE = 1 | ||
| GIT_URL = 2 | ||
| S3_URL = 3 | ||
|
|
||
| @classmethod | ||
| def parse_path(cls, path): | ||
| if cls.is_local_dir(path): | ||
| return cls.LOCAL_DIR | ||
|
|
||
| if cls.is_local_zip_file(path): | ||
| return cls.LOCAL_FILE | ||
|
|
||
| if cls.is_git_url(path): | ||
| return cls.GIT_URL | ||
|
|
||
| if cls.is_s3_url(path): | ||
| return cls.S3_URL | ||
|
|
||
| raise exceptions.WrongPathError("Given path is neither local path, nor valid URL") | ||
|
|
||
| @staticmethod | ||
| def is_local_dir(path): | ||
| return os.path.exists(path) and os.path.isdir(path) | ||
|
|
||
| @staticmethod | ||
| def is_local_zip_file(path): | ||
| return os.path.exists(path) and os.path.isfile(path) and path.endswith(".zip") | ||
|
|
||
| @staticmethod | ||
| def is_git_url(path): | ||
| return not os.path.exists(path) and path.endswith(".git") or path.lower().startswith("git:") | ||
|
|
||
| @staticmethod | ||
| def is_s3_url(path): | ||
| return not os.path.exists(path) and path.lower().startswith("s3:") | ||
|
|
||
|
|
||
| def validate_workspace_input(input_data): | ||
| workspace_url = input_data.get('workspaceUrl') | ||
| workspace_path = input_data.get('workspace') | ||
| workspace_archive = input_data.get('workspaceArchive') | ||
|
|
||
| if (workspace_archive and workspace_path) \ | ||
| or (workspace_archive and workspace_url) \ | ||
| or (workspace_path and workspace_url): | ||
| raise click.UsageError("Use either:\n\t--workspace https://path.to/git/repository.git - to point repository URL" | ||
| "\n\t--workspace /path/to/local/directory - to point on project directory" | ||
| "\n\t--workspace /path/to/local/archive.zip - to point on project .zip archive" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more naturally this would be something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed in PS-10553
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks @BartoszCki! |
||
| "\n\t--workspace none - to use no workspace" | ||
| "\n or neither to use current directory") | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more naturally this would be something like
to point to a project directoryorto use a local directory as your workspace:)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS-10553
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @BartoszCki!