Skip to content

Commit d8b2894

Browse files
Add base directory option to split.py
Overrides the directory to look for libraries.
1 parent 87feeea commit d8b2894

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

split.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def walk_dir(file_name, directory):
2020
return walk_dir(file_name, os.path.join(root, subdir))
2121

2222

23-
def locate_file(file_name, search_dirs):
24-
cur_dir = os.path.dirname(sys.argv[0])
23+
def locate_file(file_name, search_dirs, base_directory=None):
24+
cur_dir = base_directory or os.path.dirname(sys.argv[0])
2525
initial_path = os.path.join(cur_dir, file_name)
2626

2727
if os.path.isfile(initial_path):
@@ -35,10 +35,10 @@ def locate_file(file_name, search_dirs):
3535
return None
3636

3737

38-
def split(lib_name, search_dirs=[], extension="cc", out="out"):
38+
def split(lib_name, search_dirs=[], extension="cc", out="out", base_directory=None):
3939
header_name = lib_name + ".h"
4040
source_name = lib_name + "." + extension
41-
in_file = locate_file(header_name, search_dirs)
41+
in_file = locate_file(header_name, search_dirs, base_directory)
4242
if not in_file:
4343
print("File not found: {}".format(header_name))
4444
return
@@ -104,13 +104,24 @@ def main():
104104
dest="libraries",
105105
help="the libraries to split (default: [httplib])",
106106
)
107+
args_parser.add_argument(
108+
"-b",
109+
"--base-directory",
110+
help="where to look for files (default: <script directory>)",
111+
)
107112
args = args_parser.parse_args()
108113

109114
default_libraries = ["httplib"]
110115
search_dirs = ["example"]
111116

112117
for lib_name in args.libraries or default_libraries:
113-
split(lib_name, search_dirs, args.extension, args.out)
118+
split(
119+
lib_name,
120+
search_dirs,
121+
args.extension,
122+
args.out,
123+
args.base_directory,
124+
)
114125

115126

116127
if __name__ == "__main__":

0 commit comments

Comments
 (0)