def __init__(self, backup=True, banner=True, create=True, default_actions=[], dotpath='dotfiles', ignoreempty=True, import_actions=[], import_configs=[], import_variables=[], keepdot=False, link_dotfile_default=LinkTypes.NOLINK, link_on_import=LinkTypes.NOLINK, longkey=False, upignore=[], cmpignore=[], instignore=[], workdir='~/.config/dotdrop', showdiff=False, minversion=None, func_file=[], filter_file=[], diff_command='diff -r -u {0} {1}'): self.backup = backup self.banner = banner self.create = create self.default_actions = default_actions self.dotpath = dotpath self.ignoreempty = ignoreempty self.import_actions = import_actions self.import_configs = import_configs self.import_variables = import_variables self.keepdot = keepdot self.longkey = longkey self.showdiff = showdiff self.upignore = upignore self.cmpignore = cmpignore self.instignore = instignore self.workdir = workdir self.link_dotfile_default = LinkTypes.get(link_dotfile_default) self.link_on_import = LinkTypes.get(link_on_import) self.minversion = minversion self.func_file = func_file self.filter_file = filter_file self.diff_command = diff_command
def __init__(self, backup=True, banner=True, cmpignore=[], create=True, default_actions=[], dotpath='dotfiles', ignoreempty=True, import_actions=[], import_configs=[], import_variables=[], keepdot=False, link_dotfile_default=LinkTypes.NOLINK, link_on_import=LinkTypes.NOLINK, longkey=False, showdiff=False, upignore=[], workdir='~/.config/dotdrop'): self.backup = backup self.banner = banner self.create = create self.cmpignore = cmpignore self.default_actions = default_actions self.dotpath = dotpath self.ignoreempty = ignoreempty self.import_actions = import_actions self.import_configs = import_configs self.import_variables = import_variables self.keepdot = keepdot self.longkey = longkey self.showdiff = showdiff self.upignore = upignore self.workdir = workdir self.link_dotfile_default = LinkTypes.get(link_dotfile_default) self.link_on_import = LinkTypes.get(link_on_import)
def __init__(self, backup=True, banner=True, create=True, default_actions=None, dotpath='dotfiles', ignoreempty=False, import_actions=None, import_configs=None, import_variables=None, keepdot=False, link_dotfile_default=LinkTypes.NOLINK, link_on_import=LinkTypes.NOLINK, longkey=False, upignore=None, cmpignore=None, instignore=None, impignore=None, workdir='~/.config/dotdrop', showdiff=False, minversion=None, func_file=None, filter_file=None, diff_command='diff -r -u {0} {1}', template_dotfile_default=True, ignore_missing_in_dotdrop=False, force_chmod=False, chmod_on_import=False, check_version=False, clear_workdir=False, compare_workdir=False, key_prefix=True, key_separator='_'): self.backup = backup self.banner = banner self.create = create self.default_actions = default_actions or [] self.dotpath = dotpath self.ignoreempty = ignoreempty self.import_actions = import_actions or [] self.import_configs = import_configs or [] self.import_variables = import_variables or [] self.keepdot = keepdot self.longkey = longkey self.showdiff = showdiff self.upignore = upignore or [] self.cmpignore = cmpignore or [] self.instignore = instignore or [] self.impignore = impignore or [] self.workdir = workdir if ENV_WORKDIR in os.environ: self.workdir = os.environ[ENV_WORKDIR] self.link_dotfile_default = LinkTypes.get(link_dotfile_default) self.link_on_import = LinkTypes.get(link_on_import) self.minversion = minversion self.func_file = func_file or [] self.filter_file = filter_file or [] self.diff_command = diff_command self.template_dotfile_default = template_dotfile_default self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop self.force_chmod = force_chmod self.chmod_on_import = chmod_on_import self.check_version = check_version self.clear_workdir = clear_workdir self.compare_workdir = compare_workdir self.key_prefix = key_prefix self.key_separator = key_separator
def __init__(self, key, dst, src, actions=None, trans_r=None, trans_w=None, link=LinkTypes.NOLINK, noempty=False, cmpignore=None, upignore=None, instignore=None, template=True, chmod=None, ignore_missing_in_dotdrop=False): """ 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 @noempty: ignore empty template if True @upignore: patterns to ignore when updating @cmpignore: patterns to ignore when comparing @instignore: patterns to ignore when installing @template: template this dotfile @chmod: file permission """ self.actions = actions or [] self.dst = dst self.key = key self.link = LinkTypes.get(link) self.noempty = noempty self.src = src self.trans_r = trans_r self.trans_w = trans_w self.upignore = upignore or [] self.cmpignore = cmpignore or [] self.instignore = instignore or [] self.template = template self.chmod = chmod self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop if self.link != LinkTypes.NOLINK and \ ( (trans_r and len(trans_r) > 0) or (trans_w and len(trans_w) > 0) ): msg = '[{}] transformations disabled'.format(key) msg += ' because dotfile is linked' self.log.warn(msg) self.trans_r = [] self.trans_w = []
def cmd_importer(o): """import dotfile(s) from paths""" ret = True cnt = 0 paths = o.import_path for path in paths: if o.debug: LOG.dbg('trying to import {}'.format(path)) if not os.path.exists(path): LOG.err('\"{}\" does not exist, ignored!'.format(path)) ret = False continue dst = path.rstrip(os.sep) dst = os.path.abspath(dst) src = strip_home(dst) strip = '.' + os.sep if o.keepdot: strip = os.sep src = src.lstrip(strip) # create a new dotfile dotfile = Dotfile('', dst, src) linktype = LinkTypes(o.link) if o.debug: LOG.dbg('new dotfile: {}'.format(dotfile)) # prepare hierarchy for dotfile srcf = os.path.join(o.dotpath, src) if not os.path.exists(srcf): cmd = ['mkdir', '-p', '{}'.format(os.path.dirname(srcf))] if o.dry: LOG.dry('would run: {}'.format(' '.join(cmd))) else: r, _ = run(cmd, raw=False, debug=o.debug, checkerr=True) if not r: LOG.err('importing \"{}\" failed!'.format(path)) ret = False continue cmd = ['cp', '-R', '-L', dst, srcf] if o.dry: LOG.dry('would run: {}'.format(' '.join(cmd))) if linktype == LinkTypes.PARENTS: LOG.dry('would symlink {} to {}'.format(srcf, dst)) else: r, _ = run(cmd, raw=False, debug=o.debug, checkerr=True) if not r: LOG.err('importing \"{}\" failed!'.format(path)) ret = False continue if linktype == LinkTypes.PARENTS: remove(dst) os.symlink(srcf, dst) retconf, dotfile = o.conf.new(dotfile, o.profile, link=linktype, debug=o.debug) if retconf: LOG.sub('\"{}\" imported'.format(path)) cnt += 1 else: LOG.warn('\"{}\" ignored'.format(path)) if o.dry: LOG.dry('new config file would be:') LOG.raw(o.conf.dump()) else: o.conf.save() LOG.log('\n{} file(s) imported.'.format(cnt)) return ret