示例#1
0
    def handle(self, *args, **options):
        # quiet = options.get('quiet', False)  # not used
        if not args:
            return
        try:
            ms = Milestone.objects.get(code=args[0])
        except:
            raise CommandError("No milestone with code %s found" % args[0])

        forest = ms.appver.trees_over_time.latest().tree.l10n.name.split('/')

        def resolve(path):
            return os.path.join(settings.REPOSITORY_BASE,
                                *(forest + path.split('/')))

        if ms.status == Milestone.SHIPPED:
            sos = ms.signoffs
        else:
            sos = accepted_signoffs(ms.appver)
        sos = dict(sos.values_list('locale__code', 'push_id'))
        tips = dict(
            Push.objects.filter(id__in=sos.values()).annotate(
                tip=Max('changesets__id')).values_list('id', 'tip'))
        revs = dict(
            Changeset.objects.filter(id__in=tips.values()).values_list(
                'id', 'revision'))
        from mercurial import dispatch
        for loc in sorted(sos.keys()):
            repopath = resolve(loc)
            rev = revs[tips[sos[loc]]]
            dispatch.dispatch(
                dispatch.request(['update', '-R', repopath, '-r', rev]))
示例#2
0
文件: update_l10n.py 项目: gerv/elmo
    def handle(self, *args, **options):
        quiet = options.get('quiet', False)
        if not args:
            return
        try:
            ms = Milestone.objects.get(code=args[0])
        except:
            raise CommandError, "No milestone with code %s found" % args[0]

        forest = ms.appver.tree.l10n.name.split('/')
        def resolve(path):
            return os.path.join(settings.REPOSITORY_BASE, *(forest + path.split('/')))

        if ms.status == Milestone.SHIPPED:
            sos = ms.signoffs
        else:
            sos = accepted_signoffs(id=ms.appver_id)
        sos=dict(sos.values_list('locale__code', 'push_id'))
        tips = dict(Push.objects.filter(id__in=sos.values()).annotate(tip=Max('changesets__id')).values_list('id', 'tip'))
        revs = dict(Changeset.objects.filter(id__in=tips.values()).values_list('id','revision'))
        from mercurial import dispatch
        for loc in sorted(sos.keys()):
            repopath = resolve(loc)
            rev = revs[tips[sos[loc]]]
            dispatch.dispatch(
                dispatch.request(['update', '-R', repopath, '-r', rev])
                )
示例#3
0
文件: hgfs.py 项目: calebcase/hgfs
    def getattr(self, path, fh=None):
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "pull", "-u"]))

        apath = os.path.join(self.tmp, path[1:])
        st = os.lstat(apath)
        return dict((key, getattr(st, key)) for key in self.ATTRS)
    def test_push_single_dir_renamed_branch(self, stupid=False):
        # Tests pulling and pushing with a renamed branch
        # Based on test_push_single_dir
        test_util.load_svndump_fixture(self.repo_path,
                                       'branch_from_tag.svndump')
        cmd = ['clone', '--layout=single', '--branch=flaf']
        if stupid:
            cmd.append('--stupid')
        cmd += [test_util.fileurl(self.repo_path), self.wc_path]
        dispatch.dispatch(cmd)

        def file_callback(repo, memctx, path):
            if path == 'adding_file':
                return context.memfilectx(path=path,
                                          data='foo',
                                          islink=False,
                                          isexec=False,
                                          copied=False)
            raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
        ctx = context.memctx(self.repo,
                             (self.repo['tip'].node(), node.nullid),
                             'automated test',
                             ['adding_file'],
                             file_callback,
                             'an_author',
                             '2009-10-19 18:49:30 -0500',
                             {'branch': 'default',})
        self.repo.commitctx(ctx)
        hg.update(self.repo, self.repo['tip'].node())
        self.pushrevisions()
        self.assertTrue('adding_file' in self.svnls(''))

        self.assertEquals(set(['flaf']),
                          set(self.repo[i].branch() for i in self.repo))
