Merge branch 'import-kivy' into 'master'

import kivy and two fixes

See merge request fdroid/fdroidserver!778
This commit is contained in:
Hans-Christoph Steiner 2020-08-07 11:09:12 +00:00
commit 838eee355f
4 changed files with 75 additions and 16 deletions

View file

@ -17,6 +17,7 @@
# 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/>.
import configparser
import git
import json
import os
@ -58,6 +59,44 @@ def clone_to_tmp_dir(app):
return tmp_dir
def check_for_kivy_buildozer(tmp_importer_dir, app, build):
versionCode = None
buildozer_spec = os.path.join(tmp_importer_dir, 'buildozer.spec')
if os.path.exists(buildozer_spec):
config = configparser.ConfigParser()
config.read(buildozer_spec)
import pprint
pprint.pprint(sorted(config['app'].keys()))
app.id = config['app'].get('package.domain')
print(app.id)
app.AutoName = config['app'].get('package.name', app.AutoName)
app.License = config['app'].get('license', app.License)
app.Description = config['app'].get('description', app.Description)
build.versionName = config['app'].get('version')
build.output = 'bin/%s-$$VERSION$$-release-unsigned.apk' % app.AutoName
build.ndk = 'r17c'
build.srclibs = [
'buildozer@586152c',
'python-for-android@ccb0f8e1',
]
build.sudo = [
'apt-get update',
'apt-get install -y build-essential libffi-dev libltdl-dev',
]
build.prebuild = [
'sed -iE "/^[# ]*android\\.(ant|ndk|sdk)_path[ =]/d" buildozer.spec',
'sed -iE "/^[# ]*android.accept_sdk_license[ =]+.*/d" buildozer.spec',
'sed -iE "/^[# ]*android.skip_update[ =]+.*/d" buildozer.spec',
'sed -iE "/^[# ]*p4a.source_dir[ =]+.*/d" buildozer.spec',
'sed -i "s,\\[app\\],[app]\\n\\nandroid.sdk_path = $$SDK$$\\nandroid.ndk_path = $$NDK$$\\np4a.source_dir = $$python-for-android$$\\nandroid.accept_sdk_license = False\\nandroid.skip_update = True\\nandroid.ant_path = /usr/bin/ant\\n," buildozer.spec',
'pip3 install --user --upgrade $$buildozer$$ Cython==0.28.6',
]
build.build = [
'PATH="$HOME/.local/bin:$PATH" buildozer android release',
]
return build.get('versionName'), versionCode, app.get('id')
def main():
global config, options
@ -123,23 +162,25 @@ def main():
app.UpdateCheckMode = 'Tags'
build.commit = common.get_head_commit_id(git_repo)
versionName, versionCode, appid = check_for_kivy_buildozer(tmp_importer_dir, app, build)
# Extract some information...
paths = common.get_all_gradle_and_manifests(tmp_importer_dir)
subdir = common.get_gradle_subdir(tmp_importer_dir, paths)
if paths:
versionName, versionCode, package = common.parse_androidmanifests(paths, app)
if not package:
raise FDroidException(_("Couldn't find package ID"))
versionName, versionCode, appid = common.parse_androidmanifests(paths, app)
if not appid:
raise FDroidException(_("Couldn't find Application ID"))
if not versionName:
logging.warning(_('Could not find latest version name'))
if not versionCode:
logging.warning(_('Could not find latest version code'))
else:
elif not appid:
raise FDroidException(_("No gradle project could be found. Specify --subdir?"))
# Make sure it's actually new...
if package in apps:
raise FDroidException("Package " + package + " already exists")
if appid in apps:
raise FDroidException(_('Package "{appid}" already exists').format(appid=appid))
# Create a build line...
build.versionName = versionName or 'Unknown'
@ -205,17 +246,17 @@ def main():
# Keep the repo directory to save bandwidth...
if not os.path.exists('build'):
os.mkdir('build')
build_dir = os.path.join('build', package)
build_dir = os.path.join('build', appid)
if os.path.exists(build_dir):
logging.warning(_('{path} already exists, ignoring import results!')
.format(path=build_dir))
sys.exit(1)
elif tmp_importer_dir is not None:
shutil.move(tmp_importer_dir, build_dir)
with open('build/.fdroidvcs-' + package, 'w') as f:
with open('build/.fdroidvcs-' + appid, 'w') as f:
f.write(app.RepoType + ' ' + app.Repo)
metadatapath = os.path.join('metadata', package + '.yml')
metadatapath = os.path.join('metadata', appid + '.yml')
metadata.write_metadata(metadatapath, app)
logging.info("Wrote " + metadatapath)

