A configuration setting to use relative symbolic links

Edit the copy function in utils.py to take the parameter rellink and if
it is true, create links relative to the source directory. Modify
gallery.py and __init__.py to pass along this parameter. Add rel_link
flag to setting.py
This commit is contained in:
max (maauer)
2019-01-31 09:31:47 -05:00
parent 2e9ffd9ec0
commit 031f9768de
4 changed files with 8 additions and 4 deletions

View File

@@ -153,7 +153,7 @@ def build(source, destination, debug, verbose, force, config, theme, title,
src = os.path.join(settings['source'], src)
dst = os.path.join(settings['destination'], dst)
logger.debug('Copy %s to %s', src, dst)
copy(src, dst, symlink=settings['orig_link'])
copy(src, dst, symlink=settings['orig_link'], rellink=settings['rel_link'])
stats = gal.stats

View File

@@ -113,7 +113,7 @@ class Media:
check_or_create_dir(orig_path)
big_path = join(orig_path, self.src_filename)
if not isfile(big_path):
copy(self.src_path, big_path, symlink=s['orig_link'])
copy(self.src_path, big_path, symlink=s['orig_link'], rellink=['rel_link'])
return join(s['orig_dir'], self.src_filename)
@property

View File

@@ -55,6 +55,7 @@ _DEFAULT_CONFIG = {
'mp4_options': ['-crf', '23', '-strict', '-2'],
'orig_dir': 'original',
'orig_link': False,
'rel_link': False,
'output_filename': 'index.html',
'piwik': {'tracker_url': '', 'site_id': 0},
'plugin_paths': [],

View File

@@ -42,12 +42,15 @@ class Devnull(object):
pass
def copy(src, dst, symlink=False):
def copy(src, dst, symlink=False, rellink=False):
"""Copy or symlink the file."""
func = os.symlink if symlink else shutil.copy2
if symlink and os.path.lexists(dst):
os.remove(dst)
func(src, dst)
if rellink: # relative symlink from dst
func(os.path.relpath(src, os.path.dirname(dst)), dst)
else:
func(src, dst)
def check_or_create_dir(path):