示例#5
0
def main(argv):
    log = repolib.get_logger('validate-login')
    user = argv[-1]
    path = parse_path()

    log.info("Validating login for %r on %r", user, path)

    if path:
        repo = repolib.Repository(path)
        repo.repo_path = os.getcwd()
    else:
        log.error("Invalid command")
        return 1

    if not repo.exists:
        log.error("Repo %s does not exist", repo.full_path)
        return 1

    try:
        repo.load_from_hgrc()
    except IOError:
        log.error("Could not read repo config")
        return 1

    if not repo.can_be_read_by(user):
        log.error("You can not read this repository")
        return 1

    os.environ['SSH_HG_USER'] = user
    os.environ['SSH_HG_REPO'] = repo.full_path

    log.info("All checks passed, serving.")
    dispatch.dispatch(['-R', path, 'serve', '--stdio'])
示例#6
0
文件: hgfs.py 项目: calebcase/hgfs
    def rmdir(self, path):
        _path = path[1:]
        apath = os.path.join(self.tmp, _path)
        dpath = os.path.join(self.tmp, ".hgfs", _path)
        hpath = os.path.join(self.tmp, ".hgfs", _path + ".attr")

        try:
            status = os.rmdir(dpath)
        except:
            pass

        status = os.rmdir(apath)

        try:
            status = os.unlink(hpath)
        except:
            pass

        uid, gid, pid = fuse_get_context()
        username = pwd.getpwuid(uid)[0]

        dispatch(
            request(["--cwd", self.tmp, "commit", "-A", "-u", username, "-m", "hgfs[rmdir]: %s" % (_path), str(_path)])
        )
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "push"]))

        return status
示例#7
0
文件: hgfs.py 项目: calebcase/hgfs
    def symlink(self, target, source):
        _source = source[1:]
        _target = target[1:]

        asource = os.path.join(self.tmp, _source)
        atarget = os.path.join(self.tmp, _target)

        status = os.symlink(source, atarget)

        uid, gid, pid = fuse_get_context()
        username = pwd.getpwuid(uid)[0]

        dispatch(
            request(
                [
                    "--cwd",
                    self.tmp,
                    "commit",
                    "-A",
                    "-u",
                    username,
                    "-m",
                    "hgfs[symlink]: %s -> %s" % (_target, source),
                    str(source),
                    str(_target),
                ]
            )
        )
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "push"]))

        return status
示例#8
0
文件: hgfs.py 项目: calebcase/hgfs
    def read(self, path, size, offset, fh):
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "pull", "-u"]))

        os.lseek(fh, offset, os.SEEK_SET)
        data = os.read(fh, size)

        return data
示例#9
0
文件: hgfs.py 项目: calebcase/hgfs
 def destroy(self, path):
     try:
         dispatch(request(["--cwd", self.tmp, "commit", "-A", "-u", "hgfs", "-m", "hgfs[cruft]"]))
         if self.args.clone:
             dispatch(request(["--cwd", self.tmp, "push"]))
     finally:
         if self.args.clone:
             shutil.rmtree(self.tmp)
示例#10
0
文件: hgfs.py 项目: calebcase/hgfs
    def open(self, path, flags):
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "pull", "-u"]))
            self.__load_attributes()

        _path = path[1:]
        apath = os.path.join(self.tmp, _path)

        return os.open(apath, flags)
def main():
    cwd = os.getcwd()
    readonly = False
    args = sys.argv[1:]
    while len(args):
        if args[0] == '--read-only':
            readonly = True
            args.pop(0)
        else:
            break
    allowed_paths = [
        os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
        for path in args
    ]
    orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
    try:
        cmdargv = shlex.split(orig_cmd)
    except ValueError as e:
        sys.stderr.write('Illegal command "%s": %s\n' % (orig_cmd, e))
        sys.exit(255)

    if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
        path = cmdargv[2]
        repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
        if next(
            (True for patt in allowed_paths if fnmatch.fnmatch(repo, patt)),
                False) and os.path.isdir(os.path.join(repo, '.hg')):
            cmd = ['-R', repo, 'serve', '--stdio']
            req = dispatch.request(cmd)
            if readonly:
                if not req.ui:
                    req.ui = uimod.ui.load()
                req.ui.setconfig('hooks', 'pretxnopen.hg-ssh',
                                 'python:__main__.rejectpush', 'hg-ssh')
                req.ui.setconfig('hooks', 'prepushkey.hg-ssh',
                                 'python:__main__.rejectpush', 'hg-ssh')
            dispatch.dispatch(req)
        else:
            sys.stderr.write('Illegal repository "%s"\n' % repo)
            sys.exit(255)
    elif len(cmdargv) == 3 and cmdargv[:2] == ['hg', 'init']:
        path = cmdargv[2]
        repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
        if not readonly and next(
            (True
             for patt in allowed_paths if fnmatch.fnmatch(repo, patt)), False):
            cmd = ['init', repo]
            req = dispatch.request(cmd)
            dispatch.dispatch(req)
        else:
            sys.stderr.write('Permission denied "%s"\n' % repo)
            sys.exit(255)
    else:
        sys.stderr.write('Illegal command "%s"\n' % orig_cmd)
        sys.exit(255)
