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