Some corrections on tools/pelican-themes

This commit is contained in:
Skami18 2011-05-14 12:57:57 +02:00
commit 37474e5ccb

View file

@ -27,6 +27,8 @@ except:
__version__ = '0.1'
_BUILTIN_THEMES = ['simple', 'notmyidea']
def main():
parser = argparse.ArgumentParser(description="""Install themes for Pelican""")
@ -47,9 +49,16 @@ def main():
if args.list:
list(args.verbose)
list_themes(args.verbose)
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.verbose:
print('Installing themes...')
@ -64,13 +73,6 @@ def main():
for i in args.to_symlink:
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():
@ -84,7 +86,7 @@ def themes():
yield (e, None)
def list(v=False):
def list_themes(v=False):
for t, l in themes():
if not v:
t = os.path.basename(t)
@ -99,10 +101,12 @@ def list(v=False):
def remove(theme_name, v=False):
theme_name = theme_name.replace('/','')
target = os.path.join(themes_path, theme_name)
if not os.path.exists(target):
if theme_name in _BUILTIN_THEMES:
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')
elif os.path.islink(target):
if v:
@ -124,10 +128,15 @@ def install(path, v=False):
else:
theme_name = os.path.basename(os.path.normpath(path))
theme_path = os.path.join(themes_path, theme_name)
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)))
if os.path.exists(theme_path):
err(path + ' : already exists')
else:
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):
if not os.path.exists(path):
@ -137,10 +146,16 @@ def symlink(path, v=False):
else:
theme_name = os.path.basename(os.path.normpath(path))
theme_path = os.path.join(themes_path, theme_name)
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 os.path.exists(theme_path):
err(path + ' : already exists')
else:
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__':