示例#12
0
    def handle(self, *args, **options):
        rebase = options.get('rebase', False)
        update = options.get('update', False)
        all = options.get('all', False)
        if rebase:
            pull_args = ['--rebase']
        elif update:
            pull_args = ['-u']
        else:
            pull_args = []
        from life.models import Repository, Changeset
        from mercurial import dispatch
        import os.path
        from django.conf import settings

        def resolve(path):
            return os.path.join(settings.REPOSITORY_BASE, *path.split('/'))

        # check for last push helper file
        if not all and os.path.isfile(resolve('.latest_cs')):
            latest_cs = int(open(resolve('.latest_cs')).read())
            repos = (Repository.objects
                     .filter(changesets__id__gt=latest_cs)
                     .distinct())
        else:
            repos = Repository.objects.all()
        latest_cs = Changeset.objects.order_by('-pk')[0].id

        for name, url in repos.values_list('name', 'url'):
            repopath = str(resolve(name))
            if not os.path.isdir(os.path.join(repopath, '.hg')):
                # new repo, need to clone
                if os.path.isdir(repopath):
                    self.stdout.write(("\n\nCannot clone %s, "
                           "existing directory in the way\n\n") % name)
                    continue
                _parent = os.path.dirname(repopath)
                if not os.path.isdir(_parent):
                    try:
                        os.makedirs(_parent)
                    except Exception as e:
                        self.stdout.write(
                            ("\n\nFailed to prepare for clone, %s\n\n"
                             % str(e))
                        )
                        continue
                dispatch.dispatch(
                    dispatch.request(['clone', str(url), repopath])
                    )
            else:
                dispatch.dispatch(
                    dispatch.request(['pull', '-R', repopath] + pull_args)
                    )

        open(resolve('.latest_cs'), 'w').write('%i\n' % latest_cs)
示例#13
0
文件: hgfs.py 项目: calebcase/hgfs
    def readdir(self, path, fh):
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "pull", "-u"]))

        apath = os.path.join(self.tmp, path[1:])
        paths = os.listdir(apath)
        clean = []

        for path in paths:
            if path != ".hg" and path != ".hgfs":
                clean.append(path)

        return [".", ".."] + clean
示例#14
0
文件: hgfs.py 项目: calebcase/hgfs
    def rename(self, old, new):
        _old = old[1:]
        _new = new[1:]

        uid, gid, pid = fuse_get_context()
        username = pwd.getpwuid(uid)[0]

        dispatch(request(["--cwd", self.tmp, "mv", _old, _new]))
        dispatch(
            request(
                ["--cwd", self.tmp, "mv", os.path.join(".hgfs", _old + ".attr"), os.path.join(".hgfs", _new + ".attr")]
            )
        )
        dispatch(
            request(
                [
                    "--cwd",
                    self.tmp,
                    "commit",
                    "-u",
                    username,
                    "-m",
                    "hgfs[rename]: %s -> %s" % (_old, _new),
                    str(_old),
                    str(_new),
                ]
            )
        )
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "push"]))

        return 0
