def determine_file_class_and_name(filename): """Determine the name and PackageUploadFile subclass for the filename.""" source_match = re_issource.match(filename) binary_match = re_isadeb.match(filename) buildinfo_match = re_isbuildinfo.match(filename) if source_match: package = source_match.group(1) if (determine_source_file_type(filename) == SourcePackageFileType.DSC): cls = DSCFile else: cls = SourceUploadFile elif binary_match: package = binary_match.group(1) cls = { BinaryPackageFileType.DEB: DebBinaryUploadFile, BinaryPackageFileType.DDEB: DdebBinaryUploadFile, BinaryPackageFileType.UDEB: UdebBinaryUploadFile, }[determine_binary_file_type(filename)] elif buildinfo_match: package = buildinfo_match.group(1) cls = BuildInfoFile else: raise CannotDetermineFileTypeError( "Could not determine the type of %r" % filename) return package, cls
def test_re_issource(self): # Verify that various source extensions match the regexp. extensions = ( 'dsc', 'tar.gz', 'tar.bz2', 'tar.xz', 'diff.gz', 'orig.tar.gz', 'orig.tar.bz2', 'orig.tar.xz', 'orig-bar.tar.gz', 'orig-bar.tar.bz2', 'orig-bar.tar.xz', 'orig-foo_bar.tar.gz', 'debian.tar.gz', 'debian.tar.bz2', 'debian.tar.xz') for extension in extensions: self.assertEquals( ('foo-bar', '1.0', extension), re_issource.match('foo-bar_1.0.%s' % extension).groups()) # While orig-*.tar.gz is all interpreted as extension, *orig-*.tar.gz # is taken to have an extension of just 'tar.gz'. self.assertEquals( ('foo-bar', '1.0.porig-bar', 'tar.gz'), re_issource.match('foo-bar_1.0.porig-bar.tar.gz').groups()) # Some other extension doesn't match. self.assertIs(None, re_issource.match('foo-bar_1.0.notdsc')) # A badly formatted name also doesn't match. self.assertIs(None, re_issource.match('foo-bar.dsc')) # bzip2/xz compression for files which must be gzipped is invalid. self.assertIs(None, re_issource.match('foo-bar_1.0.diff.bz2')) self.assertIs(None, re_issource.match('foo-bar_1.0.diff.xz'))
def test_re_issource(self): # Verify that various source extensions match the regexp. extensions = ( 'dsc', 'tar.gz', 'tar.bz2', 'tar.xz', 'diff.gz', 'orig.tar.gz', 'orig.tar.bz2', 'orig.tar.xz', 'orig-bar.tar.gz', 'orig-bar.tar.bz2', 'orig-bar.tar.xz', 'orig-foo_bar.tar.gz', 'debian.tar.gz', 'debian.tar.bz2', 'debian.tar.xz') for extension in extensions: self.assertEqual( ('foo-bar', '1.0', extension), re_issource.match('foo-bar_1.0.%s' % extension).groups()) # While orig-*.tar.gz is all interpreted as extension, *orig-*.tar.gz # is taken to have an extension of just 'tar.gz'. self.assertEqual( ('foo-bar', '1.0.porig-bar', 'tar.gz'), re_issource.match('foo-bar_1.0.porig-bar.tar.gz').groups()) # Some other extension doesn't match. self.assertIs(None, re_issource.match('foo-bar_1.0.notdsc')) # A badly formatted name also doesn't match. self.assertIs(None, re_issource.match('foo-bar.dsc')) # bzip2/xz compression for files which must be gzipped is invalid. self.assertIs(None, re_issource.match('foo-bar_1.0.diff.bz2')) self.assertIs(None, re_issource.match('foo-bar_1.0.diff.xz'))
def verify(self): """Verify the uploaded source file. It returns an iterator over all the encountered errors and warnings. """ self.logger.debug("Verifying source file %s" % self.filename) if 'source' not in self.changes.architectures: yield UploadError("%s: changes file doesn't list 'source' in " "Architecture field." % (self.filename)) version_chopped = re_no_epoch.sub('', self.version) if self.is_orig: version_chopped = re_no_revision.sub('', version_chopped) source_match = re_issource.match(self.filename) filename_version = source_match.group(2) if filename_version != version_chopped: yield UploadError("%s: should be %s according to changes file." % (filename_version, version_chopped))
def determine_file_class_and_name(filename): """Determine the name and PackageUploadFile subclass for the filename.""" source_match = re_issource.match(filename) binary_match = re_isadeb.match(filename) if source_match: package = source_match.group(1) if determine_source_file_type(filename) == SourcePackageFileType.DSC: cls = DSCFile else: cls = SourceUploadFile elif binary_match: package = binary_match.group(1) cls = { BinaryPackageFileType.DEB: DebBinaryUploadFile, BinaryPackageFileType.DDEB: DdebBinaryUploadFile, BinaryPackageFileType.UDEB: UdebBinaryUploadFile, }[determine_binary_file_type(filename)] else: raise CannotDetermineFileTypeError("Could not determine the type of %r" % filename) return package, cls
def verify(self): """Verify the uploaded .dsc file. This method is an error generator, i.e, it returns an iterator over all exceptions that are generated while processing DSC file checks. """ for error in SourceUploadFile.verify(self): yield error # Check size and checksum of the DSC file itself try: self.checkSizeAndCheckSum() except UploadError as error: yield error try: raw_files = parse_and_merge_file_lists(self._dict, changes=False) except UploadError as e: yield e return files = [] for attr in raw_files: filename, hashes, size = attr if not re_issource.match(filename): # DSC files only really hold on references to source # files; they are essentially a description of a source # package. Anything else is crack. yield UploadError("%s: File %s does not look sourceful." % (self.filename, filename)) continue filepath = os.path.join(self.dirname, filename) try: file_instance = DSCUploadedFile(filepath, hashes, size, self.policy, self.logger) except UploadError as error: yield error else: files.append(file_instance) self.files = files if not re_valid_pkg_name.match(self.source): yield UploadError("%s: invalid source name %s" % (self.filename, self.source)) if not re_valid_version.match(self.dsc_version): yield UploadError("%s: invalid version %s" % (self.filename, self.dsc_version)) if not self.policy.distroseries.isSourcePackageFormatPermitted( self.format): yield UploadError( "%s: format '%s' is not permitted in %s." % (self.filename, self.format, self.policy.distroseries.name)) # Validate the build dependencies for field_name in ['Build-Depends', 'Build-Depends-Indep']: field = self._dict.get(field_name, None) if field is not None: if field.startswith("ARRAY"): yield UploadError( "%s: invalid %s field produced by a broken version " "of dpkg-dev (1.10.11)" % (self.filename, field_name)) try: with warnings.catch_warnings(): warnings.simplefilter("error") PkgRelation.parse_relations(field) except Warning as error: yield UploadError( "%s: invalid %s field; cannot be parsed by deb822: %s" % (self.filename, field_name, error)) # Verify if version declared in changesfile is the same than that # in DSC (including epochs). if self.dsc_version != self.version: yield UploadError( "%s: version ('%s') in .dsc does not match version " "('%s') in .changes." % (self.filename, self.dsc_version, self.version)) for error in self.checkFiles(): yield error
def verify(self): """Verify the uploaded .dsc file. This method is an error generator, i.e, it returns an iterator over all exceptions that are generated while processing DSC file checks. """ for error in SourceUploadFile.verify(self): yield error # Check size and checksum of the DSC file itself try: self.checkSizeAndCheckSum() except UploadError as error: yield error try: raw_files = parse_and_merge_file_lists(self._dict, changes=False) except UploadError as e: yield e return files = [] for attr in raw_files: filename, hashes, size = attr if not re_issource.match(filename): # DSC files only really hold on references to source # files; they are essentially a description of a source # package. Anything else is crack. yield UploadError("%s: File %s does not look sourceful." % ( self.filename, filename)) continue filepath = os.path.join(self.dirname, filename) try: file_instance = DSCUploadedFile( filepath, hashes, size, self.policy, self.logger) except UploadError as error: yield error else: files.append(file_instance) self.files = files if not re_valid_pkg_name.match(self.source): yield UploadError( "%s: invalid source name %s" % (self.filename, self.source)) if not re_valid_version.match(self.dsc_version): yield UploadError( "%s: invalid version %s" % (self.filename, self.dsc_version)) if not self.policy.distroseries.isSourcePackageFormatPermitted( self.format): yield UploadError( "%s: format '%s' is not permitted in %s." % (self.filename, self.format, self.policy.distroseries.name)) # Validate the build dependencies for field_name in ['Build-Depends', 'Build-Depends-Indep']: field = self._dict.get(field_name, None) if field is not None: if field.startswith("ARRAY"): yield UploadError( "%s: invalid %s field produced by a broken version " "of dpkg-dev (1.10.11)" % (self.filename, field_name)) try: apt_pkg.parse_src_depends(field) except (SystemExit, KeyboardInterrupt): raise except Exception as error: # Swallow everything apt_pkg throws at us because # it is not desperately pythonic and can raise odd # or confusing exceptions at times and is out of # our control. yield UploadError( "%s: invalid %s field; cannot be parsed by apt: %s" % (self.filename, field_name, error)) # Verify if version declared in changesfile is the same than that # in DSC (including epochs). if self.dsc_version != self.version: yield UploadError( "%s: version ('%s') in .dsc does not match version " "('%s') in .changes." % (self.filename, self.dsc_version, self.version)) for error in self.checkFiles(): yield error