コード例 #1
0
ファイル: __init__.py プロジェクト: pombredanne/mgit
def get_target(path, **kwargs):
    """
    :param str path: Path to target
    :param dict **kwargs: Optional preferences
    """
    prefs = MgitPreferences(**kwargs)
    actual_path = find_actual_path(path)
    if not actual_path or not os.path.isdir(actual_path):
        abort("'%s' is not a directory" % pretty_path(actual_path))
    if os.path.isdir(os.path.join(actual_path, ".git")):
        return GitCheckout(actual_path, prefs=prefs)
    return ProjectDir(actual_path, prefs=prefs)
コード例 #2
0
 def _git_command(self, args):
     """
     :param list|tuple args: Git command + args to use
     :return list, str: Full git invocation + human friendle representation
     """
     cmd = ["git"]
     if args and args[0] == "clone":
         args_represented = "git %s" % " ".join(args)
     else:
         args_represented = "git -C %s %s" % (pretty_path(
             self.path), " ".join(args))
         cmd.extend(["-C", self.path])
     cmd.extend(args)
     return cmd, args_represented
コード例 #3
0
ファイル: test_utils.py プロジェクト: pombredanne/mgit
def test_pretty_path():
    assert pretty_path(None) == '.'
    assert pretty_path('') == '.'
    assert pretty_path('/foo') == '/foo'
    assert pretty_path('../foo') == '../foo'

    user_home = os.path.expanduser('~')
    assert pretty_path(user_home) == '~'
    assert pretty_path(os.path.join(user_home, 'foo')) == '~/foo'
コード例 #4
0
ファイル: __init__.py プロジェクト: pombredanne/mgit
    def header(self):
        result = "%s:" % colored.note(pretty_path(self.path))

        if not self.projects:
            return "%s %s" % (result, colored.warn("no git folders"))

        if self.predominant:
            result += colored.highlight(
                " %s %s" %
                (len(self.projects[self.predominant]), self.predominant))

        else:
            result += colored.warn(" no predominant project")

        if self.additional:
            result += " (%s)" % colored.note(", ".join(
                "+%s %s" % (len(self.projects[project]), project)
                for project in self.additional))

        return result
コード例 #5
0
ファイル: __init__.py プロジェクト: pombredanne/mgit
    def auto_configure(self):
        """Auto-configure access token for bitbucket"""
        if self.client.headers():
            # We already have a token, configuration is done
            return True

        if not colored.is_tty():
            # We're not on a tty, can't prompt user
            LOG.warning(
                "Can't prompt for bitbucket token, not running with a tty")
            return False

        token = None
        while not token:
            token = input(
                "Please paste bitbucket token from: https://%s/plugins/servlet/auth-token/user\n"
                % self.url.hostname)  # nosec
            if not token or len(token) > 120 or len(token) < 100:
                token = None
                print("Invalid token, you can try again")
                continue
            self.client.save_headers({
                "X-Auth-User": os.environ["USER"],
                "X-Auth-Token": token
            })
            sample = self.client.get("projects/ARGUS", ttl=1)  # public repo
            if not sample:
                self.client.save_headers({})
                token = None
                print("Could not validate your token, you can try again")
                continue
            if "description" in sample:
                print("Token is valid, configuration saved in %s" %
                      pretty_path(self.client.cache_path("_headers")))
                return True
            print("Could not validate your token, you can try again: %s" %
                  sample.get("message", "<no message>"))

        return False
コード例 #6
0
ファイル: __init__.py プロジェクト: pombredanne/mgit
 def __init__(self, parent):
     self.parent = parent
     self.path = "ignores-%s.json" % pretty_path(parent.path).replace(
         "/", "-").replace("~", "-").strip("-")
     self._values = None
     self._regex = None