示例#15
0
def main():
    user = sys.argv[1]
    conf = sys.argv[2]

    # get original ssh command
    orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')

    try:
        cmdargv = shlex.split(orig_cmd)
    except ValueError as e:
        sys.stderr.write("Illegal command \"%s\": %s\n" % (orig_cmd, e))
        sys.exit(1)

    if cmdargv[:2] != ['hg', '-R'] or cmdargv[3:] != ['serve', '--stdio']:
        sys.stderr.write("Illegal command \"%s\"\n" % orig_cmd)
        sys.exit(1)

    repo = cmdargv[2].replace(os.sep, '', 1)
    perm = get_permissions(repo, conf)

    if not len(perm):
        sys.stderr.write("Repository \"%s\" not found\n" % repo)
        sys.exit(1)

    if 'location' not in perm:
        sys.stderr.write("Repository \"%s\" has no location\n" % repo)
        sys.exit(1)

    path = os.path.normpath(os.path.join(
        os.getcwd(),
        os.path.expanduser(perm['location'])
        ))

    if (user not in perm) or (perm[user] not in ['read', 'write']):
        sys.stderr.write("Access denied to \"%s\"\n" % repo)
        sys.exit(1)

    cmd = ['-R', path, 'serve', '--stdio']

    if perm[user] == 'read':
        cmd += [
            '--config',
            'hooks.prechangegroup.hg-ssh=python:__main__.reject_push',
            '--config',
            'hooks.prepushkey.hg-ssh=python:__main__.reject_push'
            ]

    dispatch.dispatch(dispatch.request(cmd))
示例#16
0
文件: hg.py 项目: epeli/revisioncask
def hg_serve(user, options, args):
    if not options.repository:
        raise subssh.InvalidArguments("Repository is missing")
    if not options.stdio:
        raise subssh.InvalidArguments("'--stdio' is missing")


    if not valid_repo.match(options.repository):
        subssh.errln("Illegal repository path '%s'" % options.repository)
        return 1

    repo_name = os.path.basename(options.repository.lstrip("/"))


    # Transform virtual root
    real_repository_path = os.path.join(config.REPOSITORIES, repo_name)

    repo = Mercurial(real_repository_path, subssh.config.ADMIN)

    if not repo.has_permissions(user.username, "r"):
        raise InvalidPermissions("%s has no read permissions to %s"
                                 %(user.username, options.repository))

    from mercurial.dispatch import dispatch
    return dispatch(['-R', repo.repo_path, 'serve', '--stdio'])
示例#17
0
    def get_data(self, args):
        """
        Return the data generated from mercurial.
        """
        fout = StringIO.StringIO()
        ferr = StringIO.StringIO()

        dispatch.dispatch(dispatch.request(args, None, None, None, fout, ferr))

        fout_value = fout.getvalue()
        ferr_value = ferr.getvalue()

        fout.close()
        ferr.close()

        return {"fout": base64.b64encode(fout_value), "ferr": base64.b64encode(ferr_value)}
示例#18
0
def _init(repo_root, user_name, args):
    
    # get repo path
    repo_path = None
    for i in range(len(args)):
        if args[i] == 'init':
            repo_path = args[i+1]

    # validate repo path
    if repo_path is None:
        raise RuntimeError('Invalid repository path')
    
    # get full repo path
    full_repo_path = os.path.join(repo_root, repo_path)
    
    # replace old repo path
    for i in range(len(args)):
        if args[i] == repo_path:
            args[i] = full_repo_path
    
    if dispatch(args) is None:
        with open(os.path.join(full_repo_path, '.hg', 'hgrc'), 'w') as fp:
            fp.write('''\
[web]
contact = %(user)s
description = %(path)s
''' % dict(user = user_name, path = repo_path))
        print >> sys.stderr, 'Created: %r' % full_repo_path
        
    else:
        raise RuntimeError('Failed to create: %r' % full_repo_path)
示例#19
0
文件: hgfs.py 项目: calebcase/hgfs
    def write(self, path, data, offset, fh):
        _path = path[1:]
        apath = os.path.join(self.tmp, _path)

        os.lseek(fh, offset, os.SEEK_SET)
        os.write(fh, data)

        uid, gid, pid = fuse_get_context()
        username = pwd.getpwuid(uid)[0]

        dispatch(
            request(["--cwd", self.tmp, "commit", "-A", "-u", username, "-m", "hgfs[write]: %s" % (_path), str(_path)])
        )
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "push"]))

        return len(data)
示例#20
0
def testdispatch(cmd):
    """Simple wrapper around dispatch.dispatch()

    Prints command and result value, but does not handle quoting.
    """
    print "running: %s" % (cmd,)
    result = dispatch.dispatch(cmd.split())
    print "result: %r" % (result,)
示例#21
0
def testdispatch(cmd):
    """Simple wrapper around dispatch.dispatch()

    Prints command and result value, but does not handle quoting.
    """
    print "running: %s" % (cmd, )
    result = dispatch.dispatch(cmd.split())
    print "result: %r" % (result, )
