diff options
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oe/package_manager/__init__.py | 9 | ||||
-rw-r--r-- | meta/lib/oe/package_manager/ipk/__init__.py | 8 | ||||
-rw-r--r-- | meta/lib/oe/patch.py | 8 | ||||
-rw-r--r-- | meta/lib/oe/reproducible.py | 2 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/debuginfod.py | 14 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/devtool.py | 14 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/recipetool.py | 16 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/cases/runtime_test.py | 2 | ||||
-rw-r--r-- | meta/lib/patchtest/repo.py | 88 | ||||
-rw-r--r-- | meta/lib/patchtest/requirements.txt | 1 | ||||
-rw-r--r-- | meta/lib/patchtest/selftest/files/TestMbox.test_bugzilla_entry_format.fail | 25 | ||||
-rw-r--r-- | meta/lib/patchtest/utils.py | 129 |
12 files changed, 90 insertions, 226 deletions
diff --git a/meta/lib/oe/package_manager/__init__.py b/meta/lib/oe/package_manager/__init__.py index 6774cdb794..d3b2317894 100644 --- a/meta/lib/oe/package_manager/__init__.py +++ b/meta/lib/oe/package_manager/__init__.py @@ -449,7 +449,7 @@ class PackageManager(object, metaclass=ABCMeta): return res return _append(uris, base_paths) -def create_packages_dir(d, subrepo_dir, deploydir, taskname, filterbydependencies): +def create_packages_dir(d, subrepo_dir, deploydir, taskname, filterbydependencies, include_self=False): """ Go through our do_package_write_X dependencies and hardlink the packages we depend upon into the repo directory. This prevents us seeing other packages that may @@ -486,14 +486,17 @@ def create_packages_dir(d, subrepo_dir, deploydir, taskname, filterbydependencie bb.fatal("Couldn't find ourself in BB_TASKDEPDATA?") pkgdeps = set() start = [start] - seen = set(start) + if include_self: + seen = set() + else: + seen = set(start) # Support direct dependencies (do_rootfs -> do_package_write_X) # or indirect dependencies within PN (do_populate_sdk_ext -> do_rootfs -> do_package_write_X) while start: next = [] for dep2 in start: for dep in taskdepdata[dep2][3]: - if taskdepdata[dep][0] != pn: + if include_self or taskdepdata[dep][0] != pn: if "do_" + taskname in dep: pkgdeps.add(dep) elif dep not in seen: diff --git a/meta/lib/oe/package_manager/ipk/__init__.py b/meta/lib/oe/package_manager/ipk/__init__.py index 8cc9953a02..0f0038d00d 100644 --- a/meta/lib/oe/package_manager/ipk/__init__.py +++ b/meta/lib/oe/package_manager/ipk/__init__.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: GPL-2.0-only # +import glob import re import shutil import subprocess @@ -134,11 +135,16 @@ class OpkgDpkgPM(PackageManager): tmp_dir = tempfile.mkdtemp() current_dir = os.getcwd() os.chdir(tmp_dir) - data_tar = 'data.tar.zst' try: cmd = [ar_cmd, 'x', pkg_path] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) + data_tar = glob.glob("data.tar.*") + if len(data_tar) != 1: + bb.fatal("Unable to extract %s package. Failed to identify " + "data tarball (found tarballs '%s').", + pkg_path, data_tar) + data_tar = data_tar[0] cmd = [tar_cmd, 'xf', data_tar] output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index 60a0cc8291..58c6e34fe8 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py @@ -882,7 +882,7 @@ class UserResolver(Resolver): os.chdir(olddir) -def patch_path(url, fetch, workdir, expand=True): +def patch_path(url, fetch, unpackdir, expand=True): """Return the local path of a patch, or return nothing if this isn't a patch""" local = fetch.localpath(url) @@ -891,7 +891,7 @@ def patch_path(url, fetch, workdir, expand=True): base, ext = os.path.splitext(os.path.basename(local)) if ext in ('.gz', '.bz2', '.xz', '.Z'): if expand: - local = os.path.join(workdir, base) + local = os.path.join(unpackdir, base) ext = os.path.splitext(base)[1] urldata = fetch.ud[url] @@ -905,12 +905,12 @@ def patch_path(url, fetch, workdir, expand=True): return local def src_patches(d, all=False, expand=True): - workdir = d.getVar('WORKDIR') + unpackdir = d.getVar('UNPACKDIR') fetch = bb.fetch2.Fetch([], d) patches = [] sources = [] for url in fetch.urls: - local = patch_path(url, fetch, workdir, expand) + local = patch_path(url, fetch, unpackdir, expand) if not local: if all: local = fetch.localpath(url) diff --git a/meta/lib/oe/reproducible.py b/meta/lib/oe/reproducible.py index 448befce33..a9f717159e 100644 --- a/meta/lib/oe/reproducible.py +++ b/meta/lib/oe/reproducible.py @@ -120,7 +120,7 @@ def get_source_date_epoch_from_git(d, sourcedir): return int(p.stdout.decode('utf-8')) def get_source_date_epoch_from_youngest_file(d, sourcedir): - if sourcedir == d.getVar('WORKDIR'): + if sourcedir == d.getVar('UNPACKDIR'): # These sources are almost certainly not from a tarball return None diff --git a/meta/lib/oeqa/selftest/cases/debuginfod.py b/meta/lib/oeqa/selftest/cases/debuginfod.py index 505b4be837..46c0cd87bb 100644 --- a/meta/lib/oeqa/selftest/cases/debuginfod.py +++ b/meta/lib/oeqa/selftest/cases/debuginfod.py @@ -62,7 +62,7 @@ class Debuginfod(OESelftestTestCase): raise TimeoutError("Cannot connect debuginfod, still %d scan jobs running" % latest) - def start_debuginfod(self): + def start_debuginfod(self, feed_dir): # We assume that the caller has already bitbake'd elfutils-native:do_addto_recipe_sysroot # Save some useful paths for later @@ -82,7 +82,7 @@ class Debuginfod(OESelftestTestCase): # Disable rescanning, this is a one-shot test "--rescan-time=0", "--groom-time=0", - get_bb_var("DEPLOY_DIR"), + feed_dir, ] format = get_bb_var("PACKAGE_CLASSES").split()[0] @@ -114,11 +114,12 @@ class Debuginfod(OESelftestTestCase): self.write_config(""" TMPDIR = "${TOPDIR}/tmp-debuginfod" DISTRO_FEATURES:append = " debuginfod" +INHERIT += "localpkgfeed" """) - bitbake("elfutils-native:do_addto_recipe_sysroot xz xz:do_package") + bitbake("elfutils-native:do_addto_recipe_sysroot xz xz:do_package xz:do_localpkgfeed") try: - self.start_debuginfod() + self.start_debuginfod(get_bb_var("LOCALPKGFEED_DIR", "xz")) env = os.environ.copy() env["DEBUGINFOD_URLS"] = "http://localhost:%d/" % self.port @@ -141,12 +142,13 @@ DISTRO_FEATURES:append = " debuginfod" self.write_config(""" TMPDIR = "${TOPDIR}/tmp-debuginfod" DISTRO_FEATURES:append = " debuginfod" +INHERIT += "localpkgfeed" CORE_IMAGE_EXTRA_INSTALL += "elfutils xz" """) - bitbake("core-image-minimal elfutils-native:do_addto_recipe_sysroot") + bitbake("core-image-minimal elfutils-native:do_addto_recipe_sysroot xz:do_localpkgfeed") try: - self.start_debuginfod() + self.start_debuginfod(get_bb_var("LOCALPKGFEED_DIR", "xz")) with runqemu("core-image-minimal", runqemuparams="nographic") as qemu: cmd = "DEBUGINFOD_URLS=http://%s:%d/ debuginfod-find debuginfo /usr/bin/xz" % (qemu.server_ip, self.port) diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py index 51949e3c93..882225dde3 100644 --- a/meta/lib/oeqa/selftest/cases/devtool.py +++ b/meta/lib/oeqa/selftest/cases/devtool.py @@ -286,10 +286,13 @@ class DevtoolTestCase(OESelftestTestCase): else: self.skipTest('No tap devices found - you must set up tap devices with scripts/runqemu-gen-tapdevs before running this test') - def _test_devtool_add_git_url(self, git_url, version, pn, resulting_src_uri): + def _test_devtool_add_git_url(self, git_url, version, pn, resulting_src_uri, srcrev=None): self.track_for_cleanup(self.workspacedir) self.add_command_to_tearDown('bitbake-layers remove-layer */workspace') - result = runCmd('devtool add --version %s %s %s' % (version, pn, git_url)) + command = 'devtool add --version %s %s %s' % (version, pn, git_url) + if srcrev : + command += ' --srcrev %s' %srcrev + result = runCmd(command) self.assertExists(os.path.join(self.workspacedir, 'conf', 'layer.conf'), 'Workspace directory not created') # Check the recipe name is correct recipefile = get_bb_var('FILE', pn) @@ -479,11 +482,12 @@ class DevtoolAddTests(DevtoolBase): def test_devtool_add_git_style2(self): version = 'v3.1.0' + srcrev = 'v3.1.0' pn = 'mbedtls' # this will trigger reformat_git_uri with branch parameter in url git_url = "'git://git@github.com/ARMmbed/mbedtls.git;protocol=https'" - resulting_src_uri = "gitsm://git@github.com/ARMmbed/mbedtls.git;protocol=https;branch=master" - self._test_devtool_add_git_url(git_url, version, pn, resulting_src_uri) + resulting_src_uri = "git://git@github.com/ARMmbed/mbedtls.git;protocol=https;branch=master" + self._test_devtool_add_git_url(git_url, version, pn, resulting_src_uri, srcrev) def test_devtool_add_library(self): # Fetch source @@ -1769,6 +1773,8 @@ class DevtoolExtractTests(DevtoolBase): # Definitions testrecipe = 'mdadm' testfile = '/sbin/mdadm' + if "usrmerge" in get_bb_var('DISTRO_FEATURES'): + testfile = '/usr/sbin/mdadm' testimage = 'oe-selftest-image' testcommand = '/sbin/mdadm --help' # Build an image to run diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py index aebea42502..126906df50 100644 --- a/meta/lib/oeqa/selftest/cases/recipetool.py +++ b/meta/lib/oeqa/selftest/cases/recipetool.py @@ -120,9 +120,15 @@ class RecipetoolAppendTests(RecipetoolBase): self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool']) def test_recipetool_appendfile_alternatives(self): + lspath = '/bin/ls' + dirname = "base_bindir" + if "usrmerge" in get_bb_var('DISTRO_FEATURES'): + lspath = '/usr/bin/ls' + dirname = "bindir" + # Now try with a file we know should be an alternative # (this is very much a fake example, but one we know is reliably an alternative) - self._try_recipetool_appendfile_fail('/bin/ls', self.testfile, ['ERROR: File /bin/ls is an alternative possibly provided by the following recipes:', 'coreutils', 'busybox']) + self._try_recipetool_appendfile_fail(lspath, self.testfile, ['ERROR: File %s is an alternative possibly provided by the following recipes:' % lspath, 'coreutils', 'busybox']) # Need a test file - should be executable testfile2 = os.path.join(self.corebase, 'oe-init-build-env') testfile2name = os.path.basename(testfile2) @@ -131,12 +137,12 @@ class RecipetoolAppendTests(RecipetoolBase): 'SRC_URI += "file://%s"\n' % testfile2name, '\n', 'do_install:append() {\n', - ' install -d ${D}${base_bindir}\n', - ' install -m 0755 ${WORKDIR}/%s ${D}${base_bindir}/ls\n' % testfile2name, + ' install -d ${D}${%s}\n' % dirname, + ' install -m 0755 ${WORKDIR}/%s ${D}${%s}/ls\n' % (testfile2name, dirname), '}\n'] - self._try_recipetool_appendfile('coreutils', '/bin/ls', testfile2, '-r coreutils', expectedlines, [testfile2name]) + self._try_recipetool_appendfile('coreutils', lspath, testfile2, '-r coreutils', expectedlines, [testfile2name]) # Now try bbappending the same file again, contents should not change - bbappendfile, _ = self._try_recipetool_appendfile('coreutils', '/bin/ls', self.testfile, '-r coreutils', expectedlines, [testfile2name]) + bbappendfile, _ = self._try_recipetool_appendfile('coreutils', lspath, self.testfile, '-r coreutils', expectedlines, [testfile2name]) # But file should have copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name) result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True) diff --git a/meta/lib/oeqa/selftest/cases/runtime_test.py b/meta/lib/oeqa/selftest/cases/runtime_test.py index 12000aac16..13aa5f16c9 100644 --- a/meta/lib/oeqa/selftest/cases/runtime_test.py +++ b/meta/lib/oeqa/selftest/cases/runtime_test.py @@ -273,7 +273,7 @@ TEST_RUNQEMUPARAMS += " slirp" import subprocess, os distro = oe.lsb.distro_identifier() - if distro and (distro in ['debian-9', 'debian-10', 'centos-7', 'centos-8', 'ubuntu-16.04', 'ubuntu-18.04'] or + if distro and (distro in ['debian-9', 'debian-10', 'centos-7', 'centos-8', 'centos-9', 'ubuntu-16.04', 'ubuntu-18.04'] or distro.startswith('almalinux') or distro.startswith('rocky')): self.skipTest('virgl headless cannot be tested with %s' %(distro)) diff --git a/meta/lib/patchtest/repo.py b/meta/lib/patchtest/repo.py index d3788f466d..5f361ac500 100644 --- a/meta/lib/patchtest/repo.py +++ b/meta/lib/patchtest/repo.py @@ -11,6 +11,7 @@ import os import utils import logging +import git from patch import PatchTestPatch logger = logging.getLogger('patchtest') @@ -21,15 +22,17 @@ class PatchTestRepo(object): # prefixes used for temporal branches/stashes prefix = 'patchtest' + def __init__(self, patch, repodir, commit=None, branch=None): self._repodir = repodir + self._repo = git.Repo.init(repodir) self._patch = PatchTestPatch(patch) - self._current_branch = self._get_current_branch() + self._current_branch = self._repo.active_branch.name # targeted branch defined on the patch may be invalid, so make sure there # is a corresponding remote branch valid_patch_branch = None - if self._patch.branch in self.upstream_branches(): + if self._patch.branch in self._repo.branches: valid_patch_branch = self._patch.branch # Target Branch @@ -52,22 +55,19 @@ class PatchTestRepo(object): self._workingbranch = "%s_%s" % (PatchTestRepo.prefix, os.getpid()) - # create working branch - self._exec({'cmd': ['git', 'checkout', '-b', self._workingbranch, self._commit]}) + # create working branch. Use the '-B' flag so that we just + # check out the existing one if it's there + self._repo.git.execute(['git', 'checkout', '-B', self._workingbranch, self._commit]) self._patchmerged = False # Check if patch can be merged using git-am self._patchcanbemerged = True try: - self._exec({'cmd': ['git', 'am', '--keep-cr'], 'input': self._patch.contents}) - except utils.CmdException as ce: - self._exec({'cmd': ['git', 'am', '--abort']}) + # Make sure to get the absolute path of the file + self._repo.git.execute(['git', 'apply', '--check', os.path.abspath(self._patch.path)], with_exceptions=True) + except git.exc.GitCommandError as ce: self._patchcanbemerged = False - finally: - # if patch was applied, remove it - if self._patchcanbemerged: - self._exec({'cmd':['git', 'reset', '--hard', self._commit]}) # for debugging purposes, print all repo parameters logger.debug("Parameters") @@ -97,78 +97,24 @@ class PatchTestRepo(object): def canbemerged(self): return self._patchcanbemerged - def _exec(self, cmds): - _cmds = [] - if isinstance(cmds, dict): - _cmds.append(cmds) - elif isinstance(cmds, list): - _cmds = cmds - else: - raise utils.CmdException({'cmd':str(cmds)}) - - results = [] - cmdfailure = False - try: - results = utils.exec_cmds(_cmds, self._repodir) - except utils.CmdException as ce: - cmdfailure = True - raise ce - finally: - if cmdfailure: - for cmd in _cmds: - logger.debug("CMD: %s" % ' '.join(cmd['cmd'])) - else: - for result in results: - cmd, rc, stdout, stderr = ' '.join(result['cmd']), result['returncode'], result['stdout'], result['stderr'] - logger.debug("CMD: %s RCODE: %s STDOUT: %s STDERR: %s" % (cmd, rc, stdout, stderr)) - - return results - - def _get_current_branch(self, commit='HEAD'): - cmd = {'cmd':['git', 'rev-parse', '--abbrev-ref', commit]} - cb = self._exec(cmd)[0]['stdout'] - if cb == commit: - logger.warning('You may be detached so patchtest will checkout to master after execution') - cb = 'master' - return cb - def _get_commitid(self, commit): if not commit: return None try: - cmd = {'cmd':['git', 'rev-parse', '--short', commit]} - return self._exec(cmd)[0]['stdout'] - except utils.CmdException as ce: - # try getting the commit under any remotes - cmd = {'cmd':['git', 'remote']} - remotes = self._exec(cmd)[0]['stdout'] - for remote in remotes.splitlines(): - cmd = {'cmd':['git', 'rev-parse', '--short', '%s/%s' % (remote, commit)]} - try: - return self._exec(cmd)[0]['stdout'] - except utils.CmdException: - pass + return self._repo.rev_parse(commit).hexsha + except Exception as e: + print(f"Couldn't find commit {commit} in repo") return None - def upstream_branches(self): - cmd = {'cmd':['git', 'branch', '--remotes']} - remote_branches = self._exec(cmd)[0]['stdout'] - - # just get the names, without the remote name - branches = set(branch.split('/')[-1] for branch in remote_branches.splitlines()) - return branches - def merge(self): if self._patchcanbemerged: - self._exec({'cmd': ['git', 'am', '--keep-cr'], - 'input': self._patch.contents, - 'updateenv': {'PTRESOURCE':self._patch.path}}) + self._repo.git.execute(['git', 'am', '--keep-cr', os.path.abspath(self._patch.path)]) self._patchmerged = True def clean(self): - self._exec({'cmd':['git', 'checkout', '%s' % self._current_branch]}) - self._exec({'cmd':['git', 'branch', '-D', self._workingbranch]}) + self._repo.git.execute(['git', 'checkout', self._current_branch]) + self._repo.git.execute(['git', 'branch', '-D', self._workingbranch]) self._patchmerged = False diff --git a/meta/lib/patchtest/requirements.txt b/meta/lib/patchtest/requirements.txt index ba55ff905e..4247b91f09 100644 --- a/meta/lib/patchtest/requirements.txt +++ b/meta/lib/patchtest/requirements.txt @@ -1,5 +1,6 @@ boto3 git-pw>=2.5.0 +GitPython jinja2 pylint pyparsing>=3.0.9 diff --git a/meta/lib/patchtest/selftest/files/TestMbox.test_bugzilla_entry_format.fail b/meta/lib/patchtest/selftest/files/TestMbox.test_bugzilla_entry_format.fail index 80f409e952..854d7eb8c7 100644 --- a/meta/lib/patchtest/selftest/files/TestMbox.test_bugzilla_entry_format.fail +++ b/meta/lib/patchtest/selftest/files/TestMbox.test_bugzilla_entry_format.fail @@ -1,25 +1,26 @@ -From fdfd605e565d874502522c4b70b786c8c5aa0bad Mon Sep 17 00:00:00 2001 +From f06e14633723c1e78bc7a4b0fd0d3b79d09f0c68 Mon Sep 17 00:00:00 2001 From: name@somedomain.com <email@address.com> -Date: Fri, 17 Feb 2017 16:29:21 -0600 -Subject: [PATCH] README: adds 'foo' to the header +Date: Thu, 2 May 2024 10:21:45 -0400 +Subject: [PATCH] README.OE-Core.md: Add foo to header -This test patch adds 'foo' to the header +This test patch adds 'foo' to the header of README.OE-Core.md [YOCTO 1234] -Signed-off-by: Daniela Plascencia <daniela.plascencia@linux.intel.com> +Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com> --- - README | 1 + + README.OE-Core.md | 1 + 1 file changed, 1 insertion(+) -diff --git a/README b/README -index 521916cd4f..cdf29dcea3 100644 ---- a/README -+++ b/README +diff --git a/README.OE-Core.md b/README.OE-Core.md +index 687c58e410c..9d863891134 100644 +--- a/README.OE-Core.md ++++ b/README.OE-Core.md @@ -1,3 +1,4 @@ +**** FOO **** OpenEmbedded-Core ================= + +-- +2.44.0 --- -2.11.0 diff --git a/meta/lib/patchtest/utils.py b/meta/lib/patchtest/utils.py index dd0abc22d9..8eddf3e85f 100644 --- a/meta/lib/patchtest/utils.py +++ b/meta/lib/patchtest/utils.py @@ -14,109 +14,6 @@ import logging import re import mailbox -class CmdException(Exception): - """ Simple exception class where its attributes are the ones passed when instantiated """ - def __init__(self, cmd): - self._cmd = cmd - def __getattr__(self, name): - value = None - if self._cmd.has_key(name): - value = self._cmd[name] - return value - -def exec_cmd(cmd, cwd, ignore_error=False, input=None, strip=True, updateenv={}): - """ - Input: - - cmd: dict containing the following keys: - - cmd : the command itself as an array of strings - ignore_error: if False, no exception is raised - strip: indicates if strip is done on the output (stdout and stderr) - input: input data to the command (stdin) - updateenv: environment variables to be appended to the current - process environment variables - - NOTE: keys 'ignore_error' and 'input' are optional; if not included, - the defaults are the ones specify in the arguments - cwd: directory where commands are executed - ignore_error: raise CmdException if command fails to execute and - this value is False - input: input data (stdin) for the command - - Output: dict containing the following keys: - - cmd: the same as input - ignore_error: the same as input - strip: the same as input - input: the same as input - stdout: Standard output after command's execution - stderr: Standard error after command's execution - returncode: Return code after command's execution - - """ - cmddefaults = { - 'cmd':'', - 'ignore_error':ignore_error, - 'strip':strip, - 'input':input, - 'updateenv':updateenv, - } - - # update input values if necessary - cmddefaults.update(cmd) - - _cmd = cmddefaults - - if not _cmd['cmd']: - raise CmdException({'cmd':None, 'stderr':'no command given'}) - - # update the environment - env = os.environ - env.update(_cmd['updateenv']) - - _command = [e for e in _cmd['cmd']] - p = subprocess.Popen(_command, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True, - cwd=cwd, - env=env) - - # execute the command and strip output - (_stdout, _stderr) = p.communicate(_cmd['input']) - if _cmd['strip']: - _stdout, _stderr = map(str.strip, [_stdout, _stderr]) - - # generate the result - result = _cmd - result.update({'cmd':_command,'stdout':_stdout,'stderr':_stderr,'returncode':p.returncode}) - - # launch exception if necessary - if not _cmd['ignore_error'] and p.returncode: - raise CmdException(result) - - return result - -def exec_cmds(cmds, cwd): - """ Executes commands - - Input: - cmds: Array of commands - cwd: directory where commands are executed - - Output: Array of output commands - """ - results = [] - _cmds = cmds - - for cmd in _cmds: - result = exec_cmd(cmd, cwd) - results.append(result) - - return results - def logger_create(name): logger = logging.getLogger(name) loggerhandler = logging.StreamHandler() @@ -125,20 +22,6 @@ def logger_create(name): logger.setLevel(logging.INFO) return logger -def get_subject_prefix(path): - prefix = "" - mbox = mailbox.mbox(path) - - if len(mbox): - subject = mbox[0]['subject'] - if subject: - pattern = re.compile(r"(\[.*\])", re.DOTALL) - match = pattern.search(subject) - if match: - prefix = match.group(1) - - return prefix - def valid_branch(branch): """ Check if branch is valid name """ lbranch = branch.lower() @@ -153,7 +36,17 @@ def valid_branch(branch): def get_branch(path): """ Get the branch name from mbox """ - fullprefix = get_subject_prefix(path) + fullprefix = "" + mbox = mailbox.mbox(path) + + if len(mbox): + subject = mbox[0]['subject'] + if subject: + pattern = re.compile(r"(\[.*\])", re.DOTALL) + match = pattern.search(subject) + if match: + fullprefix = match.group(1) + branch, branches, valid_branches = None, [], [] if fullprefix: |