Bug 1365722 - Move application.ini processing out to a separate file; r?chmanchester draft
authorMike Shal <mshal@mozilla.com>
Thu, 04 May 2017 16:13:55 -0400
changeset 582486 add67ac2e2783d9320778742e041108a65e4a16a
parent 582485 32d2f071051dacd6e9500f02cf5328d6c488213e
child 629796 e005440d771325d6a8fe31e86da8a2b391eacbdc
push id60110
push userbmo:mshal@mozilla.com
push dateMon, 22 May 2017 18:29:32 +0000
reviewerschmanchester
bugs1365722
milestone55.0a1
Bug 1365722 - Move application.ini processing out to a separate file; r?chmanchester Windows repackaging for complete mar files will also need to pull a different value out of the application.ini file, so this code should be shareable. MozReview-Commit-ID: CzCoNRYcBPX
python/mozbuild/mozbuild/repackaging/application_ini.py
python/mozbuild/mozbuild/repackaging/dmg.py
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/repackaging/application_ini.py
@@ -0,0 +1,21 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import os
+import ConfigParser
+import mozpack.path as mozpath
+
+def get_application_ini_value(application_directory, section, value):
+    rc = None
+    for root, dirs, files in os.walk(application_directory):
+        if 'application.ini' in files:
+            parser = ConfigParser.ConfigParser()
+            parser.read(mozpath.join(root, 'application.ini'))
+            rc = parser.get(section, value)
+            break
+
+    if rc is None:
+        raise Exception("Input package does not contain an application.ini file")
+
+    return rc
--- a/python/mozbuild/mozbuild/repackaging/dmg.py
+++ b/python/mozbuild/mozbuild/repackaging/dmg.py
@@ -1,19 +1,19 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import os
 import tempfile
 import tarfile
 import shutil
-import ConfigParser
 import mozpack.path as mozpath
 from mozpack.dmg import create_dmg
+from application_ini import get_application_ini_value
 
 def repackage_dmg(infile, output):
 
     if not tarfile.is_tarfile(infile):
         raise Exception("Input file %s is not a valid tarfile." % infile)
 
     tmpdir = tempfile.mkdtemp()
     try:
@@ -23,27 +23,17 @@ def repackage_dmg(infile, output):
         # Remove the /Applications symlink. If we don't, an rsync command in
         # create_dmg() will break, and create_dmg() re-creates the symlink anyway.
         try:
             os.remove(mozpath.join(tmpdir, ' '))
         except OSError as e:
             if e.errno != errno.ENOENT:
                 raise
 
-        # Grab the volume name
-        volume_name = None
-        for root, dirs, files in os.walk(tmpdir):
-            if 'application.ini' in files:
-                parser = ConfigParser.ConfigParser()
-                parser.read(mozpath.join(root, 'application.ini'))
-                volume_name = parser.get('App', 'CodeName')
-                break
-
-        if volume_name is None:
-            raise Exception("Input package does not contain an application.ini file")
+        volume_name = get_application_ini_value(tmpdir, 'App', 'CodeName')
 
         # The extra_files argument is empty [] because they are already a part
         # of the original dmg produced by the build, and they remain in the
         # tarball generated by the signing task.
         create_dmg(tmpdir, output, volume_name, [])
 
     finally:
         shutil.rmtree(tmpdir)