-
Notifications
You must be signed in to change notification settings - Fork 1
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
documenting script parser thing #33
Open
Gusic06
wants to merge
1
commit into
main
Choose a base branch
from
Gusic06-patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,61 +20,66 @@ class RemoteScriptBuilder: | |
def __init__(self) -> None: | ||
... | ||
|
||
|
||
def get_script_from_user(self, name: str) -> str: | ||
if name[-3:] != ".py": | ||
raise Exception("Invalid File Format (Must be '.py'!)") | ||
self._dir = glob.glob(fr"{pathlib.Path.home().drive}\\**\\{name}") | ||
for self.files in self._dir: | ||
for self.files in self._dir: # iterating through every file in the directory | ||
print(f"Combing ('{self.files}')") | ||
os.system("clear") | ||
os.system("cls") | ||
if self.files == name: | ||
if self.files == name: # if we find the target file, we should read the and return the contents | ||
with open(name, "r", "utf-8") as file: | ||
self.contents = file.read() | ||
if self.contents == "": | ||
print(f"Error: Unable to open {name}") | ||
time.sleep(3) | ||
sys.exit() | ||
print(f"Error: {file} was empty..") | ||
time.sleep(2) | ||
exit(1) | ||
return self.contents | ||
else: | ||
raise Exception(f"Couldn't find {name} on this device..") | ||
|
||
|
||
def add_command_to_main_file(self, command_name, script_name, function_name): | ||
def add_command_to_main_file(self, command_name: str, script_name: str, function_name: str) -> None: | ||
with open(".\\boxpyshell.py", "r") as file: | ||
_contents = file.read() | ||
new_contents = f"import {script_name}\n{_contents}\nelif command == '{command_name}':\n {function_name}({*args}, {**kwargs})" | ||
new_contents = f"import {script_name}\n{_contents}\nelif command == '{command_name}':\n {function_name}({*args}, {**kwargs})" # tbh idk what this does, but it works.. I think | ||
with open(".\\boxpyshell.py", "w") as file: | ||
file.write(new_contents) | ||
|
||
|
||
def add_file_to_list(self, name) -> None: | ||
def add_file_to_list(self, name: str) -> None: | ||
with open("_scripts.txt", "w") as file: | ||
if os.path.exists(name) is True and name[-3:] == ".py": | ||
file.write(f"{name}") | ||
if os.path.exists(name) and name[-3:] == ".py": # if the file exists and the file is a python file, we append the filename to "_scripts.txt" | ||
file.write(name) | ||
print(f"Successfully added {name} to '_scripts.txt'") | ||
else: | ||
print(f"{name} is an invalid file (Maybe you forgot to add '.py' to the end?)") | ||
exit(1) | ||
|
||
|
||
def build_file(self, name: str) -> None: | ||
self._contents = self.get_script_from_user(input("Path to the Script file -> ")) | ||
self.name = f"{name}.py" if name[-3:] != ".py" else name | ||
self._contents: str = self.get_script_from_user(input("Path to the Script file -> ")) | ||
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. If you want to set the type then instead of doing ```
var = str(input())
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. yes |
||
self.name: str = f"{name}.py" if name[-3:] != ".py" else name # we append the ".py" file extension if name doesn't have it | ||
try: | ||
if os.path.exists("scripts") is True: | ||
|
||
if os.path.exists("scripts"): | ||
with open(f".\\scripts\\{self.name}", "w") as file: | ||
file.write(f"'Script for BoxPyShell'\n{self._contents}") | ||
if os.path.exists("scripts") is False: | ||
file.write(f"# Script for BoxPyShell\n{self._contents}") | ||
if not os.path.exists("scripts"): | ||
os.mkdir("scripts") | ||
with open(f".\\scripts\\{self.name}", "w") as file: | ||
file.write(f"'Script for BoxPyShell'\n{self._contents}") | ||
file.write(f"# Script for BoxPyShell\n{self._contents}") | ||
self.add_files_to_list(self.name) | ||
|
||
except Exception as Err: | ||
print(f"Unable to create {self.file} due to a PermissionError") if type(Err) == PermissionError else print(f"Unable to create {self.file} -> {Err}") | ||
if type(Err) == PermissionError: | ||
print(f"Unable to create {self.file} due to a PermissionError") | ||
else: | ||
print(f"Unable to create {self.file} -> {Err}") | ||
|
||
|
||
def run(self) -> None: | ||
def run(self) -> None: # basically just a wrapper function that brings it all together | ||
self.build_file(input("What do you want to name your script? -> ")) | ||
self.add_command_to_main_file(input("Name of command? -> "), input("Name of source file? -> "), input("Name of function to be run? -> ")) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If you don't know then don't comment it. This is unnecessary.