Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --version #182

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 34 additions & 2 deletions git_repo/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{self} [--path=<path>] [-v...] <target> (gist|snippet) delete <gist> [-f]
{self} [--path=<path>] [-v...] <target> config [--config=<gitconfig>]
{self} [-v...] config [--config=<gitconfig>]
{self} --version
{self} --help

Tool for managing remote repository services.
Expand All @@ -52,6 +53,7 @@
<namespace>/<repo> Repository to work with
-p,--path=<path> Path to work on [default: .]
-v,--verbose Makes it more chatty (repeat twice to see git commands)
--version Show the version
-h,--help Shows this message

Options for list:
Expand Down Expand Up @@ -142,7 +144,7 @@
from .tools import print_tty, print_iter, loop_input, confirm
from .kwargparse import KeywordArgumentParser, store_parameter, register_action

from git import Repo, Git
from git import Repo, Git, __version__ as GitPythonVersion
from git.exc import InvalidGitRepositoryError, NoSuchPathError, BadName

class GitRepoRunner(KeywordArgumentParser):
Expand Down Expand Up @@ -586,9 +588,39 @@ def main(args):
return 2


class Version:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to either:

def __str__(self):
import importlib
s = ['Version: {}'.format(__version__),
' GitPython: {}'.format(GitPythonVersion),
' Services:'
]
services = RepositoryService.service_map.values()

for service in sorted(services, key=lambda s: s.name):
version = 'unknown'
try:
mod = importlib.import_module(service.__module__)
package = mod.SERVICE_PACKAGE
client = package.__name__
except:
client = 'unknown'
else:
try:
version = package.__version__
except AttributeError:
pass

s.append(' {}:'.format(service.name))
s.append(' {}: {}'.format(client, version))

return '\n'.join(s)


def cli(): # pragma: no cover
try:
sys.exit(main(docopt(__doc__.format(self=sys.argv[0].split(os.path.sep)[-1], version=__version__))))
sys.exit(main(docopt(__doc__.format(self=sys.argv[0].split(os.path.sep)[-1], version=__version__),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the --help version should also contain --version

version=Version())))
finally:
# Whatever happens, make sure that the cursor reappears with some ANSI voodoo
if sys.stdout.isatty():
Expand Down
4 changes: 4 additions & 0 deletions git_repo/services/ext/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ...exceptions import ResourceError, ResourceExistsError, ResourceNotFoundError
from ...tools import columnize

import pybitbucket
from pybitbucket.bitbucket import Client, Bitbucket
from pybitbucket.auth import BasicAuthenticator
from pybitbucket.pullrequest import PullRequest, PullRequestPayload
Expand All @@ -26,6 +27,9 @@
import os, json, platform


SERVICE_PACKAGE = pybitbucket
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like that pattern, it feels a bit redundant with the register target decorator. What I'd rather do is either make a new decorator that manages version, or add an argument to register_target with the version string.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other better side of that is that you don't need the full loading of the module into the main system, and if a module has a version string that's not standard (i.e. not using __version__ we're good for that.



@register_target('bb', 'bitbucket')
class BitbucketService(RepositoryService):
fqdn = 'bitbucket.org'
Expand Down
4 changes: 4 additions & 0 deletions git_repo/services/ext/gitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

import github3


SERVICE_PACKAGE = github3


@register_target('bucket', 'gitbucket')
class GitbucketService(GithubService):
fqdn = "localhost"
Expand Down
4 changes: 4 additions & 0 deletions git_repo/services/ext/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

from datetime import datetime


SERVICE_PACKAGE = github3


GITHUB_COM_FQDN = 'github.com'

@register_target('hub', 'github')
Expand Down
8 changes: 8 additions & 0 deletions git_repo/services/ext/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import dateutil.parser
from datetime import datetime


SERVICE_PACKAGE = gitlab


@register_target('lab', 'gitlab')
class GitlabService(RepositoryService):
fqdn = 'gitlab.com'
Expand All @@ -41,6 +45,10 @@ def connect(self):
self.gl.auth()
self.username = self.gl.user.username

def server_version(self):
self.connect()
return self.gl.version()

def create(self, user, repo, add=False):
try:
group = self.gl.groups.search(user)
Expand Down
6 changes: 6 additions & 0 deletions git_repo/services/ext/gogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from ...exceptions import ResourceError, ResourceExistsError, ResourceNotFoundError
from ...tools import columnize

import gogs_client

from gogs_client import GogsApi, GogsRepo, Token, UsernamePassword, ApiFailure
from requests import Session, HTTPError
from urllib.parse import urlparse, urlunparse
Expand All @@ -17,6 +19,10 @@
from git import config as git_config
from git.exc import GitCommandError


SERVICE_PACKAGE = gogs_client


class GogsClient(GogsApi):
def __init__(self):
self.session = Session()
Expand Down