Skip to content

Commit

Permalink
feat(patch_applicator): add -from-configuration-file flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Dec 15, 2023
1 parent 4c3edc2 commit b028f50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions discopop_library/PatchApplicator/PatchApplicatorArguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This software may be modified and distributed under the terms of
# the 3-Clause BSD License. See the LICENSE file in the package base
# directory for details.
import json
import sys
from dataclasses import dataclass
from typing import List
Expand All @@ -20,8 +21,11 @@ class PatchApplicatorArguments(object):
clear: bool
load: bool
list: bool
from_configuration_file: str

def __post_init__(self):
if self.from_configuration_file != "None":
self.__translate_from_configuration_file()
self.__validate()

def __validate(self):
Expand All @@ -48,3 +52,9 @@ def __validate(self):
if exit_required:
print("Exiting.")
sys.exit(0)

def __translate_from_configuration_file(self):
with open(self.from_configuration_file, "r") as f:
config = json.load(f)
self.apply = [str(config["pattern_id"])]
self.from_configuration_file = "None"
5 changes: 5 additions & 0 deletions discopop_library/PatchApplicator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def parse_args() -> PatchApplicatorArguments:
parser.add_argument('-C', '--clear', action="store_true", help="Reset the code to it's original state. Preserves "
"the list of applied suggestion for loading."
"Old saves will be overwritten!")
parser.add_argument(
"-fcf", "--from-configuration-file", type=str, default="None",
help="Apply patch described by the given configuration file."
)
# todo: in the long run, saving configurations to different locations could be easily implemented.

parser.add_argument('-L', '--load', action="store_true", help="Load a previous state after clearing.")
Expand All @@ -49,6 +53,7 @@ def parse_args() -> PatchApplicatorArguments:
clear=arguments.clear,
load=arguments.load,
list=arguments.list,
from_configuration_file=arguments.from_configuration_file,
)


Expand Down

0 comments on commit b028f50

Please sign in to comment.