Skip to content

Commit

Permalink
Merge pull request #17 from Rog3rSm1th/hotfix
Browse files Browse the repository at this point in the history
Allow to load input files from subdirectories, fix #16
  • Loading branch information
Rog3rSm1th committed Mar 21, 2022
2 parents b38ad38 + 8132efa commit e8840b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions frelatage/_input.py
Expand Up @@ -37,10 +37,10 @@ def init_input_folder(self) -> bool:
# /tmp/frelatage/<thread>/<argument position>
argument_directory = os.path.join(thread_directory, str(i))
os.makedirs(argument_directory)
# ./in/<filename>
# ./in/<any subfolder>/<filename>
input_file = os.path.join(start_input_directory, filenames[i])
# /tmp/frelatage/<thread>/<argument position>/<filename>
output_file = os.path.join(argument_directory, filenames[i])
output_file = os.path.join(argument_directory, os.path.basename(filenames[i]))
shutil.copyfile(input_file, output_file)
return True

Expand All @@ -62,7 +62,7 @@ def init_file_input_arguments(self) -> bool:
base_directory=self.config.FRELATAGE_INPUT_FILE_TMP_DIR,
thread="0",
position=str(i),
filename=self.arguments[i].value
filename=os.path.basename(self.arguments[i].value)
)
file_input_arguments_count+= 1
return True
Expand Down
12 changes: 9 additions & 3 deletions frelatage/corpus/corpus.py
Expand Up @@ -11,10 +11,16 @@ def load_corpus(directory: str, file_extensions: list = []) -> list[Input]:
"""
inputs = []

# ./<input directory>
# ./in by default
input_root_directory = os.path.join(
os.path.dirname(os.path.realpath(sys.argv[0])),
Config.FRELATAGE_INPUT_DIR
)

# ./<input directory>/<subdirectory>
input_directory = os.path.join(
os.path.dirname(os.path.realpath(sys.argv[0])),
Config.FRELATAGE_INPUT_DIR,
input_root_directory,
directory
)

Expand All @@ -28,7 +34,7 @@ def load_corpus(directory: str, file_extensions: list = []) -> list[Input]:
file_inputs += glob.glob(os.path.join(input_directory, "*.{extension}".format(extension=file_extension)))

# Relative path
file_inputs = [os.path.relpath(file_input, input_directory) for file_input in file_inputs]
file_inputs = [os.path.relpath(file_input, input_root_directory) for file_input in file_inputs]

# Create an Input object for every file in the subdirectory
for file_input in file_inputs:
Expand Down

0 comments on commit e8840b9

Please sign in to comment.