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

Modified main.py to automatically attempt to cleanup previous fractions in given path #27

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ def handle_args(parser: argparse.ArgumentParser):
"--rm-backup", action="store_true", help="Remove the generated backup file"
)

def handle_cleanup(fractionator: Fractionator, path: str) -> None:
fractionator.load_backup(backup_path)
fractionator.clean_fractions()

try:
os.remove(path)
except FileNotFoundError:
logging.critical(f"{path} is not a valid file.")
return

if __name__ == "__main__":
parser = argparse.ArgumentParser()
handle_args(parser)
Expand All @@ -76,33 +85,25 @@ def finish_request(self, request, client_address):
backup_path = os.path.join(out_path, BACKUP_FILENAME) # backup file path


lkm = Fractionator("", out_path, key)
# Clean mode
if args.clean:
lkm.load_backup(backup_path)
lkm.clean_fractions()
fractionator = Fractionator("", out_path, key)

handle_cleanup(fractionator, backup_path)
if args.clean: exit(0)

try:
os.remove(backup_path)
except FileNotFoundError:
logging.critical(f"{backup_path} is not a valid file.")
exit(1)
exit(0)

else:
if not args.file:
raise ValueError("The --file flag is required for this mode.")
file_path = os.path.abspath(args.file)
_, ext = os.path.splitext(file_path)
if ext != ".ko":
raise ValueError(f"Invalid file type")
# TODO: Implement path validation
lkm._path = args.file
lkm.make_fractions()
lkm.write_fractions()
lkm.save_backup(backup_path)

if not args.file:
raise ValueError("The --file flag is required for this mode.")
file_path = os.path.abspath(args.file)
_, ext = os.path.splitext(file_path)
if ext != ".ko":
raise ValueError(f"Invalid file type")

# TODO: Implement path validation
fractionator._path = args.file
fractionator.make_fractions()
fractionator.write_fractions()
fractionator.save_backup(backup_path)


# lkm.close_stream()

# Stage fractions over HTTP
Expand Down
Loading