Ejemplo n.º 1
0
    def __init__(self):
        self.shell = whelk.Shell(encoding='utf-8')
        self.git = self.shell.git
        self.git_dir = self.git('rev-parse', '--git-dir')
        if self.git_dir.returncode == 0:
            self.git_dir = os.path.abspath(self.git_dir.stdout.strip())
        else:
            self.git_dir = None
        self.in_repo = bool(self.git_dir)
        self.config_file = os.path.join(os.path.expanduser('~'), '.gitspindle')
        xdg_dir = os.environ.get(
            'XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'),
                                            '.config'))
        xdg_file = os.path.join(xdg_dir, 'git', 'spindle')
        if os.path.exists(xdg_file):
            self.config_file = xdg_file
        self.commands = {}
        self.accounts = {}
        self.my_login = {}
        self.use_credential_helper = self.git(
            'config', 'credential.helper').stdout.strip() not in ('', 'cache')

        self.usage = DocoptExit.help = """%s - %s integration for git
A full manual can be found on http://seveas.github.com/git-spindle/

Usage:\n""" % (self.prog, self.what)
        DocoptExit.help += "  %s [options] <command> [command-options]\n\nCommands:\n" % (
            self.prog)
        for name in sorted(dir(self)):
            fnc = getattr(self, name)
            if not getattr(fnc, 'is_command', False):
                continue
            if name.endswith('_'):
                name = name[:-1]
            name = name.replace('_', '-')
            self.commands[name] = fnc
            doc = [line.strip() for line in fnc.__doc__.splitlines()]
            if self.__class__.__name__ == 'BitBucket' and name == 'add-account':
                doc[0] = doc[0].replace('[--host=<host>] ', '')
            if doc[0]:
                doc[0] = ' ' + doc[0]
            help = '%s:\n  %s %s %s%s\n' % (doc[1], self.prog, '[options]',
                                            name, doc[0])
            self.usage += help
            DocoptExit.commands[name] = help
            DocoptExit.help += '  %-25s%s\n' % (name, doc[1])
        tail = """
Options:
  -h --help              Show this help message and exit
  --desc=<description>   Description for the new gist/repo
  --parent               Use the parent of a forked repo
  --yes                  Automatically answer yes to questions
  --issue=<issue>        Turn this issue into a pull request
  --http                 Use https:// urls for cloning 3rd party repos
  --ssh                  Use ssh:// urls for cloning 3rd party repos
  --git                  Use git:// urls for cloning 3rd party repos
  --goblet               When mirroring, set up goblet configuration
  --account=<account>    Use another account than the default\n"""
        self.usage += tail
        DocoptExit.help += tail
Ejemplo n.º 2
0
    def __init__(self):
        self.shell = whelk.Shell(encoding='utf-8')
        self.git = self.shell.git
        self.git_dir = self.git('rev-parse', '--git-dir')
        if self.git_dir.returncode == 0:
            self.git_dir = os.path.abspath(self.git_dir.stdout.strip())
        else:
            self.git_dir = None
        self.in_repo = bool(self.git_dir)
        self.config_file = os.path.join(os.path.expanduser('~'), '.gitspindle')
        xdg_dir = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config'))
        xdg_file = os.path.join(xdg_dir, 'git', 'spindle')
        if os.path.exists(xdg_file):
            self.config_file = xdg_file
        self.commands = {}
        self.accounts = {}
        self.my_login = {}
        self.use_credential_helper = self.git('config', 'credential.helper').stdout.strip() not in ('', 'cache')

        self.usage = """%s - %s integration for git
A full manual can be found on http://seveas.github.com/git-spindle/

Usage:\n""" % (self.prog, self.what)
        for name in sorted(dir(self)):
            fnc = getattr(self, name)
            if not getattr(fnc, 'is_command', False):
                continue
            if name.endswith('_'):
                name = name[:-1]
            name = name.replace('_', '-')
            self.commands[name] = fnc
            self.usage += '\n%s\n' % self.command_usage(name)
        self.usage += """
Ejemplo n.º 3
0
    def __init__(self):
        self.shell = whelk.Shell(encoding='utf-8')
        self.git = self.shell.git
        self.git_dir = self.git('rev-parse', '--git-dir')
        if self.git_dir.returncode == 0:
            self.git_dir = os.path.abspath(self.git_dir.stdout.strip())
        else:
            self.git_dir = None
        self.in_repo = bool(self.git_dir)
        self.config_file = os.path.join(os.path.expanduser('~'), '.gitspindle')
        self.commands = {}
        self.usage = """%s - %s integration for git
