hg.py
Go to the documentation of this file.00001 import silme.io
00002 import silme.format
00003 from silme.io.clients import IOClient, RCSClient
00004 from silme.core.object import L10nPackage, L10nObject, Blob
00005
00006 from mercurial import hg, ui, commands, context
00007 import os
00008
00009
00010 def register(Manager):
00011 Manager.register(HgClient)
00012
00013 class HgClient(RCSClient):
00014 name = 'hg'
00015 desc = "Mercurial Client"
00016 type = IOClient.__name__
00017
00018
00019 @classmethod
00020 def matches_path(cls, path):
00021 """
00022 tests if the ioclient should be used for this type of path
00023 example: hg:http://localhost/ or hg://localhost
00024 """
00025 return path.startswith('hg:')
00026
00027 @classmethod
00028 def get_blob(cls, path, source=True):
00029 (p, rev) = cls._explode_path(path)
00030
00031 blob = Blob()
00032 blob.id = os.path.basename(path)
00033 if source:
00034 blob.source = cls.get_source_without_encoding(p)
00035 blob.uri = p
00036 return blob
00037
00038
00039
00040 @classmethod
00041 def _explode_path(cls, path):
00042 return (path, 0)
00043
00044 @classmethod
00045 def _read_with_encoding(cls, path, encoding):
00046 client = pysvn.Client()
00047 text = client.cat(path, revision=pysvn.Revision( pysvn.opt_revision_kind.head ))
00048 return text
00049
00050 @classmethod
00051 def _read_without_encoding(cls, path):
00052 repo = hg.repository(ui.ui(), 'http://hg.mozilla.org/webtools/mcs/')
00053 print repo
00054 text = commands.cat(ui, repo, 'theme/html/index.html')
00055
00056 return text