Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
common: remove get_version
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed Jan 31, 2018
1 parent f64b2ae commit 01ceae3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bin/lulu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sys.path.insert(1, os.path.join(_filepath, _srcdir))
if sys.version_info[0] == 3:
import lulu
if __name__ == '__main__':
lulu.main(repo_path=_filepath)
lulu.main()
else: # Python 2
from lulu.util import log
log.e('[fatal] Python 3 is required!')
5 changes: 1 addition & 4 deletions lulu/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from lulu import config
from lulu.util import log, term
from lulu.version import __version__
from lulu.util.git import get_version
from lulu import json_output as json_output_
from lulu.util.strings import (
get_filename,
Expand Down Expand Up @@ -1176,9 +1175,7 @@ def script_main(download, download_playlist, **kwargs):
logging.basicConfig(format='[%(levelname)s] %(message)s')

def print_version():
version = get_version(
kwargs['repo_path'] if 'repo_path' in kwargs else __version__
)
version = __version__
log.i(
'version {}, a tiny downloader that scrapes the web.'.format(
version
Expand Down
37 changes: 8 additions & 29 deletions lulu/util/git.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
#!/usr/bin/env python

import os
import subprocess
from ..version import __version__


def get_head(repo_path):
"""Get (branch, commit) from HEAD of a git repo."""
try:
ref = open(os.path.join(repo_path, '.git', 'HEAD'), 'r').read().strip()[5:].split('/')
ref = open(
os.path.join(repo_path, '.git', 'HEAD'), 'r'
).read().strip()[5:].split('/')
branch = ref[-1]
commit = open(os.path.join(repo_path, '.git', *ref), 'r').read().strip()[:7]
commit = open(
os.path.join(repo_path, '.git', *ref), 'r'
).read().strip()[:7]
return branch, commit
except:
except Exception:
return None

def get_version(repo_path):
try:
version = __version__.split('.')
major, minor, cn = [int(i) for i in version]
p = subprocess.Popen(['git',
'--git-dir', os.path.join(repo_path, '.git'),
'--work-tree', repo_path,
'rev-list', 'HEAD', '--count'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw, err = p.communicate()
c_head = int(raw.decode('ascii'))
q = subprocess.Popen(['git',
'--git-dir', os.path.join(repo_path, '.git'),
'--work-tree', repo_path,
'rev-list', 'master', '--count'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw, err = q.communicate()
c_master = int(raw.decode('ascii'))
cc = c_head - c_master
assert cc
return '%s.%s.%s' % (major, minor, cn + cc)
except:
return __version__

0 comments on commit 01ceae3

Please sign in to comment.