diff --git a/fdroidserver/import_subcommand.py b/fdroidserver/import_subcommand.py index 3902250e..badb9ffb 100644 --- a/fdroidserver/import_subcommand.py +++ b/fdroidserver/import_subcommand.py @@ -18,32 +18,29 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import json +import logging import os import re -import stat -import urllib - -import git -import json import shutil +import stat import sys -import yaml +import urllib from argparse import ArgumentParser -import logging from pathlib import Path from typing import Optional +import git +import yaml + try: from yaml import CSafeLoader as SafeLoader except ImportError: from yaml import SafeLoader -from . import _ -from . import common -from . import metadata +from . import _, common, metadata from .exception import FDroidException - config = None @@ -122,7 +119,7 @@ def getrepofrompage(url: str) -> tuple[Optional[str], str]: index = page.find('hg clone') if index != -1: repotype = 'hg' - repo = page[index + 9:] + repo = page[index + 9 :] index = repo.find('<') if index == -1: return (None, _("Error while getting repo address")) @@ -134,7 +131,7 @@ def getrepofrompage(url: str) -> tuple[Optional[str], str]: index = page.find('git clone') if index != -1: repotype = 'git' - repo = page[index + 10:] + repo = page[index + 10 :] index = repo.find('<') if index == -1: return (None, _("Error while getting repo address")) @@ -243,18 +240,37 @@ def main(): # Parse command line... parser = ArgumentParser() common.setup_global_opts(parser) - parser.add_argument("-u", "--url", default=None, - help=_("Project URL to import from.")) - parser.add_argument("-s", "--subdir", default=None, - help=_("Path to main Android project subdirectory, if not in root.")) - parser.add_argument("-c", "--categories", default=None, - help=_("Comma separated list of categories.")) - parser.add_argument("-l", "--license", default=None, - help=_("Overall license of the project.")) - parser.add_argument("--omit-disable", action="store_true", default=False, - help=_("Do not add 'disable:' to the generated build entries")) - parser.add_argument("--rev", default=None, - help=_("Allows a different revision (or git branch) to be specified for the initial import")) + parser.add_argument( + "-u", "--url", default=None, help=_("Project URL to import from.") + ) + parser.add_argument( + "-s", + "--subdir", + default=None, + help=_("Path to main Android project subdirectory, if not in root."), + ) + parser.add_argument( + "-c", + "--categories", + default=None, + help=_("Comma separated list of categories."), + ) + parser.add_argument( + "-l", "--license", default=None, help=_("Overall license of the project.") + ) + parser.add_argument( + "--omit-disable", + action="store_true", + default=False, + help=_("Do not add 'disable:' to the generated build entries"), + ) + parser.add_argument( + "--rev", + default=None, + help=_( + "Allows a different revision (or git branch) to be specified for the initial import" + ), + ) metadata.add_metadata_arguments(parser) options = common.parse_args(parser) metadata.warnings_action = options.W @@ -268,7 +284,9 @@ def main(): local_metadata_files = common.get_local_metadata_files() if local_metadata_files: - raise FDroidException(_("This repo already has local metadata: %s") % local_metadata_files[0]) + raise FDroidException( + _("This repo already has local metadata: %s") % local_metadata_files[0] + ) build = metadata.Build() if options.url is None and Path('.git').is_dir(): @@ -294,7 +312,9 @@ def main(): git_repo = git.Repo(tmp_importer_dir) if not options.omit_disable: - build.disable = 'Generated by `fdroid import` - check version fields and commitid' + build.disable = ( + 'Generated by `fdroid import` - check version fields and commitid' + ) write_local_file = False else: raise FDroidException("Specify project url.") @@ -405,8 +425,11 @@ def main(): Path('build').mkdir(exist_ok=True) build_dir = Path('build') / appid if build_dir.exists(): - logging.warning(_('{path} already exists, ignoring import results!') - .format(path=build_dir)) + logging.warning( + _('{path} already exists, ignoring import results!').format( + path=build_dir + ) + ) sys.exit(1) elif tmp_importer_dir: # For Windows: Close the repo or a git.exe instance holds handles to repo diff --git a/pyproject.toml b/pyproject.toml index a64bae4e..a6262ae2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,3 @@ - # We ignore the following PEP8 warnings # * E123: closing bracket does not match indentation of opening bracket's line # - Broken if multiple indentation levels start on a single line @@ -38,7 +37,6 @@ force-exclude = '''( | fdroidserver/build\.py | fdroidserver/checkupdates\.py | fdroidserver/common\.py - | fdroidserver/import_subcommand\.py | fdroidserver/index\.py | fdroidserver/metadata\.py | fdroidserver/nightly\.py diff --git a/tests/import_subcommand.TestCase b/tests/import_subcommand.TestCase index b37c2f37..646ef019 100755 --- a/tests/import_subcommand.TestCase +++ b/tests/import_subcommand.TestCase @@ -2,29 +2,30 @@ # http://www.drdobbs.com/testing/unit-testing-with-python/240165163 -import git import logging import os import shutil import sys import tempfile import unittest -import yaml -from unittest import mock from pathlib import Path +from unittest import mock +import git import requests +import yaml localmodule = Path(__file__).resolve().parent.parent print('localmodule: ' + str(localmodule)) if localmodule not in sys.path: sys.path.insert(0, str(localmodule)) +from testcommon import TmpCwd, mkdtemp, parse_args_for_test + import fdroidserver.common import fdroidserver.import_subcommand import fdroidserver.metadata from fdroidserver.exception import FDroidException -from testcommon import TmpCwd, mkdtemp, parse_args_for_test class ImportTest(unittest.TestCase):