Skip to content

Commit c7e1792

Browse files
veloman-yunkanmgautierfr
authored andcommitted
Using global variables for base & output directories
1 parent f7aaf26 commit c7e1792

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

scripts/kiwix-resources

+9-8
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ def symlink_resource(src, resource_path):
8181
os.remove(resource_path)
8282
os.symlink(src, resource_path)
8383

84-
def preprocess_resource(srcdir, resource_path, outdir):
84+
def preprocess_resource(resource_path):
8585
print('Preprocessing', resource_path, '...')
8686
resource_dir = os.path.dirname(resource_path)
8787
if resource_dir != '':
88-
os.makedirs(os.path.join(outdir, resource_dir), exist_ok=True)
89-
srcpath = os.path.join(srcdir, resource_path)
90-
outpath = os.path.join(outdir, resource_path)
88+
os.makedirs(os.path.join(OUT_DIR, resource_dir), exist_ok=True)
89+
srcpath = os.path.join(BASE_DIR, resource_path)
90+
outpath = os.path.join(OUT_DIR, resource_path)
9191
if os.path.exists(outpath):
9292
os.remove(outpath)
9393
preprocessed_content, modified_line_count = get_preprocessed_resource(srcpath)
@@ -103,11 +103,11 @@ def copy_file(src_path, dst_path):
103103
with open(dst_path, 'wb') as dst:
104104
dst.write(src.read())
105105

106-
def preprocess_resources(resource_file_path, outdir):
106+
def preprocess_resources(resource_file_path):
107107
resource_filename = os.path.basename(resource_file_path)
108108
for resource in read_resource_file(resource_file_path):
109-
preprocess_resource(BASE_DIR, resource, outdir)
110-
copy_file(resource_file_path, os.path.join(outdir, resource_filename))
109+
preprocess_resource(resource)
110+
copy_file(resource_file_path, os.path.join(OUT_DIR, resource_filename))
111111

112112
if __name__ == "__main__":
113113
parser = argparse.ArgumentParser()
@@ -118,8 +118,9 @@ if __name__ == "__main__":
118118
parser.add_argument('resource_file')
119119
args = parser.parse_args()
120120
BASE_DIR = os.path.dirname(os.path.realpath(args.resource_file))
121+
OUT_DIR = args.outdir
121122

122123
if args.list_all:
123124
list_resources(args.resource_file)
124125
elif args.preprocess:
125-
preprocess_resources(args.resource_file, args.outdir)
126+
preprocess_resources(args.resource_file)

0 commit comments

Comments
 (0)