[import] Rename to import_subcommand internally

This enables normal import of the module without the need for
workarounds.
This commit is contained in:
FestplattenSchnitzel 2022-08-05 19:34:28 +02:00 committed by Hans-Christoph Steiner
parent 2eb56ae8d4
commit 7b7f863c65
6 changed files with 11 additions and 41 deletions

View File

@ -254,8 +254,7 @@ black:
tests/build.TestCase
tests/deploy.TestCase
tests/exception.TestCase
tests/import.TestCase
tests/import_proxy.py
tests/import_subcommand.TestCase
tests/init.TestCase
tests/install.TestCase
tests/key-tricks.py

View File

@ -567,8 +567,7 @@ include tests/gnupghome/secring.gpg
include tests/gnupghome/trustdb.gpg
include tests/gradle-maven-blocks.yaml
include tests/gradle-release-checksums.py
include tests/import_proxy.py
include tests/import.TestCase
include tests/import_subcommand.TestCase
include tests/index.TestCase
include tests/init.TestCase
include tests/install.TestCase

View File

@ -40,7 +40,7 @@ COMMANDS = OrderedDict([
("deploy", _("Interact with the repo HTTP server")),
("verify", _("Verify the integrity of downloaded packages")),
("checkupdates", _("Check for updates to applications")),
("import", _("Add a new application from its source code")),
("import", _("Extract application metadata from a source repository")),
("install", _("Install built packages on devices")),
("readmeta", _("Read all the metadata files and exit")),
("rewritemeta", _("Rewrite all the metadata files")),
@ -197,6 +197,8 @@ def main():
del sys.argv[1]
if command in COMMANDS.keys():
# import is named import_subcommand internally b/c import is reserved by Python
command = 'import_subcommand' if command == 'import' else command
mod = __import__('fdroidserver.' + command, None, None, [command])
else:
mod = __import__(available_plugins[command]['name'], None, None, [command])

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# import.py - part of the FDroid server tools
# import_subcommand.py - part of the FDroid server tools
# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
# Copyright (C) 2013-2014 Daniel Martí <mvdan@mvdan.cc>
#
@ -42,9 +42,6 @@ config = None
options = None
# WARNING! This cannot be imported as a Python module, so reuseable functions need to go into common.py!
def clone_to_tmp_dir(app):
tmp_dir = Path('tmp')
tmp_dir.mkdir(exist_ok=True)

View File

@ -1,27 +0,0 @@
# workaround the syntax error from: import fdroidserver.import
import inspect
import sys
from pathlib import Path
localmodule = Path(__file__).resolve().parent.parent
print('localmodule: ' + str(localmodule))
if localmodule not in sys.path:
sys.path.insert(0, str(localmodule))
class Options:
def __init__(self):
self.rev = None
self.subdir = None
module = __import__('fdroidserver.import')
for name, obj in inspect.getmembers(module):
if name == 'import':
clone_to_tmp_dir = obj.clone_to_tmp_dir
obj.options = Options()
options = obj.options
break
globals().update(vars(module))

View File

@ -15,15 +15,13 @@ from pathlib import Path
import requests
from testcommon import TmpCwd
# work around the syntax error from: import fdroidserver.import
import import_proxy
localmodule = Path(__file__).resolve().parent.parent
print('localmodule: ' + str(localmodule))
if localmodule not in sys.path:
sys.path.insert(0, str(localmodule))
import fdroidserver.common
import fdroidserver.import_subcommand
import fdroidserver.metadata
@ -37,6 +35,8 @@ class ImportTest(unittest.TestCase):
self.tmpdir.mkdir(exist_ok=True)
# TODO: Python3.6: Accepts a path-like object.
os.chdir(str(self.basedir))
fdroidserver.import_subcommand.options = mock.Mock()
fdroidserver.import_subcommand.options.rev = None
def test_import_gitlab(self):
# FDroidPopen needs some config to work
@ -52,7 +52,7 @@ class ImportTest(unittest.TestCase):
return
app = fdroidserver.common.get_app_from_url(url)
import_proxy.clone_to_tmp_dir(app)
fdroidserver.import_subcommand.clone_to_tmp_dir(app)
self.assertEqual(app.RepoType, 'git')
self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/ci-test-app.git')
@ -103,7 +103,7 @@ class ImportTest(unittest.TestCase):
), mock.patch(
'shutil.rmtree', lambda a, onerror=None: None
):
build_dir = import_proxy.clone_to_tmp_dir(app)
build_dir = fdroidserver.import_subcommand.clone_to_tmp_dir(app)
self.assertEqual('git', app.RepoType)
self.assertEqual(url, app.Repo)
self.assertEqual(url, app.SourceCode)