#5 Rewrite commands 'list', 'info', 'enable', 'disable' to work with new modulemd format
Opened 2 years ago by frostyx. Modified 2 years ago
frostyx/fm-dnf-plugin master  into  master

file modified
+4 -1

@@ -199,12 +199,15 @@ 

              else:

                  mmd.name = mod["name"]

                  mmd.summary = mod["summary"]

+                 mmd.stream = mod["stream"]

                  mmd.version = mod["version"]

-                 mmd.release = mod["release"]

  

                  for req_name, req_ver in mod["requires"].items():

                      mmd.update_requires(req_name, req_ver)

  

+                 if not mmd.xmd:

+                     mmd.xmd = {} # otherwise mmd.xmd == None in 1.0.2

+ 

                  mmd.xmd["_fm_need_refetch"] = True

  

              if "url" in mod:

file modified
+4 -4

@@ -90,7 +90,7 @@ 

                  raise fm.exceptions.DependencyError("Dependency on module {} is not satisfied.".format(name))

  

              # Get the Module instance for this ModuleMetadata object.

-             mods = self.mods.get_modules(mmd.name, mmd.version, mmd.release)

+             mods = self.mods.get_modules(mmd.name, mmd.stream, mmd.version)

              if not mods:

                  raise fm.exceptions.DependencyError("There is no module named {}".format(name))

  

@@ -98,7 +98,7 @@ 

              if not mod.mmd:

                  raise fm.exceptions.DependencyError("There is no metadata associated with module {}".format(name))

  

-             print("Enabling module", name + "-" + mod.mmd.version + "-" + mod.mmd.release)

+             print("Enabling module", name + "-" + mod.mmd.stream + "-" + str(mod.mmd.version))

  

              # Enable current module.

              if no_dnf == None:

@@ -123,7 +123,7 @@ 

          for mmd in modules:

              name = mmd.name

              # Get the Module instance for this ModuleMetadata object.

-             mods = self.mods.get_modules(mmd.name, mmd.version, mmd.release)

+             mods = self.mods.get_modules(mmd.name, mmd.stream, mmd.version)

              if not mods:

                  raise fm.exceptions.DependencyError("There is no module named {}".format(name))

  

@@ -134,7 +134,7 @@ 

              if not mod.is_enabled():

                  continue

  

-             print("Disabling module", name + "-" + mod.mmd.version + "-" + mod.mmd.release)

+             print("Disabling module", name + "-" + mod.mmd.stream + "-" + str(mod.mmd.version))

  

              # Now when all the depending modules are disabled, disable also

              # the original module.

file modified
+2 -2

@@ -139,8 +139,8 @@ 

          Returns full path to cached mmd file for this module.

          """

  

-         mmd_file = os.path.join(self.cache_dir, mod.name + "-" + mod.mmd.version

-                                 + "-" + mod.mmd.release + ".yaml")

+         mmd_file = os.path.join(self.cache_dir, mod.name + "-" + mod.mmd.stream

+                                 + "-" + str(mod.mmd.version) + ".yaml")

          return mmd_file

  

      def store(self, mod, enabled_by_user = False):

file modified
+6 -6

@@ -57,9 +57,9 @@ 

  

      def get_nvr(self):

          """