示例#22
0
def load_fixture_and_fetch(
    fixture_name, repo_path, wc_path, stupid=False, subdir="", noupdate=True, layout="auto", startrev=0, externals=None
):
    load_svndump_fixture(repo_path, fixture_name)
    if subdir:
        repo_path += "/" + subdir

    cmd = ["clone", "--layout=%s" % layout, "--startrev=%s" % startrev, fileurl(repo_path), wc_path]
    if stupid:
        cmd.append("--stupid")
    if noupdate:
        cmd.append("--noupdate")
    if externals:
        cmd[:0] = ["--config", "hgsubversion.externals=%s" % externals]

    dispatch.dispatch(cmd)

    return hg.repository(testui(), wc_path)
def testdispatch(cmd):
    """Simple wrapper around dispatch.dispatch()

    Prints command and result value, but does not handle quoting.
    """
    ui = uimod.ui.load()
    ui.status(b"running: %s\n" % cmd)
    req = dispatch.request(cmd.split(), ui)
    result = dispatch.dispatch(req)
    ui.status(b"result: %r\n" % result)
示例#24
0
文件: hgfs.py 项目: calebcase/hgfs
    def truncate(self, path, length, fh=None):
        _path = path[1:]
        apath = os.path.join(self.tmp, _path)

        if fh == None:
            with open(apath, "wb") as f:
                pass
        else:
            os.ftruncate(fh, length)

        uid, gid, pid = fuse_get_context()
        username = pwd.getpwuid(uid)[0]

        dispatch(
            request(
                ["--cwd", self.tmp, "commit", "-A", "-u", username, "-m", "hgfs[truncate]: %s" % (_path), str(_path)]
            )
        )
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "push"]))
示例#25
0
文件: hgfs.py 项目: calebcase/hgfs
    def __init__(self, repo, mountpoint=".", args={}):
        self.log.setLevel(args.log)
        self.log.debug("repo: %s mountpoint: %s args: %s", repo, mountpoint, repr(args))

        self.repo = repo
        self.mountpoint = os.path.abspath(mountpoint)
        self.args = args

        if not self.args.clone:
            self.repo = os.path.abspath(repo)

        self.log.debug("SELF: repo: %s mountpoint: %s args: %s", self.repo, self.mountpoint, repr(self.args))

        if self.args.clone:
            self.tmp = os.path.abspath(tempfile.mkdtemp(prefix="hgfs-"))
            dispatch(request(["clone", self.repo, self.tmp]))
        else:
            self.tmp = self.repo

        self.log.debug("Tmp: %s", self.tmp)

        self.__load_attributes()
示例#26
0
def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False,
                           subdir='', noupdate=True, layout='auto',
                           startrev=0, externals=None):
    load_svndump_fixture(repo_path, fixture_name)
    if subdir:
        repo_path += '/' + subdir

    cmd = [
        'clone',
        '--layout=%s' % layout,
        '--startrev=%s' % startrev,
        fileurl(repo_path),
        wc_path,
    ]
    if stupid:
        cmd.append('--stupid')
    if noupdate:
        cmd.append('--noupdate')
    if externals:
        cmd[:0] = ['--config', 'hgsubversion.externals=%s' % externals]

    dispatch.dispatch(cmd)

    return hg.repository(testui(), wc_path)
示例#27
0
def _serve(repo_root, user_name, args):
    
    # get repo path
    repo_path = None
    for i in range(len(args)):
        if args[i] == '-R':
            repo_path = args[i+1]
    
    # validate repo path
    if repo_path is None:
        raise RuntimeError('Invalid repository path')
    
    # get full repo path
    full_repo_path = os.path.join(repo_root, repo_path)
    
    # replace old repo path
    for i in range(len(args)):
        if args[i] == repo_path:
            args[i] = full_repo_path
    
    return dispatch(args)
