mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 08:04:16 +00:00
docstring
This commit is contained in:
@@ -16,6 +16,10 @@ from dotdrop.logger import Logger
|
||||
class Cmd:
|
||||
|
||||
def __init__(self, key, action):
|
||||
"""constructor
|
||||
@key: action key
|
||||
@action: action string
|
||||
"""
|
||||
self.key = key
|
||||
self.action = action
|
||||
self.log = Logger()
|
||||
@@ -33,6 +37,12 @@ class Cmd:
|
||||
class Action(Cmd):
|
||||
|
||||
def __init__(self, key, kind, action, *args):
|
||||
"""constructor
|
||||
@key: action key
|
||||
@kind: type of action (pre or post)
|
||||
@action: action string
|
||||
@args: action arguments
|
||||
"""
|
||||
super(Action, self).__init__(key, action)
|
||||
self.kind = kind
|
||||
self.args = args
|
||||
|
||||
@@ -16,6 +16,10 @@ import dotdrop.utils as utils
|
||||
class Comparator:
|
||||
|
||||
def __init__(self, diffopts='', debug=False):
|
||||
"""constructor
|
||||
@diffopts: cli switches to pass to unix diff
|
||||
@debug: enable debug
|
||||
"""
|
||||
self.diffopts = diffopts
|
||||
self.debug = debug
|
||||
self.log = Logger()
|
||||
|
||||
@@ -78,11 +78,16 @@ class Cfg:
|
||||
default_link_by_default = False
|
||||
default_workdir = '~/.config/dotdrop'
|
||||
|
||||
def __init__(self, cfgpath):
|
||||
def __init__(self, cfgpath, debug=False):
|
||||
"""constructor
|
||||
@cfgpath: path to the config file
|
||||
@debug: enable debug
|
||||
"""
|
||||
if not os.path.exists(cfgpath):
|
||||
raise ValueError('config file does not exist: {}'.format(cfgpath))
|
||||
# make sure to have an absolute path to config file
|
||||
self.cfgpath = os.path.abspath(cfgpath)
|
||||
self.debug = debug
|
||||
|
||||
# init the logger
|
||||
self.log = Logger()
|
||||
|
||||
@@ -430,7 +430,8 @@ def main():
|
||||
args = docopt(USAGE, version=VERSION)
|
||||
|
||||
try:
|
||||
conf = Cfg(os.path.expanduser(args['--cfg']))
|
||||
conf = Cfg(os.path.expanduser(args['--cfg']),
|
||||
debug=args['--verbose'])
|
||||
except ValueError as e:
|
||||
LOG.err('Config format error: {}'.format(str(e)))
|
||||
return False
|
||||
@@ -439,6 +440,7 @@ def main():
|
||||
opts['dry'] = args['--dry']
|
||||
opts['profile'] = args['--profile']
|
||||
opts['safe'] = not args['--force']
|
||||
opts['debug'] = args['--verbose']
|
||||
opts['installdiff'] = not args['--nodiff']
|
||||
opts['link'] = LinkTypes.NOLINK
|
||||
if opts['link_by_default']:
|
||||
@@ -450,7 +452,6 @@ def main():
|
||||
if args['--inv-link'] and opts['link'] == LinkTypes.PARENTS:
|
||||
opts['link'] = LinkTypes.NOLINK
|
||||
|
||||
opts['debug'] = args['--verbose']
|
||||
opts['variables'] = conf.get_variables(opts['profile'],
|
||||
debug=opts['debug'])
|
||||
opts['showdiff'] = opts['showdiff'] or args['--showdiff']
|
||||
|
||||
@@ -14,25 +14,27 @@ class Dotfile:
|
||||
actions={}, trans_r=None, trans_w=None,
|
||||
link=LinkTypes.NOLINK, cmpignore=[], noempty=False,
|
||||
upignore=[]):
|
||||
# key of dotfile in the config
|
||||
"""constructor
|
||||
@key: dotfile key
|
||||
@dst: dotfile dst (in user's home usually)
|
||||
@src: dotfile src (in dotpath)
|
||||
@actions: dictionary of actions to execute for this dotfile
|
||||
@trans_r: transformation to change dotfile before it is installed
|
||||
@trans_w: transformation to change dotfile before updating it
|
||||
@link: link behavior
|
||||
@cmpignore: patterns to ignore when comparing
|
||||
@noempty: ignore empty template if True
|
||||
@upignore: patterns to ignore when updating
|
||||
"""
|
||||
self.key = key
|
||||
# path where to install this dotfile
|
||||
self.dst = dst
|
||||
# path where this dotfile is stored in dotdrop
|
||||
self.src = src
|
||||
# if it is a link
|
||||
self.link = link
|
||||
# list of actions
|
||||
self.actions = actions
|
||||
# read transformation
|
||||
self.trans_r = trans_r
|
||||
# write transformation
|
||||
self.trans_w = trans_w
|
||||
# pattern to ignore when comparing
|
||||
self.cmpignore = cmpignore
|
||||
# do not deploy empty file
|
||||
self.noempty = noempty
|
||||
# pattern to ignore when updating
|
||||
self.upignore = upignore
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -21,6 +21,18 @@ class Installer:
|
||||
def __init__(self, base='.', create=True, backup=True,
|
||||
dry=False, safe=False, workdir='~/.config/dotdrop',
|
||||
debug=False, diff=True, totemp=None, showdiff=False):
|
||||
"""constructor
|
||||
@base: directory path where to search for templates
|
||||
@create: create directory hierarchy if missing when installing
|
||||
@backup: backup existing dotfile when installing
|
||||
@dry: just simulate
|
||||
@safe: ask for any overwrite
|
||||
@workdir: where to install template before symlinking
|
||||
@debug: enable debug
|
||||
@diff: diff when installing if True
|
||||
@totemp: deploy to this path instead of dotfile dst if not None
|
||||
@showdiff: show the diff before overwriting (or asking for)
|
||||
"""
|
||||
self.create = create
|
||||
self.backup = backup
|
||||
self.dry = dry
|
||||
|
||||
@@ -9,5 +9,5 @@ import os
|
||||
|
||||
|
||||
def exists(path):
|
||||
'''return true when path exists'''
|
||||
"""return true when path exists"""
|
||||
return os.path.exists(path)
|
||||
|
||||
@@ -24,6 +24,11 @@ COMMENT_END = '@@#}'
|
||||
class Templategen:
|
||||
|
||||
def __init__(self, base='.', variables={}, debug=False):
|
||||
"""constructor
|
||||
@base: directory path where to search for templates
|
||||
@variables: dictionary of variables for templates
|
||||
@debug: enable debug
|
||||
"""
|
||||
self.base = base.rstrip(os.sep)
|
||||
self.debug = debug
|
||||
self.log = Logger()
|
||||
|
||||
@@ -22,6 +22,18 @@ class Updater:
|
||||
|
||||
def __init__(self, conf, dotpath, profile, variables, dry, safe,
|
||||
iskey=False, debug=False, ignore=[], showpatch=False):
|
||||
"""constructor
|
||||
@conf: configuration
|
||||
@dotpath: path where dotfiles are stored
|
||||
@profile: profile selected
|
||||
@variables: dictionary of variables for the templates
|
||||
@dry: simulate
|
||||
@safe: ask for overwrite if True
|
||||
@iskey: will the update be called on keys or path
|
||||
@debug: enable debug
|
||||
@ignore: pattern to ignore when updating
|
||||
@showpatch: show patch if dotfile to update is a template
|
||||
"""
|
||||
self.conf = conf
|
||||
self.dotpath = dotpath
|
||||
self.profile = profile
|
||||
|
||||
Reference in New Issue
Block a user