mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 15:13:27 +02:00
Merge branch 'version' into 'master'
Fix "fdroid --version" Closes #1164 See merge request fdroid/fdroidserver!1433
This commit is contained in:
commit
aa0b85955c
@ -23,7 +23,9 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import logging
|
import logging
|
||||||
|
import importlib.metadata
|
||||||
|
|
||||||
|
import git
|
||||||
import fdroidserver.common
|
import fdroidserver.common
|
||||||
import fdroidserver.metadata
|
import fdroidserver.metadata
|
||||||
from fdroidserver import _
|
from fdroidserver import _
|
||||||
@ -142,31 +144,21 @@ def main():
|
|||||||
print(_("""ERROR: The "server" subcommand has been removed, use "deploy"!"""))
|
print(_("""ERROR: The "server" subcommand has been removed, use "deploy"!"""))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif command == '--version':
|
elif command == '--version':
|
||||||
output = _('no version info found!')
|
try:
|
||||||
cmddir = os.path.realpath(os.path.dirname(os.path.dirname(__file__)))
|
print(importlib.metadata.version("fdroidserver"))
|
||||||
moduledir = os.path.realpath(os.path.dirname(fdroidserver.common.__file__) + '/..')
|
sys.exit(0)
|
||||||
if cmddir == moduledir:
|
except importlib.metadata.PackageNotFoundError:
|
||||||
# running from git
|
pass
|
||||||
os.chdir(cmddir)
|
try:
|
||||||
if os.path.isdir('.git'):
|
print(
|
||||||
import subprocess
|
git.repo.Repo(
|
||||||
try:
|
os.path.dirname(os.path.dirname(__file__))
|
||||||
output = subprocess.check_output(['git', 'describe'],
|
).git.describe(always=True, tags=True)
|
||||||
stderr=subprocess.STDOUT,
|
)
|
||||||
universal_newlines=True)
|
sys.exit(0)
|
||||||
except subprocess.CalledProcessError:
|
except git.exc.InvalidGitRepositoryError:
|
||||||
output = 'git commit ' + subprocess.check_output(['git', 'rev-parse', 'HEAD'],
|
print(_('No version information could be found.'))
|
||||||
universal_newlines=True)
|
sys.exit(1)
|
||||||
elif os.path.exists('setup.py'):
|
|
||||||
m = re.search(r'''.*[\s,\(]+version\s*=\s*["']([0-9a-z.]+)["'].*''',
|
|
||||||
open('setup.py').read(), flags=re.MULTILINE)
|
|
||||||
if m:
|
|
||||||
output = m.group(1) + '\n'
|
|
||||||
else:
|
|
||||||
from pkg_resources import get_distribution
|
|
||||||
output = get_distribution('fdroidserver').version + '\n'
|
|
||||||
print(output)
|
|
||||||
sys.exit(0)
|
|
||||||
else:
|
else:
|
||||||
print(_("Command '%s' not recognised.\n" % command))
|
print(_("Command '%s' not recognised.\n" % command))
|
||||||
print_help(available_plugins=available_plugins)
|
print_help(available_plugins=available_plugins)
|
||||||
|
Loading…
Reference in New Issue
Block a user