示例#28
0
def freenetclone(orig, *args, **opts):
    def parsepushargs(ui, repo, path=None):
        return ui, repo, path

    def isfreenetpath(path):
        try:
            if path.startswith("freenet:") or path.startswith("USK@"):
                return True
        except AttributeError:
            return False
        return False

    ui, source, dest = parsepushargs(*args)
    # only act differently, if dest or source is an infocalypse repo.
    if not isfreenetpath(source) and not isfreenetpath(dest):
        return orig(*args, **opts)

    if not dest:
        if not isfreenetpath(source):
            dest = hg.defaultdest(source)
        else:  # this is a freenet key.  It has a /# at the end and
            # could contain .R1 or .R0 as pure technical identifiers
            # which we do not need in the local name.
            segments = source.split("/")
            pathindex = -2
            try:
                int(segments[-1])
            except ValueError:  # no number revision
                pathindex = -1
            dest = segments[pathindex]
            if dest.endswith(".R1") or dest.endswith(".R0"):
                dest = dest[:-3]

    # TODO: source holds the "repo" argument, but the naming is confusing in
    # the context of freenetpathtouri().
    # check whether to create, pull or copy
    pulluri, pushuri = None, None
    if isfreenetpath(source):
        pulluri = parse_repo_path(
            freenetpathtouri(ui, source, "pull", None, opts.get('truster')))

    if isfreenetpath(dest):
        pushuri = parse_repo_path(freenetpathtouri(ui,
                                                   dest,
                                                   "clone-push",
                                                   fcphost=opts['fcphost'],
                                                   fcpport=opts['fcpport']),
                                  assume_redundancy=True)

    # decide which infocalypse command to use.
    if pulluri and pushuri:
        action = "copy"
    elif pulluri:
        action = "pull"
    elif pushuri:
        action = "create"
    else:
        raise util.Abort(
            """Can't clone without source and target. This message should not be reached. If you see it, this is a bug."""
        )

    if action == "copy":
        raise util.Abort(
            """Cloning without intermediate local repo not yet supported in the simplified commands. Use fn-copy directly."""
        )

    if action == "create":
        # if the pushuri is the short form (USK@/name/#), generate the key.
        if pushuri.startswith("USK@/"):
            ui.status(
                "creating a new key for the repo. To use your default key, call fn-create.\n"
            )
            from sitecmds import genkeypair
            fcphost, fcpport = opts["fcphost"], opts["fcpport"]
            if not fcphost:
                fcphost = DEFAULT_FCP_HOST
            if not fcpport:
                fcpport = DEFAULT_FCP_PORT

            # use redundant keys by default, except if explicitely requested otherwise.
            namepart = pushuri[5:]
            namepart = fixnamepart(namepart)
            insert, request = genkeypair(fcphost, fcpport)
            pushuri = "USK" + insert[3:] + namepart
        elif pushuri.endswith("/0"):  # initial create, catch the no-.R1 error
            pass
            # this rewriting is dangerous here since it could make it
            # impossible to update old repos when they drop
            # out. Leaving it commented out for now. TODO: Always
            # treat a name without .R0 as requesting redundancy *in.
            # the backend*. Keep it as /name/#, but add /name.Rn/0
            # backup repos. Needs going into the backend.

            #namepart = pushuri.split("/")[-2] + "/0"
            #namepartpos = -len(namepart)
            #namepart2 = fixnamepart(namepart)
            # if namepart2 != namepart:
            # ui.status("changed the repo name to " + namepart2 + " to have more redundancy and longer lifetime. This is a small tweak on infocalypse to avoid the frequent error of forgetting to add .R1 to the name. If you really want no additional redundancy for your repo, use NAME.R0 or call hg fn-create directly.\n")
            #pushuri = pushuri[:namepartpos] + namepart
        opts["uri"] = pushuri
        repo = hg.repository(ui, ui.expandpath(source))
        # TODO: A local identity is looked up for the push URI,
        # but not returned, yet it is required to update configuration.
        # Expecting dest to be something like freenet://name@key/reponame
        local_identifier = strip_protocol(dest).split('/')[0]

        from wot_id import Local_WoT_ID
        from wot import get_fcpopts
        local_identity = Local_WoT_ID(
            local_identifier,
            get_fcpopts(fcphost=opts["fcphost"], fcpport=opts["fcpport"]))

        infocalypse_create(ui, repo, local_identity, **opts)

        # TODO: Function for adding paths? It's currently here, for pull,
        # and in WoT pull URI resolution.
        with repo.opener("hgrc", "a", text=True) as f:
            f.write("""[paths]
default-push = freenet:{0}
""".format(pushuri))

    if action == "pull":
        if os.path.exists(dest):
            raise util.Abort(_("destination " + dest + " already exists."))
        # create the repo
        req = dispatch.request(["init", dest], ui=ui)
        dispatch.dispatch(req)
        # pull the data from freenet
        origdest = ui.expandpath(dest)
        dest, branch = hg.parseurl(origdest)
        destrepo = hg.repository(ui, dest)
        infocalypse_pull(ui,
                         destrepo,
                         aggressive=True,
                         hash=None,
                         uri=pulluri,
                         **opts)
        # store the request uri for future updates
        _hgrc_template = """[paths]
default = freenet://{pulluri}

[ui]
username = anonymous

[alias]
clt = commit
ci = !$HG clt --date "$(date -u "+%Y-%m-%d %H:%M:%S +0000")" "$@"
commit = !$HG clt --date "$(date -u "+%Y-%m-%d %H:%M:%S +0000")" "$@"
"""
        # alternative: every commit is done at 09:42:30 (might be
        # confusing but should be safest): date -u "+%Y-%m-%d 09:42:30 +0000

        # second alternative: commit done at local time but with
        # timezone +0000 (could be correlated against forum entries
        # and such to find the real timezone): Leave out the -u
        with destrepo.opener("hgrc", "a", text=True) as f:
            f.write(_hgrc_template.format(pulluri=pulluri))

        ui.warn("As basic protection, infocalypse automatically \n"
                "  set the username 'anonymous' for commits in this repo, \n"
                "  changed the commands `commit` and `ci` to fake UTC time \n"
                "  and added `clt` which commits in the local timezone. \n"
                "  To change this, edit " +
                str(os.path.join(destrepo.root, ".hg", "hgrc")) + "\n")
        # and update the repo
        return hg.update(destrepo, None)
