import app into fdroid directly from git clone

This adds a new method for `fdroid import` that will generate the fdroidserver
metadata based on a local git repo.  This new mode generates the metadata in
the new .fdroid.yaml format in the git repo itself.  It is intended as a quick
way to get starting building apps using the fdroidserver tools.
This commit is contained in:
Hans-Christoph Steiner 2016-03-21 21:00:12 +01:00
parent 994488ad47
commit 19189b9b04
3 changed files with 65 additions and 22 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 binascii
import sys
import os
import shutil
@ -180,12 +181,38 @@ def main():
root_dir = None
build_dir = None
if options.url:
root_dir, build_dir = get_metadata_from_url(app, options.url)
elif os.path.isdir('.git'):
if options.url:
app.WebSite = options.url
local_metadata_files = common.get_local_metadata_files()
if local_metadata_files != []:
logging.error("This repo already has local metadata: %s" % local_metadata_files[0])
sys.exit(1)
if options.url is None and os.path.isdir('.git'):
app.AutoName = os.path.basename(os.getcwd())
app.RepoType = 'git'
build = {}
root_dir = get_subdir(os.getcwd())
if os.path.exists('build.gradle'):
build.gradle = ['yes']
import git
repo = git.repo.Repo(root_dir) # git repo
for remote in git.Remote.iter_items(repo):
if remote.name == 'origin':
url = repo.remotes.origin.url
if url.startswith('https://git'): # github, gitlab
app.SourceCode = url.rstrip('.git')
app.Repo = url
break
# repo.head.commit.binsha is a bytearray stored in a str
build.commit = binascii.hexlify(bytearray(repo.head.commit.binsha))
write_local_file = True
elif options.url:
root_dir, build_dir = get_metadata_from_url(app, options.url)
build = metadata.Build()
build.commit = '?'
build.disable = 'Generated by import.py - check/set version fields and commit id'
write_local_file = False
else:
logging.error("Specify project url.")
sys.exit(1)
@ -222,29 +249,31 @@ def main():
sys.exit(1)
# Create a build line...
build = metadata.Build()
build.version = version or '?'
build.vercode = vercode or '?'
build.commit = '?'
build.disable = 'Generated by import.py - check/set version fields and commit id'
if options.subdir:
build.subdir = options.subdir
if os.path.exists(os.path.join(root_dir, 'jni')):
build.buildjni = ['yes']
metadata.post_metadata_parse(app)
app.builds.append(build)
# Keep the repo directory to save bandwidth...
if not os.path.exists('build'):
os.mkdir('build')
if build_dir is not None:
shutil.move(build_dir, os.path.join('build', package))
with open('build/.fdroidvcs-' + package, 'w') as f:
f.write(app.RepoType + ' ' + app.Repo)
if write_local_file:
metadata.write_metadata('.fdroid.yaml', app)
else:
# Keep the repo directory to save bandwidth...
if not os.path.exists('build'):
os.mkdir('build')
if build_dir is not None:
shutil.move(build_dir, os.path.join('build', package))
with open('build/.fdroidvcs-' + package, 'w') as f:
f.write(app.RepoType + ' ' + app.Repo)
metadatapath = os.path.join('metadata', package + '.txt')
metadata.write_metadata(metadatapath, app)
logging.info("Wrote " + metadatapath)
metadatapath = os.path.join('metadata', package + '.txt')
metadata.write_metadata(metadatapath, app)
logging.info("Wrote " + metadatapath)
if __name__ == "__main__":