Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-release-src > by-pkgid > b2335a99382b50dec4f8fda309845958 > files > 3

compute-image-packages-1.1.6-5.mga6.src.rpm

From 4a9349ce6a05418a184518cd6e50b59a4de5a88f Mon Sep 17 00:00:00 2001
From: Pascal Terjan <pterjan@gmail.com>
Date: Tue, 22 Apr 2014 21:54:57 +0000
Subject: [PATCH] Add Mageia support

---
 gcimagebundle/gcimagebundlelib/mageia.py           | 54 ++++++++++++++++++++++++++++++++++++
 gcimagebundle/gcimagebundlelib/platform_factory.py |  2 ++
 gcimagebundle/gcimagebundlelib/utils.py            |  1 +
 3 files changed, 57 insertions(+)
 create mode 100644 gcimagebundle/gcimagebundlelib/mageia.py

diff --git a/gcimagebundle/gcimagebundlelib/mageia.py b/gcimagebundle/gcimagebundlelib/mageia.py
new file mode 100644
index 0000000..c005bda
--- /dev/null
+++ b/gcimagebundle/gcimagebundlelib/mageia.py
@@ -0,0 +1,54 @@
+# Copyright 2014 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+"""Mageia specific platform info."""
+
+import os
+import re
+
+from gcimagebundlelib import linux
+
+
+class Mageia(linux.LinuxPlatform):
+  """Mageia specific information."""
+
+  @staticmethod
+  def IsThisPlatform(root='/'):
+    release_file = root + '/etc/mageia-release'
+    if os.path.exists(release_file):
+      (_, _, flavor, _) = Mageia.ParseMageiaRelease(release_file)
+      if flavor and flavor.lower() == 'mageia':
+        return True
+    return False
+
+  @staticmethod
+  def ParseMageiaRelease(release_file='/etc/mageia-release'):
+    """Parses the /etc/mageia-release file."""
+    f = open(release_file)
+    lines = f.readlines()
+    f.close()
+    if not lines:
+      return (None, None, None, None)
+    line0 = lines[0]
+    g = re.match(r'(\S+) release ([\d.]+) \(([^)]*)\)', line0)
+    if not g:
+      return (None, None, None, None)
+    (osname, version, label) = (g.group(1), g.group(2), g.group(3))
+    return (osname, label, osname, version)
+
+  def __init__(self):
+    super(Mageia, self).__init__()
+    (self.distribution_codename, _, self.distribution,
+     self.distribution_version) = Mageia.ParseMageiaRelease()
diff --git a/gcimagebundle/gcimagebundlelib/platform_factory.py b/gcimagebundle/gcimagebundlelib/platform_factory.py
index 235705e..3ac7a27 100644
--- a/gcimagebundle/gcimagebundlelib/platform_factory.py
+++ b/gcimagebundle/gcimagebundlelib/platform_factory.py
@@ -21,6 +21,7 @@ from gcimagebundlelib import centos
 from gcimagebundlelib import fedora
 from gcimagebundlelib import debian
 from gcimagebundlelib import gcel
+from gcimagebundlelib import mageia
 from gcimagebundlelib import opensuse
 from gcimagebundlelib import rhel
 from gcimagebundlelib import sle
@@ -42,6 +43,7 @@ class PlatformFactory(object):
     self.Register('Fedora', fedora.Fedora)
     self.Register('Debian', debian.Debian)
     self.Register('GCEL', gcel.Gcel)
+    self.Register('Mageia', mageia.Mageia)
     self.Register('openSUSE', opensuse.OpenSUSE)
     self.Register('Red Hat Enterprise Linux', rhel.RHEL)
     self.Register('SUSE Linux Enterprise', sle.SLE)
diff --git a/gcimagebundle/gcimagebundlelib/utils.py b/gcimagebundle/gcimagebundlelib/utils.py
index 5c87728..2427504 100644
--- a/gcimagebundle/gcimagebundlelib/utils.py
+++ b/gcimagebundle/gcimagebundlelib/utils.py
@@ -50,6 +50,7 @@ class LoadDiskImage(object):
   def __enter__(self):
     """Map disk image as a device."""
     SyncFileSystem()
+    RunCommand(['modprobe', 'loop'])
     kpartx_cmd = ['kpartx', '-a', '-v', '-s', self._file_path]
     output = RunCommand(kpartx_cmd)
     devs = []
-- 
1.8.5.4