示例#29
0
def main():
    cwd = os.getcwd()
    user = sys.argv[1]
    conf = sys.argv[2]

    # Get the original SSH Command sent through. The repo should be the item after the connect string
    orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')

    try:
        cmdargv = shlex.split(orig_cmd)

    # Changed to "as" here for Python 3.3 compatibility
    except ValueError as e:
        sys.stderr.write('Illegal command "%s": %s\n' % (orig_cmd, e))
        sys.exit(255)

    if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
        try:

            # Now we need to extract the repository name (what is in the conf file)
            repository = cmdargv[2].replace(os.sep, '', 1)

            # Get the repository and users from the config file (or get a blank {})
            perms = get_permission(repository, conf)

            # If the returned dict is empty, then exit this process. This means no section with
            # the named repository exist!
            if not len(perms):
                sys.stderr.write('No repository found for "%s"\n' % repository)
                sys.exit(255)

            # This is the reason we are using a try in case this key does not exist.
            # 'location' param under repository section contains the relative or absolute path
            # to the repository on the file system from the current working
            # directory which can be changed in the authorized_keys
            path = perms['location']

            # Get the path of the repository to be used with hg commands below.
            # This is the translation between the section name in the conf file and
            # the location param that points to the actual directory on the file system
            # By default, this uses cwd (Current working directory) and can be changed in the
            # authorized_keys file in the command section by using 'cd /path/to/start/from && '
            # as the first part of the command string before calling this script.
            repo = os.path.normpath(os.path.join(cwd,
                                                 os.path.expanduser(path)))

        except KeyError:
            sys.stderr.write('Invalid Repository "%s"\n' % repository)
            sys.exit(255)

        # We will try and get the username out of the config, if it is not present, we exit!
        # We will also check to make sure the access is set to read or write. If Not, goodbye!
        try:
            access = perms[user]
        except:
            sys.stderr.write('Illegal Repository "%s"\n' % repo)
            sys.exit(255)

        # If the user does not have read or write (write implies read) we exit.
        if access not in ['read', 'write']:
            sys.stderr.write('Access denied to "%s"\n' % repository)
            sys.exit(255)

        cmd = ['-R', repo, 'serve', '--stdio']
        if access == "read":
            cmd += [
                '--config',
                'hooks.prechangegroup.hg-ssh=python:__main__.rejectpush',
                '--config',
                'hooks.prepushkey.hg-ssh=python:__main__.rejectpush'
            ]

        dispatch.dispatch(dispatch.request(cmd))

    else:
        sys.stderr.write('Illegal command "%s"\n' % orig_cmd)
        sys.exit(255)
