From ae9543048271e8582ce6df98fc7ed2568e04f292 Mon Sep 17 00:00:00 2001 From: idziubenko Date: Thu, 15 Jul 2021 13:56:05 +0300 Subject: [PATCH] py3 changes --- .gitignore | 6 ++++++ pym/builder/builder.py | 21 +++++++++++---------- pym/builder/emerge_fetch.py | 10 +++++----- pym/builder/variables/__init__.py | 11 ++++++----- pym/builder/variables/builder.py | 26 +++++++++++++------------- pym/builder/variables/images.py | 10 +++++----- pym/builder/variables/linux.py | 6 +++--- pym/builder/wsdl_builder.py | 14 +++++++------- setup.py | 2 +- 9 files changed, 57 insertions(+), 49 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35ea017 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +revert_changes_to_vmachine +push_to_vmachine* +.vscode +*.pyc +*.pyo +*.bak \ No newline at end of file diff --git a/pym/builder/builder.py b/pym/builder/builder.py index a32f800..3a79911 100644 --- a/pym/builder/builder.py +++ b/pym/builder/builder.py @@ -73,6 +73,7 @@ from os import path from .datavars import BuilderError from .emerge_fetch import EmergeFetcher, EmergeFetcherError from calculate.lib.utils.grub import GrubCommand +from functools import reduce _ = lambda x: x from calculate.lib.cl_lang import (setLocalTranslate, getLazyLocalTranslate) @@ -231,7 +232,7 @@ class Builder(Update): :return: """ data = [] - re_subbuild = re.compile("\/[^-]+-[^-]+-(\d+)-[^-]+$", re.I) + re_subbuild = re.compile(r"\/[^-]+-[^-]+-(\d+)-[^-]+$", re.I) for container_dn in listDirectory(dn, fullPath=True): with ContainerDistributive(container_dn) as distro: info = distro.get_information() @@ -269,7 +270,7 @@ class Builder(Update): x['release'], x['arch'], x['variant'])): - info = grps.next() + info = next(grps) dist_key = "{dist}:{release}:{arch}:{variant}".format(**info) try: indexsystem.write("{dist};{release};{arch};" @@ -856,7 +857,7 @@ class Builder(Update): eclassdata = readFile(nvidia_eclass) reBlock = re.compile( r"if has \$\{nvidia_gpu\}\s+\\([^;]+);\s*then(.*?)fi", re.S) - reMask = re.compile('>=x11-drivers/nvidia-drivers[^"]+') + reMask = re.compile(r'>=x11-drivers/nvidia-drivers[^"]+') for block in reBlock.findall(eclassdata): nvidia_ids, mask_data = block m = reMask.search(mask_data) @@ -1289,7 +1290,7 @@ class Builder(Update): self._update_binhost_packages() if path.exists(pathPackages): re_keywords = re.compile( - '^(KEYWORDS|SYNC):.*$\n', re.M) + r'^(KEYWORDS|SYNC):.*$\n', re.M) data = readFile(pathPackages) data_blocks = data.split('\n\n') modified_blocks = [ @@ -1563,10 +1564,10 @@ class Builder(Update): map(lambda x: os.unlink(x) if path.islink(x) else os.rmdir(x), map(lambda x: path.join(pathname, x), dirs)) for node, mode, dmode, major, minor in [ - ("console", 0600, stat.S_IFCHR, 5, 1), - ("tty1", 0600, stat.S_IFCHR, 4, 1), - ("null", 0666, stat.S_IFCHR, 1, 3), - ("zero", 0666, stat.S_IFCHR, 1, 5)]: + ("console", 0o600, stat.S_IFCHR, 5, 1), + ("tty1", 0o600, stat.S_IFCHR, 4, 1), + ("null", 0o666, stat.S_IFCHR, 1, 3), + ("zero", 0o666, stat.S_IFCHR, 1, 5)]: nodePath = path.join(devPath, node) os.mknod(nodePath, mode | dmode, os.makedev(major, minor)) os.chmod(nodePath, mode) @@ -1961,10 +1962,10 @@ class Builder(Update): if all(y not in pretend for y in x)] required_pkgs = list(set(chain(*required_pkgs))) - clear_req_pkgs = filter( + clear_req_pkgs = list(filter( None, [x.strip() for x in system_ini.getVar( "automagic-clear", - package["CATEGORY/PN"]).split(",")]) + package["CATEGORY/PN"]).split(",")])) waste_pkgs = [x for x in clear_req_pkgs if all(y["CATEGORY/PN"] != x for y in required_pkgs)] diff --git a/pym/builder/emerge_fetch.py b/pym/builder/emerge_fetch.py index e8740da..93b69b4 100644 --- a/pym/builder/emerge_fetch.py +++ b/pym/builder/emerge_fetch.py @@ -46,10 +46,10 @@ class EmergeFetcher(object): _color_block = EmergeInformationBlock._color_block _new_line = EmergeInformationBlock._new_line re_fetching = re.compile( - ">>> Fetching \({c}\d+{c} of {c}\d+{c}\) {c}(.*?){c}{nl}(.*?)" - "(?=>>> Fetching|$)".format(c=_color_block, nl=_new_line), re.S) + r">>> Fetching \({c}\d+{c} of {c}\d+{c}\) {c}(.*?){c}{nl}(.*?)" + r"(?=>>> Fetching|$)".format(c=_color_block, nl=_new_line), re.S) - re_filename = re.compile("^{c} [*] {c}(\S+).*;-\)".format(c=_color_block), + re_filename = re.compile(r"^{c} [*] {c}(\S+).*;-\)".format(c=_color_block), re.M) lock_token = "is already locked by another fetcher" @@ -69,8 +69,8 @@ class EmergeFetcher(object): errno=EmergeFetcherError.FetchErrno.Lock) if self.manually_token in data: extension = re.search( - "{nl}( {c}\*{c} The driver.*to be downloaded.*?)" - "{nl}{nl}".format(c=self._color_block, + r"{nl}( {c}\*{c} The driver.*to be downloaded.*?)" + r"{nl}{nl}".format(c=self._color_block, nl=self._new_line), data, re.S) if extension: extension = extension.group(1) diff --git a/pym/builder/variables/__init__.py b/pym/builder/variables/__init__.py index a04b5ac..1f6055a 100644 --- a/pym/builder/variables/__init__.py +++ b/pym/builder/variables/__init__.py @@ -14,10 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import action -import builder -import linux -import profiles -import images + +from . import action +from . import builder +from . import linux +from . import profiles +from . import images section = "builder" diff --git a/pym/builder/variables/builder.py b/pym/builder/variables/builder.py index daed32c..edaf5e3 100644 --- a/pym/builder/variables/builder.py +++ b/pym/builder/variables/builder.py @@ -27,7 +27,7 @@ from calculate.lib.utils.portage import getSquashList, isPkgInstalled from calculate.lib.variables.system import RootType import calculate.update.variables.update as update from .action import Actions -import linux as vars_linux +from . import linux as vars_linux import datetime from calculate.install import distr import calculate.lib.utils.device as device @@ -618,7 +618,7 @@ class VariableClBuilderNewId(BaseBuildId): def check(self, value): if not value and self.Get('cl_builder_source_filename'): raise VariableError(_("Please specify the build ID")) - if value and not re.match("^[A-Za-z][A-Za-z0-9/:_+-]+$", value): + if value and not re.match(r"^[A-Za-z][A-Za-z0-9/:_+-]+$", value): raise VariableError(_("Wrong symbols in the build ID")) if value in self.Get('cl_builder_storage'): raise VariableError(_("Build %s already exists") % _u8(value)) @@ -737,7 +737,7 @@ class VariableClBuilderIdPath(ReadonlyVariable): def get(self): build_id = self.Get('cl_builder_id') if build_id: - return re.sub("[/:]", "_", self.Get('cl_builder_id')) + return re.sub(r"[/:]", "_", self.Get('cl_builder_id')) return "" @@ -789,8 +789,8 @@ class VariableClBuilderParentPath(ReadonlyVariable): def get(self): builder_path = self.Get('cl_builder_path') - return ("../" * len(filter(None, - builder_path.split('/'))))[:-1] + return ("../" * len(list(filter(None, + builder_path.split('/')))))[:-1] class VariableClBuilderStageSet(ReadonlyVariable): @@ -1139,8 +1139,8 @@ class VariableClBuilderKernelVer(KernelInfo): return self.get_src_kernel_version(src) def get_config_version(self, configfile): - re_config = re.compile("Automatically generated file;.*\n" - ".*?Linux/\S+\s+(\S+)\s", re.M) + re_config = re.compile(r"Automatically generated file;.*\n" + r".*?Linux/\S+\s+(\S+)\s", re.M) if path.exists(configfile): with open(configfile) as f: match = re_config.search(f.read(200)) @@ -1160,10 +1160,10 @@ class VariableClBuilderKernelVer(KernelInfo): return version # get version from Makefile - re_makefile = re.compile("^VERSION = (\S+)\n" - "PATCHLEVEL = (\S+)\n" - "SUBLEVEL = (\S+)\n" - "EXTRAVERSION = (\S*)\n", re.M) + re_makefile = re.compile(r"^VERSION = (\S+)\n" + r"PATCHLEVEL = (\S+)\n" + r"SUBLEVEL = (\S+)\n" + r"EXTRAVERSION = (\S*)\n", re.M) if path.exists(makefile_path): with open(makefile_path) as f: match = re_makefile.search(f.read(200)) @@ -1238,7 +1238,7 @@ class VariableClBuilderKernel(KernelData): def filter(self, iterable, version=None): ftype = typeFile(magic=0x4).getMType - re_kver = re.compile("bzImage, version (\S+)\s") + re_kver = re.compile(r"bzImage, version (\S+)\s") for fn in iterable: m = re_kver.search(ftype(fn)) if m.group(1) == version: @@ -1595,7 +1595,7 @@ class VariableClLivemenuPath(ReadonlyVariable): def get(self): data = readFile(self.grub_config) - m = re.search('^livepath=([^\n]+)', data, re.M) + m = re.search(r'^livepath=([^\n]+)', data, re.M) if m: return m.group(1).strip("'\"") return "" diff --git a/pym/builder/variables/images.py b/pym/builder/variables/images.py index 076feee..686ec77 100644 --- a/pym/builder/variables/images.py +++ b/pym/builder/variables/images.py @@ -26,8 +26,8 @@ from calculate.lib.datavars import ReadonlyVariable, HumanReadable, \ ReadonlyTableVariable, FieldValue, VariableError, Variable, \ VariableInterface from calculate.install.variables import system, X11, locale, audio -import builder -from action import Actions +from . import builder +from .action import Actions _ = lambda x: x @@ -123,11 +123,11 @@ class VariableClBuilderImageData(ReadonlyTableVariable): parser = re.compile( r"^.*/(.*?)-((\d{8})|(\d[0-9.]*\d(?:_beta\d+|_alpha\d+|_rc\d+)?))" - "(-\d+)?-(x86_64|i686)\.iso$") + r"(-\d+)?-(x86_64|i686)\.iso$") ver_parser = re.compile( r"^.*/(.*?)-((?:\d[0-9.]*)?\d(?:_beta\d+|_alpha\d+|_rc\d+)?)" - ".*\.iso$") + r".*\.iso$") def sortkey(self, x): m = self.parser.search(x) @@ -307,7 +307,7 @@ class VariableClBuilderX11VideoDrv(GrubOptionVariable, def choice(self): values = (X11.VariableOsInstallX11VideoAvailable.supported + [self.default_video]) - return map(lambda x: (x, self.driver_names.get(x, x)), values) + return list(map(lambda x: (x, self.driver_names.get(x, x)), values)) class VariableClBuilderAudio(GrubOptionVariable, audio.VariableOsAudio): diff --git a/pym/builder/variables/linux.py b/pym/builder/variables/linux.py index 97df845..f41afc7 100644 --- a/pym/builder/variables/linux.py +++ b/pym/builder/variables/linux.py @@ -122,7 +122,7 @@ class DataVarsBuilderLinux(linux.LinuxDataVars): if isinstance(image, distr.ContainerDistributive): c = image.get_information() else: - re_stage = re.compile("stage(\d)-(amd64|x86)-(\d{8}).tar.\w+") + re_stage = re.compile(r"stage(\d)-(amd64|x86)-(\d{8}).tar.\w+") m = re_stage.search(fn) if m: map_arch = {'amd64': 'x86_64', 'x86': 'i686'} @@ -481,8 +481,8 @@ class VariableClBuilderSyncOverlayRep(ReadonlyVariable): else: dv = self.Get('cl_builder_linux_datavars') if dv: - return filter(lambda x: x not in ("portage", "gentoo"), - dv.Get('cl_repository_name')) + return list(filter(lambda x: x not in ("portage", "gentoo"), + dv.Get('cl_repository_name'))) else: return [] diff --git a/pym/builder/wsdl_builder.py b/pym/builder/wsdl_builder.py index d2ec827..8f91269 100644 --- a/pym/builder/wsdl_builder.py +++ b/pym/builder/wsdl_builder.py @@ -26,13 +26,13 @@ from calculate.update.update import UpdateError from .datavars import BuilderError from .variables.action import Actions as BuilderActions from calculate.lib.utils.git import GitError -from utils.cl_builder_prepare import ClBuilderPrepareAction -from utils.cl_builder_profile import ClBuilderProfileAction -from utils.cl_builder_break import ClBuilderBreakAction -from utils.cl_builder_update import ClBuilderUpdateAction -from utils.cl_builder_restore import ClBuilderRestoreAction -from utils.cl_builder_image import ClBuilderImageAction -from utils.cl_builder_menu import ClBuilderMenuAction +from .utils.cl_builder_prepare import ClBuilderPrepareAction +from .utils.cl_builder_profile import ClBuilderProfileAction +from .utils.cl_builder_break import ClBuilderBreakAction +from .utils.cl_builder_update import ClBuilderUpdateAction +from .utils.cl_builder_restore import ClBuilderRestoreAction +from .utils.cl_builder_image import ClBuilderImageAction +from .utils.cl_builder_menu import ClBuilderMenuAction _ = lambda x: x from calculate.lib.cl_lang import setLocalTranslate, getLazyLocalTranslate diff --git a/setup.py b/setup.py index 5b4497b..2349634 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # -*- coding: utf-8 -*- # setup.py --- Setup script for calculate-builder