import: split URL parsing from code cloning

This makes things testable and easier to follow.
This commit is contained in:
Hans-Christoph Steiner 2020-02-03 12:39:41 +01:00
parent bfe587979d
commit e9a6c84efd
3 changed files with 29 additions and 24 deletions

View file

@ -89,12 +89,9 @@ config = None
options = None
def get_metadata_from_url(app, url):
def get_app_from_url(url):
tmp_dir = 'tmp'
if not os.path.isdir(tmp_dir):
logging.info(_("Creating temporary directory"))
os.makedirs(tmp_dir)
app = metadata.App()
# Figure out what kind of project it is...
projecttype = None
@ -162,18 +159,25 @@ def get_metadata_from_url(app, url):
or ' ' in repo):
raise FDroidException("Repo address '{0}' does not seem to be valid".format(repo))
# Get a copy of the source so we can extract some info...
logging.info('Getting source from ' + repotype + ' repo at ' + repo)
build_dir = os.path.join(tmp_dir, 'importer')
if os.path.exists(build_dir):
shutil.rmtree(build_dir)
vcs = common.getvcs(repotype, repo, build_dir)
vcs.gotorevision(options.rev)
app.RepoType = repotype
app.Repo = repo
return build_dir
return app
def clone_to_tmp_dir(app):
tmp_dir = 'tmp'
if not os.path.isdir(tmp_dir):
logging.info(_("Creating temporary directory"))
os.makedirs(tmp_dir)
tmp_dir = os.path.join(tmp_dir, 'importer')
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
vcs = common.getvcs(app.RepoType, app.Repo, tmp_dir)
vcs.gotorevision(options.rev)
return tmp_dir
def get_all_gradle_and_manifests(build_dir):
@ -234,8 +238,7 @@ def main():
config = common.read_config(options)
apps = metadata.read_metadata()
app = metadata.App()
app.UpdateCheckMode = "Tags"
app = None
build_dir = None
@ -245,8 +248,10 @@ def main():
build = metadata.Build()
if options.url is None and os.path.isdir('.git'):
app = metadata.App()
app.AutoName = os.path.basename(os.getcwd())
app.RepoType = 'git'
app.UpdateCheckMode = "Tags"
if os.path.exists('build.gradle'):
build.gradle = ['yes']
@ -264,7 +269,8 @@ def main():
build.commit = binascii.hexlify(bytearray(repo.head.commit.binsha))
write_local_file = True
elif options.url:
build_dir = get_metadata_from_url(app, options.url)
app = get_app_from_url(options.url)
build_dir = clone_to_tmp_dir(app)
build.commit = '?'
build.disable = 'Generated by import.py - check/set version fields and commit id'
write_local_file = False