def __init__(self, repo_path, create=False, baseui=None, src_url=None, update_after_clone=False): """ Raises RepositoryError if repository could not be find at the given ``repo_path``. :param repo_path: local path of the repository :param create=False: if set to True, would try to create repository if it does not exist rather than raising exception :param baseui=None: user data :param src_url=None: would try to clone repository from given location :param update_after_clone=False: sets update of working copy after making a clone """ if not isinstance(repo_path, str): raise VCSError('Mercurial backend requires repository path to ' 'be instance of <str> got %s instead' % type(repo_path)) self.path = abspath(repo_path) self.baseui = baseui or ui.ui() # We've set path and ui, now we can set _repo itself self._repo = self._get_repo(create, src_url, update_after_clone)
def make_ui(read_from='file', path=None, checkpaths=True, clear_session=True): """ A function that will read python rc files or database and make an mercurial ui object from read options :param path: path to mercurial config file :param checkpaths: check the path :param read_from: read from 'file' or 'db' """ baseui = ui.ui() # clean the baseui object baseui._ocfg = config.config() baseui._ucfg = config.config() baseui._tcfg = config.config() if read_from == 'file': if not os.path.isfile(path): log.debug('hgrc file is not present at %s, skipping...' % path) return False log.debug('reading hgrc from %s' % path) cfg = config.config() cfg.read(path) for section in ui_sections: for k, v in cfg.items(section): log.debug('settings ui from file: [%s] %s=%s' % (section, k, v)) baseui.setconfig(safe_str(section), safe_str(k), safe_str(v)) elif read_from == 'db': sa = meta.Session() ret = sa.query(Ui).all() hg_ui = ret for ui_ in hg_ui: if ui_.ui_active: ui_val = safe_str(ui_.ui_value) if ui_.ui_section == 'hooks' and BRAND != 'kallithea' and ui_val.startswith( 'python:' + BRAND + '.lib.hooks.'): ui_val = ui_val.replace('python:' + BRAND + '.lib.hooks.', 'python:kallithea.lib.hooks.') log.debug('settings ui from db: [%s] %s=%s', ui_.ui_section, ui_.ui_key, ui_val) baseui.setconfig(safe_str(ui_.ui_section), safe_str(ui_.ui_key), ui_val) if ui_.ui_key == 'push_ssl': # force set push_ssl requirement to False, kallithea # handles that baseui.setconfig(safe_str(ui_.ui_section), safe_str(ui_.ui_key), False) if clear_session: meta.Session.remove() # prevent interactive questions for ssh password / passphrase ssh = baseui.config('ui', 'ssh', default='ssh') baseui.setconfig('ui', 'ssh', '%s -oBatchMode=yes -oIdentitiesOnly=yes' % ssh) return baseui
def make_ui(read_from='file', path=None, checkpaths=True, clear_session=True): """ A function that will read python rc files or database and make an mercurial ui object from read options :param path: path to mercurial config file :param checkpaths: check the path :param read_from: read from 'file' or 'db' """ baseui = ui.ui() # clean the baseui object baseui._ocfg = config.config() baseui._ucfg = config.config() baseui._tcfg = config.config() if read_from == 'file': if not os.path.isfile(path): log.debug('hgrc file is not present at %s, skipping...', path) return False log.debug('reading hgrc from %s', path) cfg = config.config() cfg.read(path) for section in ui_sections: for k, v in cfg.items(section): log.debug('settings ui from file: [%s] %s=%s', section, k, v) baseui.setconfig(safe_str(section), safe_str(k), safe_str(v)) elif read_from == 'db': sa = meta.Session() ret = sa.query(Ui).all() hg_ui = ret for ui_ in hg_ui: if ui_.ui_active: ui_val = safe_str(ui_.ui_value) if ui_.ui_section == 'hooks' and BRAND != 'kallithea' and ui_val.startswith('python:' + BRAND + '.lib.hooks.'): ui_val = ui_val.replace('python:' + BRAND + '.lib.hooks.', 'python:kallithea.lib.hooks.') log.debug('settings ui from db: [%s] %s=%s', ui_.ui_section, ui_.ui_key, ui_val) baseui.setconfig(safe_str(ui_.ui_section), safe_str(ui_.ui_key), ui_val) if ui_.ui_key == 'push_ssl': # force set push_ssl requirement to False, kallithea # handles that baseui.setconfig(safe_str(ui_.ui_section), safe_str(ui_.ui_key), False) if clear_session: meta.Session.remove() # prevent interactive questions for ssh password / passphrase ssh = baseui.config('ui', 'ssh', default='ssh') baseui.setconfig('ui', 'ssh', '%s -oBatchMode=yes -oIdentitiesOnly=yes' % ssh) return baseui
def _check_url(cls, url, repoui=None): """ Function will check given url and try to verify if it's a valid link. Sometimes it may happened that mercurial will issue basic auth request that can cause whole API to hang when used from python or other external calls. On failures it'll raise urllib2.HTTPError, exception is also thrown when the return code is non 200 """ # check first if it's not an local url if os.path.isdir(url) or url.startswith('file:'): return True if url.startswith('ssh:'): # in case of invalid uri or authentication issues, sshpeer will # throw an exception. sshpeer(repoui or ui.ui(), url).lookup('tip') return True url_prefix = None if '+' in url[:url.find('://')]: url_prefix, url = url.split('+', 1) handlers = [] url_obj = hg_url(url) test_uri, authinfo = url_obj.authinfo() url_obj.passwd = '*****' cleaned_uri = str(url_obj) if authinfo: #create a password manager passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() passmgr.add_password(*authinfo) handlers.extend((httpbasicauthhandler(passmgr), httpdigestauthhandler(passmgr))) o = urllib2.build_opener(*handlers) o.addheaders = [('Content-Type', 'application/mercurial-0.1'), ('Accept', 'application/mercurial-0.1')] q = {"cmd": 'between'} q.update({'pairs': "%s-%s" % ('0' * 40, '0' * 40)}) qs = '?%s' % urllib.urlencode(q) cu = "%s%s" % (test_uri, qs) req = urllib2.Request(cu, None, {}) try: resp = o.open(req) if resp.code != 200: raise Exception('Return Code is not 200') except Exception, e: # means it cannot be cloned raise urllib2.URLError("[%s] org_exc: %s" % (cleaned_uri, e))
def _check_url(cls, url, repoui=None): """ Function will check given url and try to verify if it's a valid link. Sometimes it may happened that mercurial will issue basic auth request that can cause whole API to hang when used from python or other external calls. On failures it'll raise urllib2.HTTPError, exception is also thrown when the return code is non 200 """ # check first if it's not an local url if os.path.isdir(url) or url.startswith('file:'): return True if url.startswith('ssh:'): # in case of invalid uri or authentication issues, sshpeer will # throw an exception. sshpeer(repoui or ui.ui(), url).lookup('tip') return True url_prefix = None if '+' in url[:url.find('://')]: url_prefix, url = url.split('+', 1) handlers = [] url_obj = hg_url(url) test_uri, authinfo = url_obj.authinfo() url_obj.passwd = '*****' cleaned_uri = str(url_obj) if authinfo: #create a password manager passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() passmgr.add_password(*authinfo) handlers.extend((httpbasicauthhandler(passmgr), httpdigestauthhandler(passmgr))) o = urllib2.build_opener(*handlers) o.addheaders = [('Content-Type', 'application/mercurial-0.1'), ('Accept', 'application/mercurial-0.1')] q = {"cmd": 'between'} q.update({'pairs': "%s-%s" % ('0' * 40, '0' * 40)}) qs = '?%s' % urllib.urlencode(q) cu = "%s%s" % (test_uri, qs) req = urllib2.Request(cu, None, {}) try: resp = o.open(req) if resp.code != 200: raise Exception('Return Code is not 200') except Exception, e: # means it cannot be cloned raise urllib2.URLError("[%s] org_exc: %s" % (cleaned_uri, e))
def make_ui(self, path='hgwebdir.config'): """ A function that will read python rc files and make an ui from read options :param path: path to mercurial config file """ #propagated from mercurial documentation sections = [ 'alias', 'auth', 'decode/encode', 'defaults', 'diff', 'email', 'extensions', 'format', 'merge-patterns', 'merge-tools', 'hooks', 'http_proxy', 'smtp', 'patch', 'paths', 'profiling', 'server', 'trusted', 'ui', 'web', ] repos = path baseui = ui.ui() cfg = config.config() cfg.read(repos) self.paths = cfg.items('paths') self.base_path = self.paths[0][1].replace('*', '') self.check_repo_dir(self.paths) self.set_statics(cfg) for section in sections: for k, v in cfg.items(section): baseui.setconfig(section, k, v) return baseui
def make_ui(self, path='hgwebdir.config'): """ A function that will read python rc files and make an ui from read options :param path: path to mercurial config file """ #propagated from mercurial documentation sections = [ 'alias', 'auth', 'decode/encode', 'defaults', 'diff', 'email', 'extensions', 'format', 'merge-patterns', 'merge-tools', 'hooks', 'http_proxy', 'smtp', 'patch', 'paths', 'profiling', 'server', 'trusted', 'ui', 'web', ] repos = path baseui = ui.ui() cfg = config.config() cfg.read(repos) self.paths = cfg.items('paths') self.base_path = self.paths[0][1].replace('*', '') self.check_repo_dir(self.paths) self.set_statics(cfg) for section in sections: for k, v in cfg.items(section): baseui.setconfig(section, k, v) return baseui
def __init__(self, repo_path, create=False, baseui=None, src_url=None, update_after_clone=False): """ Raises RepositoryError if repository could not be find at the given ``repo_path``. :param repo_path: local path of the repository :param create=False: if set to True, would try to create repository if it does not exist rather than raising exception :param baseui=None: user data :param src_url=None: would try to clone repository from given location :param update_after_clone=False: sets update of working copy after making a clone """ if not isinstance(repo_path, str): raise VCSError('Mercurial backend requires repository path to ' 'be instance of <str> got %s instead' % type(repo_path)) self.path = abspath(repo_path) self.baseui = baseui or ui.ui() # We've set path and ui, now we can set _repo itself self._repo = self._get_repo(create, src_url, update_after_clone)
qs = '?%s' % urllib.urlencode(q) cu = "%s%s" % (test_uri, qs) req = urllib2.Request(cu, None, {}) try: resp = o.open(req) if resp.code != 200: raise Exception('Return Code is not 200') except Exception, e: # means it cannot be cloned raise urllib2.URLError("[%s] org_exc: %s" % (cleaned_uri, e)) if not url_prefix: # skip svn+http://... (and git+... too) # now check if it's a proper hg repo try: httppeer(repoui or ui.ui(), url).lookup('tip') except Exception, e: raise urllib2.URLError( "url [%s] does not look like an hg repo org_exc: %s" % (cleaned_uri, e)) return True def _get_repo(self, create, src_url=None, update_after_clone=False): """ Function will check for mercurial repository in given path and return a localrepo object. If there is no repository in that path it will raise an exception unless ``create`` parameter is set to True - in that case repository would be created and returned. If ``src_url`` is given, would try to clone repository from the location at given clone_point. Additionally it'll make update to
qs = '?%s' % urllib.urlencode(q) cu = "%s%s" % (test_uri, qs) req = urllib2.Request(cu, None, {}) try: resp = o.open(req) if resp.code != 200: raise Exception('Return Code is not 200') except Exception, e: # means it cannot be cloned raise urllib2.URLError("[%s] org_exc: %s" % (cleaned_uri, e)) if not url_prefix: # skip svn+http://... (and git+... too) # now check if it's a proper hg repo try: httppeer(repoui or ui.ui(), url).lookup('tip') except Exception, e: raise urllib2.URLError( "url [%s] does not look like an hg repo org_exc: %s" % (cleaned_uri, e)) return True def _get_repo(self, create, src_url=None, update_after_clone=False): """ Function will check for mercurial repository in given path and return a localrepo object. If there is no repository in that path it will raise an exception unless ``create`` parameter is set to True - in that case repository would be created and returned. If ``src_url`` is given, would try to clone repository from the location at given clone_point. Additionally it'll make update to