A full manual can be found on http://seveas.github.com/git-spindle/

Usage:\n""" % (self.prog, self.what)
        for name in sorted(dir(self)):
            fnc = getattr(self, name)
            if not getattr(fnc, 'is_command', False):
                continue
            name = name.replace('_', '-')
            self.commands[name] = fnc
            self.usage += (
                '  %s %s %s\n' %
                (self.prog, name, fnc.__doc__.split('\n', 1)[0].strip()))
        self.usage += """
Ejemplo n.º 4
0
class Credential(object):
    shell = whelk.Shell(encoding='utf-8')
    params = ['protocol', 'host', 'path', 'username', 'password']

    def __init__(self, protocol, host, path='', username='', password=''):
        self.protocol = protocol
        self.host = host
        self.path = path
        self.username = username
        self.password = password

    def __str__(self):
        return '%s://%s:%s@%s/%s' % (self.protocol, self.username, self.password, self.host, self.path)

    def __repr__(self):
        return '<Credential %s>' % str(self)

    def fill(self):
        self.communicate('fill')

    def fill_noninteractive(self):
        env = os.environ.copy()
        env['GIT_TERMINAL_PROMPT'] = '0'
        env.pop('GIT_ASKPASS', None)
        env.pop('SSH_ASKPASS', None)
        self.communicate('fill', env=env)

    def approve(self):
        if not self.username or not self.password:
            raise ValueError("No username or password specified")
        self.communicate('approve')

    def reject(self):
        if not self.username:
            raise ValueError("No username specified")
        self.communicate('reject')
        self.password = ''

    def communicate(self, action, env=os.environ):
        data = self.format() + '\n\n'
        if env.get('GIT_TERMINAL_PROMPT', None) == '0':
            ret = self.shell.git('-c', 'core.askpass='******'credential', action, env=env, input=data)
        else:
            ret = self.shell.git('credential', action, env=env, input=data)
        if not ret:
            if 'terminal prompts disabled' not in ret.stderr:
                raise RuntimeError("git credential %s failed: %s" % (action, ret.stderr))
        self.parse(ret.stdout)

    def format(self):
        return '\n'.join(['%s=%s' % (x, getattr(self, x)) for x in self.params if getattr(self, x)])

    def parse(self, text):
        for key, val in [line.split('=', 1) for line in text.splitlines() if line]:
            if key not in self.params:
                raise ValueError("Unexpected data: %s=%s" % (key, val))
            setattr(self, key, val)
Ejemplo n.º 5
0
    def __init__(self):
        self.shell = whelk.Shell(encoding='utf-8')
        self.git = self.shell.git
        self.git_dir = self.git('rev-parse', '--git-dir')
        if self.git_dir.returncode == 0:
            self.git_dir = os.path.abspath(self.git_dir.stdout.strip())
        else:
            self.git_dir = None
        self.in_repo = bool(self.git_dir)
        self.config_file = os.path.join(os.path.expanduser('~'), '.gitspindle')
        xdg_dir = os.environ.get(
            'XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'),
                                            '.config'))
        xdg_file = os.path.join(xdg_dir, 'git', 'spindle')
        if os.path.exists(xdg_file):
            self.config_file = xdg_file
        self.commands = {}
        self.accounts = {}
        self.my_login = {}
        self.use_credential_helper = self.git(
            'config', 'credential.helper').stdout.strip() not in ('', 'cache')

        self.usage = """%s - %s integration for git
A full manual can be found on http://seveas.github.com/git-spindle/

Usage:\n""" % (self.prog, self.what)
        for name in sorted(dir(self)):
            fnc = getattr(self, name)
            if not getattr(fnc, 'is_command', False):
                continue
            if name.endswith('_'):
                name = name[:-1]
            name = name.replace('_', '-')
            self.commands[name] = fnc
            doc = [line.strip() for line in fnc.__doc__.splitlines()]
            if self.__class__.__name__ == 'BitBucket' and name == 'add-account':
                doc[0] = doc[0].replace('[--host=<host>] ', '')
            if doc[0]:
                doc[0] = ' ' + doc[0]
            self.usage += '%s:\n  %s %s %s%s\n' % (doc[1], self.prog,
                                                   '[options]', name, doc[0])
        self.usage += """