View file

@ -45,6 +45,7 @@ BINARY_TRANSPARENCY_DIR = 'binary_transparency'
AUTO_S3CFG = '.fdroid-server-update-s3cfg'
USER_S3CFG = 's3cfg'
REMOTE_HOSTNAME_REGEX = re.compile(r'\W*\w+\W+(\w+).*')
def update_awsbucket(repo_section):
@ -384,15 +385,17 @@ def update_servergitmirrors(servergitmirrors, repo_section):
repo = git.Repo.init(git_mirror_path)
enabled_remotes = []
for remote_url in servergitmirrors:
hostname = re.sub(r'\W*\w+\W+(\w+).*', r'\1', remote_url)
r = git.remote.Remote(repo, hostname)
name = REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url)
enabled_remotes.append(name)
r = git.remote.Remote(repo, name)
if r in repo.remotes:
r = repo.remote(hostname)
r = repo.remote(name)
if 'set_url' in dir(r): # force remote URL if using GitPython 2.x
r.set_url(remote_url)
else:
repo.create_remote(hostname, remote_url)
repo.create_remote(name, remote_url)
logging.info('Mirroring to: ' + remote_url)
# sadly index.add don't allow the --all parameter
@ -414,6 +417,9 @@ def update_servergitmirrors(servergitmirrors, repo_section):
# push for every remote. This will overwrite the git history
for remote in repo.remotes:
if remote.name not in enabled_remotes:
repo.delete_remote(remote)
continue
if remote.name == 'gitlab':
logging.debug('Writing .gitlab-ci.yml to deploy to GitLab Pages')
with open(os.path.join(git_mirror_path, ".gitlab-ci.yml"), "wt") as out_file:

View file

@ -167,10 +167,10 @@ v_all=${plugin_v[@]}
for f in {.,..}/gradle/wrapper/gradle-wrapper.properties; do
[[ -f $f ]] || continue
while IFS='' read -r line || [ -n "$line" ]; do
line=$(printf $line | tr -d '\r') # strip Windows linefeeds
if [[ $line == 'distributionUrl='* ]]; then
wrapper_ver=${line#*/gradle-}
wrapper_ver=${wrapper_ver%-*.zip}
wrapper_ver=$(printf $wrapper_ver | tr -d '\r') # strip Windows linefeeds
break 2
fi
done < $f
@ -186,14 +186,13 @@ fi
for f in {.,..}/build.gradle{,.kts}; do
[[ -f $f ]] || continue
while IFS='' read -r line || [ -n "$line" ]; do
line=$(printf $line | tr -d '\r') # strip Windows linefeeds
if [[ -z "$plugin_pver" && $line == *'com.android.tools.build:gradle:'* ]]; then
plugin_pver=${line#*[\'\"]com.android.tools.build:gradle:}
plugin_pver=${plugin_pver%[\'\"]*}
plugin_pver=$(printf $plugin_pver | tr -d '\r') # strip Windows linefeeds
elif [[ -z "$wrapper_ver" && $line == *'gradleVersion = '* ]]; then
wrapper_ver=${line#*gradleVersion*=*[\'\"]}
wrapper_ver=${wrapper_ver%[\'\"]*}
wrapper_ver=$(printf $wrapper_ver | tr -d '\r') # strip Windows linefeeds
fi
done < $f
done

View file

@ -148,6 +148,19 @@ class ServerTest(unittest.TestCase):
virustotal_apikey = os.getenv('VIRUSTOTAL_API_KEY')
fdroidserver.server.upload_to_virustotal('repo', virustotal_apikey)
def test_remote_hostname_regex(self):
for remote_url, name in (
('git@github.com:guardianproject/fdroid-repo', 'github'),
('git@gitlab.com:guardianproject/fdroid-repo', 'gitlab'),
('https://github.com:guardianproject/fdroid-repo', 'github'),
('https://gitlab.com/guardianproject/fdroid-repo', 'gitlab'),
('https://salsa.debian.org/foo/repo', 'salsa'),
):
self.assertEqual(
name,
fdroidserver.server.REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url)
)
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))