def check(self, path): """ the real check """ super(UniventionPackageCheck, self).check(path) fn = os.path.join(path, 'debian', 'control') self.debug('Reading %s' % (fn, )) try: parser = uub.ParserDebianControl(fn) self.path = path except uub.FailedToReadFile, e: self.addmsg('0014-0', 'failed to open and read file', filename=fn) return
def check(self, path): """ the real check """ super(UniventionPackageCheck, self).check(path) fn = join(path, 'debian', 'control') self.debug('Reading %s' % (fn,)) try: parser = uub.ParserDebianControl(fn) self.path = path except uub.FailedToReadFile: self.addmsg('0014-0', 'failed to open and read file', filename=fn) return except uub.UCSLintException: self.addmsg('0014-1', 'parsing error', filename=fn) return deps = self.check_source(parser.source_section) for section in parser.binary_sections: deps |= self.check_package(section) self.check_unknown(path, parser) self.check_transitional(path, deps)
def check(self, path): """ the real check """ super(UniventionPackageCheck, self).check(path) fn_changelog = os.path.join(path, 'debian', 'changelog') try: content_changelog = open(fn_changelog, 'r').read(1024) except IOError: self.addmsg('0011-1', 'failed to open and read file', filename=fn_changelog) return fn_control = os.path.join(path, 'debian', 'control') try: parser = uub.ParserDebianControl(fn_control) except uub.FailedToReadFile: self.addmsg('0011-1', 'failed to open and read file', filename=fn_control) return except uub.UCSLintException: self.addmsg('0011-11', 'parsing error', filename=fn_control) return # compare package name reChangelogPackage = re.compile('^([a-z0-9.-]+) \((.*?)\) (.*?)\n') match = reChangelogPackage.match(content_changelog) if match: srcpkgname = match.group(1) else: srcpkgname = None self.addmsg('0011-9', 'cannot determine source package name', filename=fn_changelog) controlpkgname = parser.source_section.get('Source') if not controlpkgname: self.addmsg('0011-9', 'cannot determine source package name', filename=fn_control) if srcpkgname and controlpkgname: if srcpkgname != controlpkgname: self.addmsg( '0011-2', 'source package name differs in debian/changelog and debian/control', filename=fn_changelog) # parse source section of debian/control if not parser.source_section.get('Section', '') in ('univention'): self.addmsg('0011-3', 'wrong Section entry - should be "univention"', filename=fn_control) if not parser.source_section.get('Priority', '') in ('optional'): self.addmsg('0011-4', 'wrong Priority entry - should be "optional"', filename=fn_control) if not parser.source_section.get( 'Maintainer', '') in ('Univention GmbH <*****@*****.**>'): self.addmsg( '0011-5', 'wrong Maintainer entry - should be "Univention GmbH <*****@*****.**>"', filename=fn_control) if parser.source_section.get('XS-Python-Version', ''): self.addmsg('0011-11', 'XS-Python-Version is not required any longer', filename=fn_control) if 'python-central' in parser.source_section.get('Build-Depends', ''): self.addmsg( '0011-12', 'please use python-support instead of python-central in Build-Depends', filename=fn_control) if 'ucslint' not in parser.source_section.get('Build-Depends', ''): self.addmsg('0011-13', 'ucslint is missing in Build-Depends', filename=fn_control) self.check_debhelper(path, parser)
def check(self, path): """ the real check """ super(UniventionPackageCheck, self).check(path) fnlist_joinscripts = {} # # search join scripts # for f in os.listdir(path): if f.endswith('.inst') and f[0:2].isdigit(): fn = os.path.join(path, f) fnlist_joinscripts[fn] = False self.debug('found %s' % fn) # # check if join scripts use versioning # for js in fnlist_joinscripts.keys(): self.check_join_script(js) # # check if join scripts are present in debian/rules || debian/*.install # found = {} debianpath = os.path.join(path, 'debian') # get all .install files fnlist = list( uub.FilteredDirWalkGenerator(debianpath, suffixes=['.install'])) # append debian/rules fn_rules = os.path.join(path, 'debian', 'rules') fnlist.append(fn_rules) # Look for dh-umc-modules-install try: content = open(fn_rules, 'r').read() except IOError: self.addmsg('0001-9', 'failed to open and read file', fn_rules) else: if UniventionPackageCheck.RE_DH_JOIN.search(content): self.debug('Detected use of univention-install-joinscript') try: fn_control = os.path.join(path, 'debian', 'control') parser = uub.ParserDebianControl(fn_control) except uub.UCSLintException: self.debug('Errors in debian/control. Skipping here') else: for binary_package in parser.binary_sections: package = binary_package.get('Package') for js in fnlist_joinscripts.keys(): if re.match( r'^\./\d\d%s.inst$' % re.escape(package), js): self.debug( 'univention-install-joinscript will take care of %s' % js) fnlist_joinscripts[js] = True found[js] = found.get(js, 0) + 1 if UniventionPackageCheck.RE_DH_UMC.search(content): self.debug('Detected use of dh-umc-module-install') for fn in uub.FilteredDirWalkGenerator( debianpath, suffixes=['.umc-modules']): package = os.path.basename(fn)[:-len('.umc-modules')] inst = '%s.inst' % (package, ) for js in fnlist_joinscripts.keys(): if js.endswith(inst): self.debug( '%s installed by dh-umc-module-install' % (js, )) found[js] = found.get(js, 0) + 1 fnlist_joinscripts[js] = True for fn in fnlist: try: content = open(fn, 'r').read() except IOError: self.addmsg('0001-9', 'failed to open and read file', fn) for js in fnlist_joinscripts.keys(): name = os.path.basename(js) self.debug('looking for %s in %s' % (name, fn)) if name in content: self.debug('found %s in %s' % (name, fn)) found[js] = found.get(js, 0) + 1 for js in fnlist_joinscripts.keys(): if found.get(js, 0) == 0: self.addmsg( '0001-6', 'join script is not mentioned in debian/rules or *.install files', js) # # check if join scripts are present in debian/*postinst # for f in os.listdir(os.path.join(path, 'debian')): if (f.endswith('.postinst') and not f.endswith('.debhelper.postinst')) or (f == 'postinst'): fn = os.path.join(path, 'debian', f) self.debug('loading %s' % (fn)) try: content = open(fn, 'r').read() except IOError: self.addmsg('0001-9', 'failed to open and read file', fn) continue for js in fnlist_joinscripts.keys(): name = os.path.basename(js) self.debug('looking for %s in %s' % (name, fn)) if name in content: fnlist_joinscripts[js] = True self.debug('found %s in %s' % (name, fn)) match = UniventionPackageCheck.RE_LINE_CONTAINS_SET_E.search( content) if match: self.debug('found "set -e" in %s' % fn) for line in content.splitlines(): if name in line: match = UniventionPackageCheck.RE_LINE_ENDS_WITH_TRUE.search( line) if not match: self.addmsg( '0001-8', 'the join script %s is not called with "|| true" but "set -e" is set' % (name, ), fn) for js, found in fnlist_joinscripts.items(): if not found: self.addmsg( '0001-7', 'Join script is not mentioned in debian/*.postinst', js)
def check(self, path: str) -> None: """ the real check """ super(UniventionPackageCheck, self).check(path) fnlist_joinscripts = {} # # search join scripts # for f in os.listdir(path): if not f[0:2].isdigit(): continue fn = os.path.join(path, f) if f.endswith('.inst'): fnlist_joinscripts[fn] = CALLED elif f.endswith('.uinst'): fnlist_joinscripts[fn] = CALLED | COPIED else: continue self.debug('found %s' % fn) # # check if join scripts use versioning # for js in fnlist_joinscripts: self.check_join_script(js) # # check if join scripts are present in debian/rules || debian/*.install # found = {} # type: Dict[str, int] debianpath = os.path.join(path, 'debian') # get all .install files fnlist = list( uub.FilteredDirWalkGenerator(debianpath, suffixes=['.install'])) # append debian/rules fn_rules = os.path.join(path, 'debian', 'rules') fnlist.append(fn_rules) # Look for dh-umc-modules-install try: content = open(fn_rules, 'r').read() except EnvironmentError: self.addmsg('0001-9', 'failed to open and read file', fn_rules) else: if self.RE_DH_JOIN.search(content): self.debug('Detected use of univention-install-joinscript') try: fn_control = os.path.join(path, 'debian', 'control') parser = uub.ParserDebianControl(fn_control) except uub.UCSLintException: self.debug('Errors in debian/control. Skipping here') else: for binary_package in parser.binary_sections: package = binary_package['Package'] for js in fnlist_joinscripts: if re.match( r'^\./\d\d%s\.u?inst$' % re.escape(package), js): self.debug( 'univention-install-joinscript will take care of %s' % js) fnlist_joinscripts[js] = 0 found[js] = found.get(js, 0) + 1 if self.RE_DH_UMC.search(content): self.debug('Detected use of dh-umc-module-install') for fn in uub.FilteredDirWalkGenerator( debianpath, suffixes=['.umc-modules']): package = os.path.basename(fn)[:-len('.umc-modules')] inst = '%s.inst' % (package, ) uinst = '%s.uinst' % (package, ) for js in fnlist_joinscripts: if js.endswith(inst) or js.endswith(uinst): self.debug( '%s installed by dh-umc-module-install' % (js, )) found[js] = found.get(js, 0) + 1 fnlist_joinscripts[js] = 0 for fn in fnlist: try: content = open(fn, 'r').read() except EnvironmentError: self.addmsg('0001-9', 'failed to open and read file', fn) continue for js in fnlist_joinscripts: name = os.path.basename(js) self.debug('looking for %s in %s' % (name, fn)) if name in content: self.debug('found %s in %s' % (name, fn)) found[js] = found.get(js, 0) + 1 for js in fnlist_joinscripts: if found.get(js, 0) == 0: self.addmsg( '0001-6', 'join script is not mentioned in debian/rules or *.install files', js) # # check if join scripts are present in debian/*{pre,post}{inst,rm} # for f in os.listdir(os.path.join(path, 'debian')): if '.debhelper.' in f: continue if f.endswith('.postinst') or f == 'postinst': bit = CALLED elif f.endswith('.prerm') or f == 'prerm': bit = COPIED elif f.endswith('.postrm') or f == 'postrm': bit = CALLED else: continue fn = os.path.join(path, 'debian', f) self.debug('loading %s' % (fn)) try: content = open(fn, 'r').read() except EnvironmentError: self.addmsg('0001-9', 'failed to open and read file', fn) continue set_e = self.RE_LINE_CONTAINS_SET_E.search(content) if set_e: self.debug('found "set -e" in %s' % fn) for js in fnlist_joinscripts: name = os.path.basename(js) self.debug('looking for %s in %s' % (name, fn)) if name in content: fnlist_joinscripts[js] &= ~bit self.debug('found %s in %s' % (name, fn)) if set_e: for row, line in enumerate(content.splitlines(), start=1): if name in line: match = self.RE_LINE_ENDS_WITH_TRUE.search( line) if not match: self.addmsg( '0001-8', 'the join script %s is not called with "|| true" but "set -e" is set' % (name, ), fn, row, line=line) for js, missing in fnlist_joinscripts.items(): if missing & CALLED and js.endswith('.inst'): self.addmsg( '0001-7', 'Join script is not mentioned in debian/*.postinst', js) if missing & CALLED and js.endswith('.uinst'): self.addmsg( '0001-17', 'Unjoin script seems not to be called in any postrm file', js) if missing & COPIED and js.endswith('.uinst'): self.addmsg( '0001-18', 'Unjoin script seems not to be copied in any prerm file', js)
def check(self, path: str) -> None: """ the real check """ super(UniventionPackageCheck, self).check(path) fn_changelog = os.path.join(path, 'debian', 'changelog') try: content_changelog = open(fn_changelog, 'r').read(1024) except EnvironmentError: self.addmsg('0011-1', 'failed to open and read file', fn_changelog) return fn_control = os.path.join(path, 'debian', 'control') try: parser = uub.ParserDebianControl(fn_control) except uub.FailedToReadFile: self.addmsg('0011-1', 'failed to open and read file', fn_control) return except uub.UCSLintException: self.addmsg('0011-11', 'parsing error', fn_control) return compat_version = 0 fn_compat = os.path.join(path, 'debian', 'compat') try: content_compat = open(fn_compat, 'r').read() compat_version = int(content_compat) except EnvironmentError: # self.addmsg('0011-1', 'failed to open and read file', fn_compat) pass except ValueError: self.addmsg('0011-19', 'parsing error', fn_compat) # compare package name match = RE_DEBIAN_CHANGELOG.match(content_changelog) if match: srcpkgname = match.group(1) else: srcpkgname = '' self.addmsg('0011-9', 'cannot determine source package name', fn_changelog) controlpkgname = parser.source_section.get('Source') if not controlpkgname: self.addmsg('0011-9', 'cannot determine source package name', fn_control) if srcpkgname and controlpkgname: if srcpkgname != controlpkgname: self.addmsg( '0011-2', 'source package name differs in debian/changelog and debian/control', fn_changelog) # parse source section of debian/control if not parser.source_section.get('Section', '') in ('univention'): self.addmsg('0011-3', 'wrong Section entry - should be "univention"', fn_control) if not parser.source_section.get('Priority', '') in ('optional'): self.addmsg('0011-4', 'wrong Priority entry - should be "optional"', fn_control) if not parser.source_section.get( 'Maintainer', '') in ('Univention GmbH <*****@*****.**>'): self.addmsg( '0011-5', 'wrong Maintainer entry - should be "Univention GmbH <*****@*****.**>"', fn_control) if parser.source_section.get('XS-Python-Version', ''): self.addmsg('0011-11', 'XS-Python-Version is not required any longer', fn_control) build_depends = dict( (m.group(1), m.groupdict()) for m in (RE_DEP.match(dep) for dep in (alt.strip() for dep in parser.source_section.get( 'Build-Depends', '').split(',') for alt in dep.split('|')) if dep) if m) if 'python-central' in build_depends: self.addmsg( '0011-12', 'please use python-support instead of python-central in Build-Depends', fn_control) if 'python-support' in build_depends: self.addmsg( '0011-17', 'please use dh-python instead of python-support in Build-Depends', fn_control) try: dep = build_depends['debhelper'] vstr = dep['vstr'] vint = int(vstr.split('.')[0]) if vstr else 0 except LookupError: pass except ValueError: self.addmsg('0011-10', 'failed parsing debhelper version', fn_control) else: if not compat_version: pass elif not vint: pass elif compat_version > vint: self.addmsg( '0011-20', 'debian/compat=%d > debian/control=%d disagree on the version for debhelper' % (compat_version, vint), fn_control) elif compat_version < vint: self.addmsg( '0011-20', 'debian/compat=%d < debian/control=%d disagree on the version for debhelper' % (compat_version, vint), fn_compat) else: pass self.check_debhelper(path, parser) try: fn_rules = os.path.join(path, 'debian', 'rules') with open(fn_rules, 'r') as fd: rules = fd.read() if re.search('--with[ =]*["\']?python_support', rules): self.addmsg( '0011-18', 'please use --with python2,python3 instead of python_support', fn_rules) except EnvironmentError: pass