diff options
Diffstat (limited to 'lib/portage/sync/modules/mercurial')
-rw-r--r-- | lib/portage/sync/modules/mercurial/mercurial.py | 55 | ||||
-rw-r--r-- | lib/portage/sync/modules/mercurial/meson.build | 8 |
2 files changed, 36 insertions, 27 deletions
diff --git a/lib/portage/sync/modules/mercurial/mercurial.py b/lib/portage/sync/modules/mercurial/mercurial.py index 486b4fdd6..aad8ff94a 100644 --- a/lib/portage/sync/modules/mercurial/mercurial.py +++ b/lib/portage/sync/modules/mercurial/mercurial.py @@ -2,11 +2,12 @@ # Distributed under the terms of the GNU General Public License v2 import logging +import shlex import subprocess import portage from portage import os -from portage.util import writemsg_level, shlex_split +from portage.util import writemsg_level from portage.sync.syncbase import NewBase @@ -35,9 +36,9 @@ class MercurialSync(NewBase): if not os.path.exists(self.repo.location): os.makedirs(self.repo.location) self.logger( - self.xterm_titles, "Created new directory %s" % self.repo.location + self.xterm_titles, f"Created new directory {self.repo.location}" ) - except IOError: + except OSError: return (1, False) sync_uri = self.repo.sync_uri @@ -46,25 +47,25 @@ class MercurialSync(NewBase): hg_cmd_opts = "" if self.repo.module_specific_options.get("sync-mercurial-env"): - shlexed_env = shlex_split( + shlexed_env = shlex.split( self.repo.module_specific_options["sync-mercurial-env"] ) - env = dict( - (k, v) + env = { + k: v for k, _, v in (assignment.partition("=") for assignment in shlexed_env) if k - ) + } self.spawn_kwargs["env"].update(env) if self.repo.module_specific_options.get("sync-mercurial-clone-env"): - shlexed_env = shlex_split( + shlexed_env = shlex.split( self.repo.module_specific_options["sync-mercurial-clone-env"] ) - clone_env = dict( - (k, v) + clone_env = { + k: v for k, _, v in (assignment.partition("=") for assignment in shlexed_env) if k - ) + } self.spawn_kwargs["env"].update(clone_env) if self.settings.get("PORTAGE_QUIET") == "1": @@ -74,7 +75,7 @@ class MercurialSync(NewBase): " %s" % self.repo.module_specific_options["sync-mercurial-clone-extra-opts"] ) - hg_cmd = "%s clone%s %s ." % ( + hg_cmd = "{} clone{} {} .".format( self.bin_command, hg_cmd_opts, portage._shell_quote(sync_uri), @@ -82,12 +83,12 @@ class MercurialSync(NewBase): writemsg_level(hg_cmd + "\n") exitcode = portage.process.spawn( - shlex_split(hg_cmd), + shlex.split(hg_cmd), cwd=portage._unicode_encode(self.repo.location), - **self.spawn_kwargs + **self.spawn_kwargs, ) if exitcode != os.EX_OK: - msg = "!!! hg clone error in %s" % self.repo.location + msg = f"!!! hg clone error in {self.repo.location}" self.logger(self.xterm_titles, msg) writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) return (exitcode, False) @@ -102,25 +103,25 @@ class MercurialSync(NewBase): hg_cmd_opts = "" if self.repo.module_specific_options.get("sync-mercurial-env"): - shlexed_env = shlex_split( + shlexed_env = shlex.split( self.repo.module_specific_options["sync-mercurial-env"] ) - env = dict( - (k, v) + env = { + k: v for k, _, v in (assignment.partition("=") for assignment in shlexed_env) if k - ) + } self.spawn_kwargs["env"].update(env) if self.repo.module_specific_options.get("sync-mercurial-pull-env"): - shlexed_env = shlex_split( + shlexed_env = shlex.split( self.repo.module_specific_options["sync-mercurial-pull-env"] ) - pull_env = dict( - (k, v) + pull_env = { + k: v for k, _, v in (assignment.partition("=") for assignment in shlexed_env) if k - ) + } self.spawn_kwargs["env"].update(pull_env) if self.settings.get("PORTAGE_QUIET") == "1": @@ -130,7 +131,7 @@ class MercurialSync(NewBase): " %s" % self.repo.module_specific_options["sync-mercurial-pull-extra-opts"] ) - hg_cmd = "%s pull -u%s" % (self.bin_command, hg_cmd_opts) + hg_cmd = f"{self.bin_command} pull -u{hg_cmd_opts}" writemsg_level(hg_cmd + "\n") rev_cmd = [self.bin_command, "id", "--id", "--rev", "tip"] @@ -139,12 +140,12 @@ class MercurialSync(NewBase): ) exitcode = portage.process.spawn( - shlex_split(hg_cmd), + shlex.split(hg_cmd), cwd=portage._unicode_encode(self.repo.location), - **self.spawn_kwargs + **self.spawn_kwargs, ) if exitcode != os.EX_OK: - msg = "!!! hg pull error in %s" % self.repo.location + msg = f"!!! hg pull error in {self.repo.location}" self.logger(self.xterm_titles, msg) writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1) return (exitcode, False) diff --git a/lib/portage/sync/modules/mercurial/meson.build b/lib/portage/sync/modules/mercurial/meson.build new file mode 100644 index 000000000..4e4897ed3 --- /dev/null +++ b/lib/portage/sync/modules/mercurial/meson.build @@ -0,0 +1,8 @@ +py.install_sources( + [ + 'mercurial.py', + '__init__.py', + ], + subdir : 'portage/sync/modules/mercurial', + pure : not native_extensions +) |