chiark / gitweb /
import app into fdroid directly from git clone
authorHans-Christoph Steiner <hans@eds.org>
Mon, 21 Mar 2016 20:00:12 +0000 (21:00 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 23 Mar 2016 16:16:28 +0000 (17:16 +0100)
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.

docs/fdroid.texi
fdroidserver/import.py
setup.py

index f158147c6a3fc06096023f28cc6e808e9ca9c507..1cc011d68ae7a46285b3d1054f1a10afcb496496 100644 (file)
@@ -401,19 +401,32 @@ the signed output directory were modified, you won't be notified.
 @node Importing Applications
 @chapter Importing Applications
 
-To help with starting work on including a new application, @code{fdroid import}
-will take a URL and optionally some other parameters, and attempt to construct
-as much information as possible by analysing the source code. Basic usage is:
+To help with starting work on including a new application, use
+@code{fdroid import} to set up a new template project.  It has two
+modes of operation, starting with a cloned git repo:
+
+@example
+git clone https://gitlab.com/fdroid/fdroidclient
+cd fdroidclient
+fdroid import
+@end example
+
+Or starting with a URL to a project page:
 
 @example
 fdroid import --url=http://address.of.project
 @end example
 
-For this to work, the URL must point to a project format that the script
+When a URL is specified using the @code{--url=} flag, @code{fdroid
+import} will use that URL to find out information about the project,
+and if it finds a git repo, it will also clone that.  For this to
+work, the URL must point to a project format that the script
 understands. Currently this is limited to one of the following:
 
 @enumerate
 @item
+GitLab - @code{https://gitlab.com/PROJECTNAME/REPONAME}
+@item
 Gitorious - @code{https://gitorious.org/PROJECTNAME/REPONAME}
 @item
 Github - @code{https://github.com/USER/PROJECT}
index 247a42c4a4b981ab6ecb9eda4b5933780a644bd2..4d342f044c2be815f2ccce115f3134f9d2758d64 100644 (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)
-
-    metadatapath = os.path.join('metadata', package + '.txt')
-    metadata.write_metadata(metadatapath, app)
-    logging.info("Wrote " + metadatapath)
+    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)
 
 
 if __name__ == "__main__":
index 017cccd9cdaebffa41f57634c1c1002bf2a6f6bd..9c068b86654f327295f436a3d78eb4ad5151f3fe 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -27,6 +27,7 @@ setup(name='fdroidserver',
                   'examples/fdroid-icon.png']),
       ],
       install_requires=[
+          'GitPython',
           'mwclient',
           'paramiko',
           'Pillow',