Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

sync: use wconfig adapter to edit paths

Changeset 37ecf43764f9

Parent af0c9ad7265b

by Yuya Nishihara

Changes to one file · Browse files at 37ecf43764f9 Showing diff from parent af0c9ad7265b Diff from another changeset...

 
13
14
15
16
 
17
18
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
316
317
318
319
 
 
 
320
321
322
323
324
325
326
327
328
329
 
 
330
331
332
333
 
334
335
336
 
367
368
369
370
 
 
 
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
 
387
388
389
390
 
391
392
393
 
466
467
468
469
 
 
470
471
472
473
474
475
476
477
478
479
480
 
485
486
487
488
489
490
 
 
 
491
492
493
 
494
495
496
497
498
499
 
500
501
502
 
626
627
628
629
630
631
632
633
634
635
636
637
638
639
 
 
640
641
642
 
13
14
15
 
16
17
 
18
19
20
21
22
23
 
 
 
 
 
 
 
 
 
 
24
25
26
 
306
307
308
 
309
310
311
312
313
314
 
 
315
316
 
 
 
317
318
319
 
 
 
320
321
322
323
 
354
355
356
 
357
358
359
360
361
362
 
 
363
364
 
 
365
366
367
368
369
370
 
371
372
 
 
 
373
374
375
376
 
449
450
451
 
452
453
454
455
456
 
457
458
 
 
459
460
461
 
466
467
468
 
 
 
469
470
471
472
473
 
474
475
476
477
 
 
 
478
479
480
481
 
605
606
607
 
 
 
 
 
 
 
 
 
 
 
608
609
610
611
612
@@ -13,24 +13,14 @@
 from PyQt4.QtCore import *  from PyQt4.QtGui import *   -from mercurial import config, hg, ui, url, util, error +from mercurial import hg, ui, url, util, error   -from tortoisehg.util import hglib, thgrepo +from tortoisehg.util import hglib, thgrepo, wconfig  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib, cmdui    # TODO  # Write keyring help, connect to help button -# Ini file locking for sync.py and settings.py - -try: - import iniparse - # Monkypatch this regex to prevent iniparse from considering - # 'rem' as a comment - iniparse.ini.CommentLine.regex = \ - re.compile(r'^(?P<csep>[%;#])(?P<comment>.*)$') -except ImportError: - iniparse = None    _schemes = ['local', 'ssh', 'http', 'https']   @@ -316,21 +306,18 @@
  _run.email(ui.ui(), root=self.root)     def removeAlias(self, alias): - if iniparse is None: + fn = os.path.join(self.root, '.hg', 'hgrc') + fn, cfg = loadIniFile([fn], self) + if not hasattr(cfg, 'write'):   qtlib.WarningMsgBox(_('Unable to remove URL'),   _('Iniparse must be installed.'), parent=self)   return - fn = os.path.join(self.root, '.hg', 'hgrc') - fn, cfg = loadIniFile([fn], self)   if fn is None:   return - if 'paths' in cfg: - if alias in cfg['paths']: - del cfg['paths'][alias] + if alias in cfg['paths']: + del cfg['paths'][alias]   try: - f = util.atomictempfile(fn, 'w', createmode=None) - f.write(str(cfg)) - f.rename() + wconfig.writefile(cfg, fn)   self.refresh()   except IOError, e:   qtlib.WarningMsgBox(_('Unable to write configuration file'), @@ -367,27 +354,23 @@
  QTimer.singleShot(0, lambda:self.aliasentry.setFocus())     def accept(self): - if iniparse is None: + fn = os.path.join(self.root, '.hg', 'hgrc') + fn, cfg = loadIniFile([fn], self) + if not hasattr(cfg, 'write'):   qtlib.WarningMsgBox(_('Unable to save an URL'),   _('Iniparse must be installed.'), parent=self)   return - fn = os.path.join(self.root, '.hg', 'hgrc') - fn, cfg = loadIniFile([fn], self)   if fn is None:   return - if 'paths' not in cfg: - cfg.new_namespace('paths')   alias = hglib.fromunicode(self.aliasentry.text())   path = hglib.fromunicode(self.urlentry.text())   if alias in cfg['paths']:   if not qtlib.QuestionMsgBox(_('Confirm URL replace'),   _('%s already exists, replace URL?') % alias):   return - cfg['paths'][alias] = path + cfg.set('paths', alias, path)   try: - f = util.atomictempfile(fn, 'w', createmode=None) - f.write(str(cfg)) - f.rename() + wconfig.writefile(cfg, fn)   except IOError, e:   qtlib.WarningMsgBox(_('Unable to write configuration file'),   hglib.tounicode(e), parent=self) @@ -466,15 +449,13 @@
  self.saveToPath(util.user_rcpath())     def saveToPath(self, path): - if iniparse is None: + fn, cfg = loadIniFile(path, self) + if not hasattr(cfg, 'write'):   qtlib.WarningMsgBox(_('Unable to save authentication'),   _('Iniparse must be installed.'), parent=self)   return - fn, cfg = loadIniFile(path, self)   if fn is None:   return - if 'auth' not in cfg: - cfg._new_namespace('auth')   schemes = hglib.fromunicode(self.schemes.currentText())   prefix = hglib.fromunicode(self.prefixentry.text())   username = hglib.fromunicode(self.userentry.text()) @@ -485,18 +466,16 @@
  _('Authentication info for %s already'   'exists, replace?') % host):   return - cfg['auth'][alias+'.schemes'] = schemes - cfg['auth'][alias+'.username'] = username - cfg['auth'][alias+'.prefix'] = prefix + cfg.set('auth', alias+'.schemes', schemes) + cfg.set('auth', alias+'.username', username) + cfg.set('auth', alias+'.prefix', prefix)   key = alias+'.password'   if password: - cfg['auth'][key] = password + cfg.set('auth', key, password)   elif not password and key in cfg['auth']:   del cfg['auth'][key]   try: - f = util.atomictempfile(fn, 'w', createmode=None) - f.write(str(cfg)) - f.rename() + wconfig.writefile(cfg, fn)   except IOError, e:   qtlib.WarningMsgBox(_('Unable to write configuration file'),   hglib.tounicode(e), parent=self) @@ -626,17 +605,8 @@
  qtlib.WarningMsgBox(_('Unable to create a config file'),   _('Insufficient access rights.'), parent=parent)   return None, {} - try: - if iniparse: - return fn, iniparse.INIConfig(file(fn), optionxformvalue=None) - else: - cfg = config.config() - cfg.read(fn) - return fn, cfg - except Exception, e: - qtlib.WarningMsgBox(_('Unable to parse a config file'), - hglib.tounicode(e), parent=parent) - return None, {} + + return fn, wconfig.readfile(fn)