nutools/lib/pyulib/migrate/tasks1/tiddlywiki.py

50 lines
1.3 KiB
Python
Raw Normal View History

2021-02-24 10:55:56 +04:00
#!/usr/bin/env python2
2013-08-27 15:14:44 +04:00
# -*- coding: utf-8 -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
"""%(name)s: Gérer un fichier html tiddlywiki
USAGE
%(name)s [-f tiddlywiki.html] action
"""
try: True, False
except: True, False = 1, 0
import os, sys
from os import path
from pyutools.base import get_args, die
from pyutools.TiddlyWiki import *
######################################################################
# Programme principal
def run():
twfile = None
2015-08-20 07:58:17 +04:00
2013-08-27 15:14:44 +04:00
opts, args = get_args(None, [
("h", "help", "Afficher l'aide"),
("f:", None, "Spécifier le fichier tiddlywiki.html"),
])
for opt, value in opts:
if opt in ("-h", "--help"):
print __doc__ % {"name": path.split(sys.argv[0])}
sys.exit(0)
elif opt in ("-f", ):
twfile = value
if twfile is None: twfile = "TODO.html"
if not path.exists(twfile): die("Fichier inexistant: %s" % twfile)
action = args[0:1] and args[0] or "list"
if action in ("l", "list"):
list_tiddlers(twfile, args[1:])
elif action in ('a', 'add', 'r', 'replace'):
replace_tiddler(twfile, args=args[1:])
elif action in ('d', 'delete'):
delete_tiddler(twfile, args=args[1:])
else:
die("Action invalide: %s" % action)
if __name__ == "__main__":
run()