Merge branch 'master' into master

This commit is contained in:
Anton Hvornum 2020-11-02 20:19:35 +01:00 committed by GitHub
commit 77f69f844b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 17 deletions

View File

@ -29,17 +29,17 @@ def find_examples():
def find(url): def find(url):
parsed_url = urlparse(url) parsed_url = urlparse(url)
if not parsed_url.scheme: if not parsed_url.scheme:
examples = find_examples() examples = find_examples()
if f"{url}.py" in examples: if f"{url}.py" in examples:
return open(examples[f"{url}.py"]).read() return open(examples[f"{url}.py"]).read()
try: try:
return open(url, 'r').read() return open(url, 'r').read()
except FileNotFoundError: except FileNotFoundError:
return ProfileNotFound(f"File {url} does not exist") return ProfileNotFound(f"File {url} does not exist")
elif parsed_url.scheme in ('https', 'http'): elif parsed_url.scheme in ('https', 'http'):
return urllib.request.urlopen(url).read().decode('utf-8') return urllib.request.urlopen(url).read().decode('utf-8')
else: else:
return ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}") return ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}")
def run_as_a_module(): def run_as_a_module():
@ -48,21 +48,24 @@ def run_as_a_module():
a nuitka3 compiled version of the project. a nuitka3 compiled version of the project.
This function and the file __main__ acts as a entry point. This function and the file __main__ acts as a entry point.
""" """
if len(sys.argv) == 1: if len(sys.argv) == 1:
sys.argv.append('guided') sys.argv.append('guided')
try: try:
profile = find(sys.argv[1]) profile = find(sys.argv[1])
except ProfileNotFound as err: except ProfileNotFound as err:
print(f"Couldn't find file: {err}") print(f"Couldn't find file: {err}")
sys.exit(1) sys.exit(1)
os.chdir(os.path.abspath(os.path.dirname(__file__)))
try: try:
exec(profile) # Is this is very safe? exec(profile) # Is this is very safe?
except Exception as err: except Exception as err:
print(f"Failed to run profile... {err}") print(f"Failed to run profile... {err}")
sys.exit(1) # Should prompt for another profile path instead sys.exit(1) # Should prompt for another profile path instead
if __name__ == '__main__': if __name__ == '__main__':
run_as_a_module() run_as_a_module()