-         Returns NVR ("$name-$version-$release) of this module.

+         Returns NVR ("$name-$stream-$version) of this module.

          """

-         return self.name + "-" + self.mmd.version + "-" + self.mmd.release

+         return self.name + "-" + self.mmd.stream + "-" + self.mmd.version

  

      def get_metadata_expire(self):

          """

@@ -180,8 +180,8 @@ 

          ret = "Name: " + self.name + "\n"

          if self.mmd:

              ret += "  Summary: " + self.mmd.summary + "\n"

-             ret += "  Version: " + self.mmd.version + "\n"

-             ret += "  Release: " + self.mmd.release + "\n"

+             ret += "  Stream: " + self.mmd.stream + "\n"

+             ret += "  Release: " + str(self.mmd.version) + "\n"

              ret += "  Description: " + self.mmd.description + "\n"

  

              if self.mmd.profiles and len(self.mmd.profiles) != 0:

@@ -211,8 +211,8 @@ 

          if self.url != other.url:

              return False

          if self.mmd and other.mmd:

-             if self.mmd.version != other.mmd.version:

+             if self.mmd.stream != other.mmd.stream:

                  return False

-             if self.mmd.release != other.mmd.release:

+             if self.mmd.version != other.mmd.version:

                  return False

          return True

file modified
+25 -25

@@ -107,9 +107,9 @@ 

                  del self[key]

                  self[key] = m

                  if key in mods:

-                     self[key] += sorted(mods[key], key = lambda mod: (mod.mmd.version, int(mod.mmd.release)))

+                     self[key] += sorted(mods[key], key = lambda mod: (mod.mmd.stream, int(mod.mmd.version)))

              else:

-                 self[key] = sorted(mods[key], key = lambda mod: (mod.mmd.version, int(mod.mmd.release)))

+                 self[key] = sorted(mods[key], key = lambda mod: (mod.mmd.stream, int(mod.mmd.version)))

  

      def enable(self, name, profiles):

          """

@@ -159,8 +159,8 @@ 

              if not enabled_mod:

                  continue

  

-             available_mods = self.get_modules(name, enabled_mod.mmd.version)

-             available_mods = sorted(available_mods, key = lambda mod: int(mod.mmd.release))

+             available_mods = self.get_modules(name, enabled_mod.mmd.stream)

+             available_mods = sorted(available_mods, key = lambda mod: int(mod.mmd.version))

              latest_mod = available_mods[-1]

              if latest_mod != enabled_mod:

                  to_upgrade.add_module(latest_mod, False)

@@ -179,7 +179,7 @@ 

              if not enabled_mod:

                  continue

              available_mods = self.get_modules(name)

-             available_mods = sorted(available_mods, key = lambda mod: (mod.mmd.version, int(mod.mmd.release)))

+             available_mods = sorted(available_mods, key = lambda mod: (mod.mmd.stream, int(mod.mmd.version)))

              latest_mod = available_mods[-1]

              if latest_mod != enabled_mod:

                  to_upgrade.add_module(latest_mod, False)

@@ -195,8 +195,8 @@ 

              if not enabled_mod:

                  raise fm.exceptions.DependencyError("Module {} is not enabled".format(name))

  

-             available_mods = self.get_modules(name, enabled_mod.mmd.version)

-             available_mods = sorted(available_mods, key = lambda mod: int(mod.mmd.release))

+             available_mods = self.get_modules(name, enabled_mod.mmd.stream)

+             available_mods = sorted(available_mods, key = lambda mod: int(mod.mmd.version))

              latest_mod = available_mods[-1]

  

              resolver = FmModulesResolver(self)

@@ -210,9 +210,9 @@ 

          if len(lst) > 2:

              try:

                  int(lst[-2][0])

-                 release = str(int(lst[-1]))

-                 version = lst[-2]

-                 return '-'.join(lst[:-2]), version, release

+                 version = str(int(lst[-1]))

+                 stream = lst[-2]

+                 return '-'.join(lst[:-2]), stream, version

              except:

                  pass

  

@@ -231,13 +231,13 @@ 

          Rebases the module named `name` to version defined by `nvr.

          """

  

-         name, version, release = self._name_to_nvr(nvr)

+         name, stream, version = self._name_to_nvr(nvr)

          enabled_mod = self.get_enabled_module(name)

          if not enabled_mod:

              raise fm.exceptions.DependencyError("Module {} is not enabled".format(name))

  

-         available_mods = self.get_modules(name, version, release)

-         available_mods = sorted(available_mods, key = lambda mod: (mod.mmd.version, int(mod.mmd.release)))

+         available_mods = self.get_modules(name, stream, version)

+         available_mods = sorted(available_mods, key = lambda mod: (mod.mmd.stream, int(mod.mmd.version)))

          latest_mod = available_mods[-1]

  

          resolver = FmModulesResolver(self)

@@ -290,8 +290,8 @@ 

          # Modules instance and remove them from cache.

          for mods in cached_mods.values():

              for mod in mods:

-                 our_modules = self.get_modules(mod.name, mod.mmd.version,

-                                                mod.mmd.release)

+                 our_modules = self.get_modules(mod.name, mod.mmd.stream,

+                                                mod.mmd.version)

                  if not our_modules or len(our_modules) == 0:

                      self.available_cache.remove(mod)

  

@@ -309,9 +309,9 @@ 

          if cache and mod.mmd and not self.available_cache.is_valid(mod) and not self.disable_cache:

              self.available_cache.store(mod)

  

-     def get_modules(self, name, version = None, release = None):

+     def get_modules(self, name, stream = None, version = None):

          """

-         Returns all modules matching the `name` and `version` or `release`

+         Returns all modules matching the `name` and `stream` or `version`

          when defined.

          """

  

@@ -320,9 +320,9 @@ 

  

          mods = []

          for mod in self[name]:

-             if version and mod.mmd.version != version:

+             if stream and mod.mmd.stream != stream:

                  continue

-             if release and mod.mmd.release != release:

+             if version and mod.mmd.version != version:

                  continue

              mods.append(mod)

  

@@ -350,12 +350,12 @@ 

          """

          Returns full description of all modules matching the specified `nvr`.

          """

-         name, version, release = self._name_to_nvr(nvr)

-         mods = self.get_modules(name, version, release)

+         name, stream, version = self._name_to_nvr(nvr)

+         mods = self.get_modules(name, stream, version)

          if not mods or len(mods) == 0:

              raise fm.exceptions.DependencyError("Unknown module {}".format(nvr))

  

-         mods = sorted(mods, key = lambda mod: (mod.mmd.version, int(mod.mmd.release)))

+         mods = sorted(mods, key = lambda mod: (mod.mmd.stream, int(mod.mmd.version)))

  

          ret = ""

          did_fetch = False

@@ -378,14 +378,14 @@ 

          # Get the maximum width of the text we will show in each column

          # of output.

          max_name_width = max(len(word) for word in self.keys()) + 4  # padding

-         max_vr_width = (max(len(mod.mmd.version) + 1 + 

-                             len(mod.mmd.release) for mods in self.values()

+         max_vr_width = (max(len(mod.mmd.stream) + 1 +

+                             len(str(mod.mmd.version)) for mods in self.values()

                              for mod in mods) + 4)  # padding

  

          ret = ""

          for mods in self.values():

              for mod in mods:

-                 vr = mod.mmd.version + "-" + mod.mmd.release

+                 vr = mod.mmd.stream + "-" + str(mod.mmd.version)

  

                  # Show output in 3 columns...

                  ret += mod.name.ljust(max_name_width)

This repo still assumes old version of python-modulemd with name-version-release. I wanted to use

dnf module list
dnf module info <name>

commands with python3-modulemd-1.0.2 so I modified the code a bit. I think that it is a good idea to share it with you, even though it is not complete support for all commands. Maybe someone (maybe even myself) can continue on it. Or we can throw it off.

1 new commit added

  • Rewrite 'enable' and 'disable' commands to work with new modulemd format
2 years ago

1 new commit added

  • mmd.xmd inited to {}
2 years ago