Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
No more silly locking problems. It uses Mercurial's atomictempfile class to manage overwriting the configuration file (write to temp, close, rename). Uses cPickle to dump/parse the config data, this is simple and efficient.
"""shlib.py - TortoiseHg shell utilities Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>This software may be used and distributed according to the termsof the GNU General Public License, incorporated herein by reference."""
-import dumbdbm, anydbm-anydbm._defaultmod = dumbdbm-import os
import sys
import gtk
-import shelve+import cPickleimport time
import hgtk
import gobject
from mercurial.i18n import _
+from mercurial import utilclass SimpleMRUList(object):
def __init__(self, size=10, reflist=[], compact=True):
self._size=sizeself._list=reflistifcompact:self.compact()def__iter__(self):foreleminself._list:yieldelemdefadd(self,val):ifvalinself._list:self._list.remove(val)self._list.insert(0,val)self.flush()defget_size(self):returnself._sizedefset_size(self,size):self._size=sizeself.flush()defflush(self):whilelen(self._list)>self._size:delself._list[-1]defcompact(self):''' remove duplicate in list '''newlist=[]forvinself._list:ifvnotinnewlist:newlist.append(v)self._list[:]=newlistclassSettings(object):version=1.0def__init__(self,appname,path=None):self._appname=appnameself._data={}self._path=pathandpathorself._get_path(appname)self._audit()self.read()defget_value(self,key,default=None,create=False):ifkeyinself._data:returnself._data[key]elifcreate:self._data[key]=defaultreturndefaultdefset_value(self,key,value):self._data[key]=valuedefmrul(self,key,size=10):''' wrapper method to create a most-recently-used (MRU) list '''ls=self.get_value(key,[],True)ml=SimpleMRUList(size=size,reflist=ls)returnmldefget_keys(self):returnself._data.keys()defget_appname(self):returnself._appname def read(self):
self._data.clear()
- if not os.path.exists(self._path+'.dat'):
- return- dbase = shelve.open(self._path)- try:
-self._dbappname = dbase['APPNAME']- self.version = dbase['VERSION']- self._data.update(dbase.get('DATA', {}))
- except KeyError:
-pass- dbase.close()+ if os.path.exists(self._path):
+ try:
+ f = file(self._path, 'rb')+ self._data = cPickle.loads(f.read())
+ f.close()+except Exception:
+pass def write(self):
self._write(self._path, self._data)
def _write(self, appname, data):
-dbase = shelve.open(self._get_path(appname))
-dbase['VERSION'] = Settings.version- dbase['APPNAME'] = appname- dbase['DATA'] = data- try:- dbase.close()
-except IOError:- pass # Don't care too much about permission errors-+s = cPickle.dumps(data)
+f = util.atomictempfile(appname,'wb',None)
+f.write(s)+f.rename() def _get_path(self, appname):
if os.name == 'nt':
- return os.path.join(os.environ.get('APPDATA'), 'TortoiseHg', appname)
+ return os.path.join(os.environ.get('APPDATA'), 'TortoiseHg',
+ appname)
else:
return os.path.join(os.path.expanduser('~'), '.tortoisehg',
-'settings', appname)
+ appname)
def _audit(self):
if os.path.exists(os.path.dirname(self._path)):
returnos.makedirs(os.path.dirname(self._path))defget_system_times():t=os.times()ift[4]==0.0:# Windows leaves this as zero, so use time.clock()t=(t[0],t[1],t[2],t[3],time.clock())returntdefset_tortoise_icon(window,thgicon):ico=get_tortoise_icon(thgicon)ifico:window.set_icon_from_file(ico)defget_thg_modifier():ifsys.platform=='darwin':return'<Mod1>'else:return'<Control>'defset_tortoise_keys(window):'Set default TortoiseHg keyboard accelerators'ifsys.platform=='darwin':mask=gtk.accelerator_get_default_mod_mask()mask|=gtk.gdk.MOD1_MASK;gtk.accelerator_set_default_mod_mask(mask)mod=get_thg_modifier()accelgroup=gtk.AccelGroup()window.add_accel_group(accelgroup)key,modifier=gtk.accelerator_parse(mod+'w')window.add_accelerator('thg-close',accelgroup,key,modifier,gtk.ACCEL_VISIBLE)key,modifier=gtk.accelerator_parse(mod+'q')window.add_accelerator('thg-exit',accelgroup,key,modifier,gtk.ACCEL_VISIBLE)key,modifier=gtk.accelerator_parse('F5')window.add_accelerator('thg-refresh',accelgroup,key,modifier,gtk.ACCEL_VISIBLE)key,modifier=gtk.accelerator_parse(mod+'Return')window.add_accelerator('thg-accept',accelgroup,key,modifier,gtk.ACCEL_VISIBLE)# connect ctrl-w and ctrl-q to every windowwindow.connect('thg-close',thgclose)window.connect('thg-exit',thgexit)defthgexit(window):ifthgclose(window):gobject.idle_add(hgtk.thgexit,window)defthgclose(window):ifhasattr(window,'should_live'):ifwindow.should_live():returnFalsewindow.destroy()returnTruedefget_tortoise_icon(thgicon):'''Find a tortoise icon, apply to PyGtk window'''# The context menu should set this variablevar=os.environ.get('THG_ICON_PATH',None)paths=varand[var]or[]try:# Else try relative paths from hggtk, the repository layoutfdir=os.path.dirname(__file__)paths.append(os.path.join(fdir,'..','icons'))# ... or the unix installer layoutpaths.append(os.path.join(fdir,'..','..','..','share','pixmaps','tortoisehg','icons'))paths.append(os.path.join(fdir,'..','..','..','..','share','pixmaps','tortoisehg','icons'))exceptNameError:# __file__ is not always availablepassforpinpaths:path=os.path.join(p,'tortoise',thgicon)ifos.path.isfile(path):returnpathelse:print_('icon not found'),thgiconreturnNonedefversion():try:import__version__return__version__.versionexceptImportError:return_('unknown')ifos.name=='nt':defshell_notify(paths):try:fromwin32com.shellimportshell,shellconimportpywintypesexceptImportError:returndirs=[]forpathinpaths:abspath=os.path.abspath(path)ifnotos.path.isdir(abspath):abspath=os.path.dirname(abspath)ifabspathnotindirs:dirs.append(abspath)# send notifications to deepest directories firstdirs.sort(lambdax,y:len(y)-len(x))fordirindirs:try:pidl,ignore=shell.SHILCreateFromPath(dir,0)exceptpywintypes.com_error:returnifpidlisNone:continueshell.SHChangeNotify(shellcon.SHCNE_UPDATEITEM,shellcon.SHCNF_IDLIST|shellcon.SHCNF_FLUSH,pidl,None)else:defshell_notify(paths):pass
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.