def _get_ui(): try: ui = mercurial.ui.ui(report_untrusted=False, interactive=False, quiet=True) except TypeError: # Mercurial 1.3 changed the way we setup the ui object. ui = mercurial.ui.ui() ui.quiet = True ui._report_untrusted = False ui.setconfig('ui', 'interactive', False) return ui
def localpeer(ui, path): ui.setconfig(b'ui', b'ssh', b'') has_checksafessh = hasattr(util, 'checksafessh') sshargs = procutil.sshargs shellquote = procutil.shellquote quotecommand = getattr(procutil, 'quotecommand', None) url = util.url if has_checksafessh: checksafessh = util.checksafessh procutil.sshargs = lambda *a: b'' procutil.shellquote = lambda x: x if has_checksafessh: util.checksafessh = lambda x: None # In very old versions of mercurial, shellquote was not used, and # double quotes were hardcoded. Remove them by overriding # quotecommand. def override_quotecommand(cmd): cmd = cmd.lstrip() if cmd.startswith(b'"'): cmd = cmd[1:-1] return quotecommand(cmd) if quotecommand: procutil.quotecommand = override_quotecommand class override_url(object): def __init__(self, *args, **kwargs): self.scheme = b'ssh' self.host = b'localhost' self.port = None self.path = path self.user = b'user' self.passwd = None util.url = override_url repo = sshpeer(ui, path, False) if has_checksafessh: util.checksafessh = checksafessh util.url = url if quotecommand: procutil.quotecommand = quotecommand procutil.shellquote = shellquote procutil.sshargs = sshargs return repo
def localpeer(ui, path): ui.setconfig('ui', 'ssh', '') has_checksafessh = hasattr(util, 'checksafessh') sshargs = procutil.sshargs shellquote = procutil.shellquote quotecommand = procutil.quotecommand url = util.url if has_checksafessh: checksafessh = util.checksafessh procutil.sshargs = lambda *a: '' procutil.shellquote = lambda x: x if has_checksafessh: util.checksafessh = lambda x: None # In very old versions of mercurial, shellquote was not used, and # double quotes were hardcoded. Remove them by overriding # quotecommand. def override_quotecommand(cmd): cmd = cmd.lstrip() if cmd.startswith('"'): cmd = cmd[1:-1] return quotecommand(cmd) procutil.quotecommand = override_quotecommand class override_url(object): def __init__(self, *args, **kwargs): self.scheme = 'ssh' self.host = 'localhost' self.port = None self.path = path self.user = '******' self.passwd = None util.url = override_url repo = sshpeer(ui, path, False) if has_checksafessh: util.checksafessh = checksafessh util.url = url procutil.quotecommand = quotecommand procutil.shellquote = shellquote procutil.sshargs = sshargs return repo
def __init__(self, path, charset=None, _=lambda x: x, unix_eol=False, extension=None, repo_path=None): """ Takes the path to the directory where the pages are to be kept. If the directory doesn't exist, it will be created. If it's inside a Mercurial repository, that repository will be used, otherwise a new repository will be created in it. """ super(WikiStorage, self).__init__(charset=charset, _=_, unix_eol=unix_eol, extension=extension) self.path = os.path.abspath(path) if not os.path.exists(self.path): os.makedirs(self.path) ui = mercurial.ui.ui() ui.quiet = True ui._report_untrusted = False ui.setconfig(b'ui', b'interactive', False) self.ui = ui if repo_path is None: self.repo_path = self.path else: self.repo_path = os.path.abspath(repo_path) if not self.path.startswith(self.repo_path): raise StorageError( "Page path %r is outside of the repository path %r." % (self.path, self.repo_path)) self.repo_prefix = self.path[len(self.repo_path):].strip('/') if not os.path.exists(os.path.join(self.repo_path, '.hg')): # Create the repository if needed. mercurial.hg.repository(self.ui, self.repo_path.encode('utf8'), create=True)
parser.add_option("-d", "--debug", action = "store_true", dest = "debug", default = False, help = "print detailed debugging information to stdout") parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False, help = "print more detailed debugging information to stdout") parser.add_option("-o", "--output", dest = "output", metavar = "OUTPUT_PATH", help = "Path to build into (default 'dist')") parser.add_option("-b", "--backup", dest = "backup", metavar = "BACKUP_PATH", help = "Path to preserve old version to") parser.add_option("-i", "--ignore", action = "append", dest = "ignore", metavar = "IGNORE_PATH", help = "Ignore files in this path") parser.add_option("-c", "--cache", action = "store_true", dest = "cache", default = False, help = "use cached test suite and specification data only") (options, args) = parser.parse_args() ui = ui.ui() ui.setconfig('ui', 'debug', str(options.debug)) ui.setconfig('ui', 'quiet', str(options.quiet)) ui.setconfig('ui', 'verbose', str(options.verbose)) builder = Builder(ui, options.output, options.backup, options.ignore, options.cache) result = builder.build(args) quit(result)
def writeauth(items): ui = origui.copy() for name, value in items.iteritems(): ui.setconfig('auth', name, value) return ui
def reposetup(ui, repo): ui.setconfig("hooks", "changegroup.autocompile", publish)
def thgdispatch(ui, path=None, args=[]): ''' Replicate functionality of mercurial dispatch but force the use of the passed in ui for all purposes ''' # read --config before doing anything else # (e.g. to change trust settings for reading .hg/hgrc) config = _earlygetopt(['--config'], args) if config: ui.updateopts(config=_parseconfig(config)) # check for cwd cwd = _earlygetopt(['--cwd'], args) if cwd: os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object path = rootpath(path) or "" if path: try: ui.readconfig(os.path.join(path, ".hg", "hgrc")) except IOError: pass # now we can expand paths, even ones in .hg/hgrc rpath = _earlygetopt(["-R", "--repository", "--repo"], args) if rpath: path = ui.expandpath(rpath[-1]) extensions.loadall(ui) if not hasattr(extensions, 'extensions'): extensions.extensions = lambda: () # pre-0.9.5, loadall did below for name, module in extensions.extensions(): if name in _loaded: continue # setup extensions extsetup = getattr(module, 'extsetup', None) if extsetup: extsetup() cmdtable = getattr(module, 'cmdtable', {}) overrides = [cmd for cmd in cmdtable if cmd in commands.table] if overrides: ui.warn(_("extension '%s' overrides commands: %s\n") % (name, " ".join(overrides))) commands.table.update(cmdtable) _loaded[name] = 1 # check for fallback encoding fallback = ui.config('ui', 'fallbackencoding') if fallback: util._fallbackencoding = fallback fullargs = args cmd, func, args, options, cmdoptions = parse(ui, args) if options["encoding"]: util._encoding = options["encoding"] if options["encodingmode"]: util._encodingmode = options["encodingmode"] ui.updateopts(options["verbose"], options["debug"], options["quiet"], not options["noninteractive"], options["traceback"]) if options['help']: return commands.help_(ui, cmd, options['version']) elif options['version']: return commands.version_(ui) elif not cmd: return commands.help_(ui, 'shortlist') repo = None if cmd not in commands.norepo.split(): try: repo = hg.repository(ui, path=path) repo.ui = ui ui.setconfig("bundle", "mainreporoot", repo.root) if not repo.local(): raise util.Abort(_("repository '%s' is not local") % path) except RepoError: if cmd not in commands.optionalrepo.split(): if not path: raise RepoError(_("There is no Mercurial repository here" " (.hg not found)")) raise d = lambda: func(ui, repo, *args, **cmdoptions) else: d = lambda: func(ui, *args, **cmdoptions) # run pre-hook, and abort if it fails ret = hook.hook(ui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) if ret: return ret # Run actual command try: ret = d() except TypeError, inst: # was this an argument error? tb = traceback.extract_tb(sys.exc_info()[2]) if len(tb) != 2: # no raise raise ParseError(cmd, _("invalid arguments"))