Commits

Jan Borsodi committed 0212061

command.release: The latest version of a service is now updated in target.current section.

  • Participants
  • Parent commits 963dc7d
  • Branches repo-manager

Comments (0)

Files changed (1)

File hob/script.py

             shutil.copyfile(src, dest_path)
 
     # Update hob.conf with new entries
-    if new_config_entries:
-        target_section = "target.all"
-        from ConfigParser import RawConfigParser
-        raw_config = RawConfigParser()
-        raw_config.read([conf_path])
-        if raw_config.has_section(target_section):
-            for service, path, base, version in new_config_entries:
-                # config file must only use forward slash for path
-                path = path.replace("\\", "/")
-                raw_config.set(target_section, "%s-%s" % (service.name, version), path)
+    target_section = "target.all"
+    from ConfigParser import RawConfigParser
+    raw_config = RawConfigParser()
+    raw_config.read([conf_path])
+    if raw_config.has_section(target_section):
+        modified = False
+        for service, path, base, version in new_config_entries:
+            # config file must only use forward slash for path
+            path = path.replace("\\", "/")
+            raw_config.set(target_section, "%s-%s" % (service.name, version), path)
+            modified = True
+
+        # Update list of services to contain latest versions
+        from collections import defaultdict
+        latest_services = {}
+        for service_name, version_map in local.services().iteritems():
+            for major in version_map:
+                for minor in version_map[major]:
+                    service = version_map[major][minor]
+                    cur_service = latest_services.get(service.name, None)
+                    if cur_service:
+                        version = cur_service.getVersionNumber()
+                        if major > version[0] or (major == version[0] and minor > version[1]):
+                            latest_services[service.name] = service
+                            modified = True
+                    else:
+                        latest_services[service.name] = service
+                        modified = True
+        if modified:
+            cur_target = "target.current"
+            if raw_config.has_option("hob", "target"):
+                cur_target = "target." + raw_config.get("hob", "target")
+            for service in latest_services.itervalues():
+                basename = join_underscore(split_camelcase(service.name))
+                dest = os.path.normpath("%(name)s/%(name)s-%(version)s.proto" % dict(name=basename, version=service.getVersion()))
+                raw_config.set(cur_target, service.name, dest.replace("\\", "/"))
+        
+        if modified:
             raw_config.write(open(conf_path, "wb"))
         else:
             print "Could not find config section '%s', cannot update hob.conf with new service entries" % target_section