示例#30
0
文件: hgfs.py 项目: calebcase/hgfs
    def readlink(self, path):
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "pull", "-u"]))

        apath = os.path.join(self.tmp, path[1:])
        return os.readlink(apath)
示例#31
0
def dispatch(cmd):
    assert '--quiet' in cmd
    cmd = getattr(dispatchmod, 'request', lambda x: x)(cmd)
    return dispatchmod.dispatch(cmd)
示例#32
0
文件: hgcompat.py 项目: stasm/elmo
 def dispatch(*args):
     return _dispatch.dispatch(_dispatch.request(*args))
示例#33
0
from mercurial.dispatch import dispatch

args = [’clone’,’http://petsc.cs.iit.edu/petsc/tutorials/vecfem]
dispatch(args)
示例#34
0
文件: hgcompat.py 项目: lauraxt/elmo
 def dispatch(*args):
     return _dispatch.dispatch(*args)
示例#35
0
文件: hgfs.py 项目: calebcase/hgfs
        apath = os.path.join(self.tmp, _path)
        st = os.stat(apath)

        attributes = dict((key, getattr(st, key)) for key in self.ATTRS)

        uid, gid, pid = fuse_get_context()
        username = pwd.getpwuid(uid)[0]
        attributes[".hgfs"] = {"pw_uid": uid, "pw_name": username, "gr_gid": gid, "gr_name": grp.getgrgid(gid)[0]}

        modpath = os.path.join(self.tmp, ".hgfs", _path + ".attr")
        with open(modpath, "wb+") as f:
            f.write(json.dumps(attributes, sort_keys=True, indent=2))

        ahgfs = os.path.join(self.tmp, ".hgfs")

        dispatch(request(["--cwd", self.tmp, "commit", "-A", "-u", username, "-m", msg, ".hgfs", str(_path)]))
        if self.args.clone:
            dispatch(request(["--cwd", self.tmp, "push"]))

    def access(self, path, mode):
        _path = path[1:]
        apath = os.path.join(self.tmp, _path)

        if not os.access(apath, mode):
            raise FuseOSError(EACCES)

    def chmod(self, path, mode):
        _path = path[1:]
        apath = os.path.join(self.tmp, _path)
        status = os.chmod(apath, mode)
示例#36
0
def runcmd():
    dispatch.dispatch(dispatch.request(['version', '-q'], ui_))
示例#37
0
def runcmd():
    dispatch.dispatch(dispatch.request(['version', '-q'], ui_))
示例#38
0
文件: vcs_ssh.py 项目: cans/vcs-ssh
 def hg_dispatch(cmdargv):
     logger.debug(_("Using in-process Mercurial dispatch"))
     return dispatch.dispatch(dispatch.request(cmdargv))
示例#39
0
文件: hgcompat.py 项目: stasm/elmo
 def dispatch(*args):
     return _dispatch.dispatch(*args)
示例#40
0
文件: hgcompat.py 项目: lauraxt/elmo
 def dispatch(*args):
     return _dispatch.dispatch(_dispatch.request(*args))
示例#41
0
def dispatch(cmd):
    cmd = getattr(dispatchmod, 'request', lambda x: x)(cmd)
    return dispatchmod.dispatch(cmd)
示例#42
0
文件: hgssh2.py 项目: dengzhp/hgssh2
        sys.stderr.write('Illegal command "%s": %s\n' % (orig_cmd, e))
        sys.exit(255)

    if cmdargv[:2] == ['hg', '-R'] and cmdargv[3:] == ['serve', '--stdio']:
        path = cmdargv[2]
        repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
        if path in perms:
            cmd = ['-R', repo, 'serve', '--stdio']
            if perms[path] == "read":
                cmd += [
                    '--config',
                    'hooks.prechangegroup.hg-ssh=python:__main__.rejectpush',
                    '--config',
                    'hooks.prepushkey.hg-ssh=python:__main__.rejectpush'
                    ]
            dispatch.dispatch(dispatch.request(cmd))
        else:
            sys.stderr.write('Illegal repository "%s"\n' % repo)
            sys.exit(255)
    else:
        sys.stderr.write('Illegal command "%s"\n' % orig_cmd)
        sys.exit(255)

def rejectpush(ui, **kwargs):
    ui.warn("Permission denied\n")
    # mercurial hooks use unix process conventions for hook return values
    # so a truthy return means failure
    return True

if __name__ == '__main__':
    main()