hgkw/keyword.py
branchkwmap-templates
changeset 179 8ddd39a79dc7
parent 178 4a27c306c6a2
child 180 5d20f5d642f3
equal deleted inserted replaced
178:4a27c306c6a2 179:8ddd39a79dc7
    97 def kwdemo(ui, repo, **opts):
    97 def kwdemo(ui, repo, **opts):
    98     '''print [keywordmaps] configuration and an expansion example
    98     '''print [keywordmaps] configuration and an expansion example
    99     '''
    99     '''
   100     log = 'hg keyword config and expansion example'
   100     log = 'hg keyword config and expansion example'
   101     fn = 'demo.txt'
   101     fn = 'demo.txt'
   102     ui.setconfig('keyword', fn, '')
       
   103     if opts['default']:
       
   104         kwstatus = 'default'
       
   105         kwmaps = deftemplates
       
   106         if ui.configitems('keywordmaps'):
       
   107             for k, v in kwmaps.items():
       
   108                 ui.setconfig('keywordmaps', k, v)
       
   109     else:
       
   110         kwstatus = 'current'
       
   111         kwmaps = dict(ui.configitems('keywordmaps')) or deftemplates
       
   112     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   102     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   113     if ui.verbose:
   103     if ui.verbose:
   114         ui.status(_('creating temporary repo at %s\n') % tmpdir)
   104         ui.status(_('creating temporary repo at %s\n') % tmpdir)
   115     _repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   105     _repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   116     reposetup(ui, _repo)
   106     _repo.ui.setconfig('keyword', fn, '')
       
   107     if opts['default']:
       
   108         kwstatus = 'default'
       
   109         kwmaps = deftemplates
       
   110     else:
       
   111         kwstatus = 'current'
       
   112         kwmaps = dict(ui.configitems('keywordmaps')) or deftemplates
       
   113     if ui.configitems('keywordmaps'):
       
   114         for k, v in kwmaps.items():
       
   115             _repo.ui.setconfig('keywordmaps', k, v)
       
   116     reposetup(_repo.ui, _repo)
   117     ui.status(_('config with %s keyword maps:\n') % kwstatus)
   117     ui.status(_('config with %s keyword maps:\n') % kwstatus)
   118     ui.write('[keyword]\n%s =\n[keywordmaps\n' % fn)
   118     ui.write('[keyword]\n%s =\n[keywordmaps\n' % fn)
   119     for k, v in kwmaps.items():
   119     for k, v in kwmaps.items():
   120         ui.write('%s = %s\n' % (k, v))
   120         ui.write('%s = %s\n' % (k, v))
   121     path = _repo.wjoin(fn)
   121     path = _repo.wjoin(fn)