mirror of https://github.com/kiwix/libkiwix.git
Using global variables for base & output directories
This commit is contained in:
parent
157f01e951
commit
03ab2f67dd
|
@ -81,13 +81,13 @@ def symlink_resource(src, resource_path):
|
||||||
os.remove(resource_path)
|
os.remove(resource_path)
|
||||||
os.symlink(src, resource_path)
|
os.symlink(src, resource_path)
|
||||||
|
|
||||||
def preprocess_resource(srcdir, resource_path, outdir):
|
def preprocess_resource(resource_path):
|
||||||
print('Preprocessing', resource_path, '...')
|
print('Preprocessing', resource_path, '...')
|
||||||
resource_dir = os.path.dirname(resource_path)
|
resource_dir = os.path.dirname(resource_path)
|
||||||
if resource_dir != '':
|
if resource_dir != '':
|
||||||
os.makedirs(os.path.join(outdir, resource_dir), exist_ok=True)
|
os.makedirs(os.path.join(OUT_DIR, resource_dir), exist_ok=True)
|
||||||
srcpath = os.path.join(srcdir, resource_path)
|
srcpath = os.path.join(BASE_DIR, resource_path)
|
||||||
outpath = os.path.join(outdir, resource_path)
|
outpath = os.path.join(OUT_DIR, resource_path)
|
||||||
if os.path.exists(outpath):
|
if os.path.exists(outpath):
|
||||||
os.remove(outpath)
|
os.remove(outpath)
|
||||||
preprocessed_content, modified_line_count = get_preprocessed_resource(srcpath)
|
preprocessed_content, modified_line_count = get_preprocessed_resource(srcpath)
|
||||||
|
@ -103,11 +103,11 @@ def copy_file(src_path, dst_path):
|
||||||
with open(dst_path, 'wb') as dst:
|
with open(dst_path, 'wb') as dst:
|
||||||
dst.write(src.read())
|
dst.write(src.read())
|
||||||
|
|
||||||
def preprocess_resources(resource_file_path, outdir):
|
def preprocess_resources(resource_file_path):
|
||||||
resource_filename = os.path.basename(resource_file_path)
|
resource_filename = os.path.basename(resource_file_path)
|
||||||
for resource in read_resource_file(resource_file_path):
|
for resource in read_resource_file(resource_file_path):
|
||||||
preprocess_resource(BASE_DIR, resource, outdir)
|
preprocess_resource(resource)
|
||||||
copy_file(resource_file_path, os.path.join(outdir, resource_filename))
|
copy_file(resource_file_path, os.path.join(OUT_DIR, resource_filename))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -118,8 +118,9 @@ if __name__ == "__main__":
|
||||||
parser.add_argument('resource_file')
|
parser.add_argument('resource_file')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
BASE_DIR = os.path.dirname(os.path.realpath(args.resource_file))
|
BASE_DIR = os.path.dirname(os.path.realpath(args.resource_file))
|
||||||
|
OUT_DIR = args.outdir
|
||||||
|
|
||||||
if args.list_all:
|
if args.list_all:
|
||||||
list_resources(args.resource_file)
|
list_resources(args.resource_file)
|
||||||
elif args.preprocess:
|
elif args.preprocess:
|
||||||
preprocess_resources(args.resource_file, args.outdir)
|
preprocess_resources(args.resource_file)
|
||||||
|
|
Loading…
Reference in New Issue