mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Some corrections on tools/pelican-themes
This commit is contained in:
parent
f6870f4a01
commit
37474e5ccb
1 changed files with 34 additions and 19 deletions
|
|
@ -27,6 +27,8 @@ except:
|
||||||
|
|
||||||
|
|
||||||
__version__ = '0.1'
|
__version__ = '0.1'
|
||||||
|
_BUILTIN_THEMES = ['simple', 'notmyidea']
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="""Install themes for Pelican""")
|
parser = argparse.ArgumentParser(description="""Install themes for Pelican""")
|
||||||
|
|
@ -47,9 +49,16 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
if args.list:
|
if args.list:
|
||||||
list(args.verbose)
|
list_themes(args.verbose)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
if args.to_remove:
|
||||||
|
if args.verbose:
|
||||||
|
print('Removing themes...')
|
||||||
|
|
||||||
|
for i in args.to_remove:
|
||||||
|
remove(i, v=args.verbose)
|
||||||
|
|
||||||
if args.to_install:
|
if args.to_install:
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print('Installing themes...')
|
print('Installing themes...')
|
||||||
|
|
@ -64,13 +73,6 @@ def main():
|
||||||
for i in args.to_symlink:
|
for i in args.to_symlink:
|
||||||
symlink(i, v=args.verbose)
|
symlink(i, v=args.verbose)
|
||||||
|
|
||||||
if args.to_remove:
|
|
||||||
if args.verbose:
|
|
||||||
print('Removing themes...')
|
|
||||||
|
|
||||||
for i in args.to_remove:
|
|
||||||
remove(i, v=args.verbose)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def themes():
|
def themes():
|
||||||
|
|
@ -84,7 +86,7 @@ def themes():
|
||||||
yield (e, None)
|
yield (e, None)
|
||||||
|
|
||||||
|
|
||||||
def list(v=False):
|
def list_themes(v=False):
|
||||||
for t, l in themes():
|
for t, l in themes():
|
||||||
if not v:
|
if not v:
|
||||||
t = os.path.basename(t)
|
t = os.path.basename(t)
|
||||||
|
|
@ -99,10 +101,12 @@ def list(v=False):
|
||||||
|
|
||||||
def remove(theme_name, v=False):
|
def remove(theme_name, v=False):
|
||||||
|
|
||||||
|
theme_name = theme_name.replace('/','')
|
||||||
target = os.path.join(themes_path, theme_name)
|
target = os.path.join(themes_path, theme_name)
|
||||||
|
|
||||||
|
if theme_name in _BUILTIN_THEMES:
|
||||||
if not os.path.exists(target):
|
err(theme_name + ' is a builtin theme.\nYou cannot remove a builtin theme with this script, remove it by hand if you want.')
|
||||||
|
elif not os.path.exists(target):
|
||||||
err(target + ' : no such file or directory')
|
err(target + ' : no such file or directory')
|
||||||
elif os.path.islink(target):
|
elif os.path.islink(target):
|
||||||
if v:
|
if v:
|
||||||
|
|
@ -124,10 +128,15 @@ def install(path, v=False):
|
||||||
else:
|
else:
|
||||||
theme_name = os.path.basename(os.path.normpath(path))
|
theme_name = os.path.basename(os.path.normpath(path))
|
||||||
theme_path = os.path.join(themes_path, theme_name)
|
theme_path = os.path.join(themes_path, theme_name)
|
||||||
try:
|
if os.path.exists(theme_path):
|
||||||
shutil.copytree(path, theme_path)
|
err(path + ' : already exists')
|
||||||
except Exception, e:
|
else:
|
||||||
err("Cannot copy `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e)))
|
if v:
|
||||||
|
print("Copying `{p}' to `{t}' ...".format(p=path, t=theme_path))
|
||||||
|
try:
|
||||||
|
shutil.copytree(path, theme_path)
|
||||||
|
except Exception, e:
|
||||||
|
err("Cannot copy `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e)))
|
||||||
|
|
||||||
def symlink(path, v=False):
|
def symlink(path, v=False):
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
|
@ -137,10 +146,16 @@ def symlink(path, v=False):
|
||||||
else:
|
else:
|
||||||
theme_name = os.path.basename(os.path.normpath(path))
|
theme_name = os.path.basename(os.path.normpath(path))
|
||||||
theme_path = os.path.join(themes_path, theme_name)
|
theme_path = os.path.join(themes_path, theme_name)
|
||||||
try:
|
if os.path.exists(theme_path):
|
||||||
os.symlink(path, theme_path)
|
err(path + ' : already exists')
|
||||||
except Exception, e:
|
else:
|
||||||
err("Cannot link `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e)))
|
if v:
|
||||||
|
print("Linking `{p}' to `{t}' ...".format(p=path, t=theme_path))
|
||||||
|
try:
|
||||||
|
os.symlink(path, theme_path)
|
||||||
|
except Exception, e:
|
||||||
|
err("Cannot link `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue