[Python-modules-commits] [python-aptly] 01/03: Import python-aptly_0.9.1.orig.tar.gz

Filip Pytloun fpytloun-guest at moszumanska.debian.org
Sun Apr 23 09:42:41 UTC 2017


This is an automated email from the git hooks/post-receive script.

fpytloun-guest pushed a commit to branch master
in repository python-aptly.

commit f4fbc44d5966f9fe8dbc4dddc9b06ba7205184af
Author: Filip Pytloun <filip at pytloun.cz>
Date:   Fri Apr 21 17:58:08 2017 +0200

    Import python-aptly_0.9.1.orig.tar.gz
---
 .gitignore                  |  2 ++
 aptly/publisher/__init__.py | 39 +++++++++++++++++++--------------------
 aptly/publisher/__main__.py | 20 ++++++++++++--------
 setup.py                    |  2 +-
 4 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6cf9b64..95931dd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@
 *.pyc
 .DS_Store
 .ropeproject
+*.egg-info
+dist
diff --git a/aptly/publisher/__init__.py b/aptly/publisher/__init__.py
index 2140f43..582d0c6 100644
--- a/aptly/publisher/__init__.py
+++ b/aptly/publisher/__init__.py
@@ -369,26 +369,14 @@ class Publish(object):
             opts
         )
 
-    def get_publish(self):
-        """
-        Try to find our publish
-        """
-        publishes = self.client.do_get('/publish')
-        if not self.prefix:
-            prefix = '.'
-        else:
-            prefix = self.prefix
-
-        for publish in publishes:
-            if publish['Distribution'] == self.distribution \
-                    and publish['Prefix'] == prefix:
-                return publish
-        return False
-
-    def do_publish(self, recreate=False, force_overwrite=False,
-                   publish_contents=False, architectures=None):
+    def do_publish(self, recreate=False, no_recreate=False,
+                   force_overwrite=False, publish_contents=False,
+                   architectures=None):
         self.merge_snapshots()
-        publish = self.get_publish()
+        try:
+            publish = self._get_publish()
+        except NoSuchPublish:
+            publish = False
 
         if not publish:
             # New publish
@@ -408,4 +396,15 @@ class Publish(object):
             elif to_publish == published:
                 lg.info("Publish %s is up to date" % self.name)
             else:
-                self.update_publish(force_overwrite, publish_contents)
+                try:
+                    self.update_publish(force_overwrite, publish_contents)
+                except AptlyException as e:
+                    if e.res.status_code == 404:
+                        # Publish exists but we are going to add some new
+                        # components. Unfortunately only way is to recreate it
+                        if no_recreate:
+                            lg.error("Cannot update publish %s (adding new components?), falling back to recreating it is disabled so skipping.")
+                        else:
+                            lg.warning("Cannot update publish %s (adding new components?), falling back to recreating it" % self.name)
+                            self.drop_publish()
+                            self.create_publish(force_overwrite, publish_contents, architectures)
diff --git a/aptly/publisher/__main__.py b/aptly/publisher/__main__.py
index e889350..ce6bb36 100644
--- a/aptly/publisher/__main__.py
+++ b/aptly/publisher/__main__.py
@@ -40,6 +40,7 @@ def main():
     group_common.add_argument('--timeout', type=int, default=300, help="Aptly client timeout. Raise for larger publishes and slow server.")
     group_common.add_argument('--url', required=True, help="URL to Aptly API, eg. http://localhost:8080")
     group_common.add_argument('--recreate', action="store_true", help="Drop publish and create it again, only way to add new components")
+    group_common.add_argument('--no-recreate', action="store_true", help="Never recreate publish (even when we are adding new components where it's the only option)")
     group_common.add_argument('--force-overwrite', action="store_true", help="Overwrite files in pool/ directory without notice")
     group_common.add_argument('--publish-contents', action="store_true", default=False, help="Publish contents. It's slow so disabled by default to support large repositories.")
 
@@ -69,6 +70,7 @@ def main():
     if args.action == 'publish':
         action_publish(client, publishmgr, config_file=args.config,
                        recreate=args.recreate,
+                       no_recreate=args.no_recreate,
                        force_overwrite=args.force_overwrite,
                        publish_contents=args.publish_contents,
                        publish_names=args.dists,
@@ -78,8 +80,8 @@ def main():
             parser.error("Action 'promote' requires both --source and --target arguments")
         action_promote(client, source=args.source, target=args.target,
                        components=args.components, recreate=args.recreate,
-                       packages=args.packages, diff=args.diff,
-                       force_overwrite=args.force_overwrite,
+                       no_recreate=args.no_recreate, packages=args.packages,
+                       diff=args.diff, force_overwrite=args.force_overwrite,
                        publish_contents=args.publish_contents)
     elif args.action == 'cleanup':
         publishmgr.cleanup_snapshots()
@@ -87,8 +89,8 @@ def main():
 
 
 def action_promote(client, source, target, components=None, recreate=False,
-                   packages=None, diff=False, force_overwrite=False,
-                   publish_contents=False):
+                   no_recreate=False, packages=None, diff=False,
+                   force_overwrite=False, publish_contents=False):
     try:
         publish_source = Publish(client, source, load=True)
     except NoSuchPublish as e:
@@ -156,7 +158,7 @@ def action_promote(client, source, target, components=None, recreate=False,
                     lg.error("Component %s does not exist")
                     sys.exit(1)
 
-    publish_target.do_publish(recreate=recreate,
+    publish_target.do_publish(recreate=recreate, no_recreate=no_recreate,
                               force_overwrite=force_overwrite,
                               publish_contents=publish_contents)
 
@@ -214,8 +216,9 @@ def action_diff(source, target, components=[], packages=True):
 
 
 def action_publish(client, publishmgr, config_file, recreate=False,
-                   force_overwrite=False, publish_contents=False,
-                   publish_names=None, architectures=None):
+                   no_recreate=False, force_overwrite=False,
+                   publish_contents=False, publish_names=None,
+                   architectures=None):
     if not architectures:
         architectures = []
     snapshots = client.do_get('/snapshots', {'sort': 'time'})
@@ -247,7 +250,8 @@ def action_publish(client, publishmgr, config_file, recreate=False,
             if arch not in architectures:
                 architectures.append(arch)
 
-    publishmgr.do_publish(recreate=recreate, force_overwrite=force_overwrite,
+    publishmgr.do_publish(recreate=recreate, no_recreate=no_recreate,
+                          force_overwrite=force_overwrite,
                           publish_contents=publish_contents,
                           names=publish_names, architectures=architectures)
 
diff --git a/setup.py b/setup.py
index 9a1be58..a32f654 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ long_desc = open('README.rst').read()
 
 setup(
     name="python-aptly",
-    version="0.8.1",
+    version="0.9.1",
     description="Aptly REST API client and tooling",
     long_description=long_desc,
     author="Filip Pytloun",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-aptly.git



More information about the Python-modules-commits mailing list