def parse_maintainer_bytes(content, fieldname): """Wrapper for parse_maintainer to handle both Unicode and bytestrings. It verifies the content type and transforms it to a unicode with guess(). Then we can safely call parse_maintainer(). """ if type(content) != unicode: content = guess_encoding(content) return parse_maintainer(content, fieldname)
def safe_fix_maintainer(content, fieldname): """Wrapper for fix_maintainer() to handle unicode and string argument. It verifies the content type and transform it in a unicode with guess() before call ascii_smash(). Then we can safely call fix_maintainer(). """ if type(content) != unicode: content = guess_encoding(content) content = ascii_smash(content) return fix_maintainer(content, fieldname)
def sanitize_string(s): """Make sure string does not trigger 'ascii' codec errors. Convert string to unicode if needed so that characters outside the (7-bit) ASCII range do not cause errors like these: 'ascii' codec can't decode byte 0xc4 in position 21: ordinal not in range(128) """ if isinstance(s, unicode): return s else: return guess_encoding(s)
def storeInDatabase(self, build): """Store DSC information as a SourcePackageRelease record. It reencodes all fields extracted from DSC, the simulated_changelog and the copyright, because old packages contain latin-1 text and that sucks. """ # Organize all the parameters requiring encoding transformation. pending = self._dict.copy() pending['simulated_changelog'] = self.changes.simulated_changelog pending['copyright'] = self.copyright # We have no way of knowing what encoding the original copyright # file is in, unfortunately, and there is no standard, so guess. encoded_raw_content = guess_encoding(self.raw_content) encoded = Deb822Dict() for key, value in pending.items(): if value is not None: encoded[key] = guess_encoding(value) else: encoded[key] = None # Lets upload the changelog file to librarian # We have to do this separately because we need the librarian file # alias id to embed in the SourceReleasePackage changelog_lfa = self.librarian.create( "changelog", len(self.changelog), StringIO(self.changelog), "text/x-debian-source-changelog", restricted=self.policy.archive.private) source_name = getUtility(ISourcePackageNameSet).getOrCreateByName( self.source) user_defined_fields = self.extractUserDefinedFields([ (field, encoded[field]) for field in self._dict.iterkeys() ]) if self.changes.buildinfo is not None: buildinfo_lfa = self.changes.buildinfo.storeInDatabase() else: buildinfo_lfa = None release = self.policy.distroseries.createUploadedSourcePackageRelease( sourcepackagename=source_name, version=self.dsc_version, maintainer=self.maintainer['person'], builddepends=encoded.get('Build-Depends', ''), builddependsindep=encoded.get('Build-Depends-Indep', ''), build_conflicts=encoded.get('Build-Conflicts', ''), build_conflicts_indep=encoded.get('Build-Conflicts-Indep', ''), architecturehintlist=encoded.get('Architecture', ''), creator=self.changes.changed_by['person'], urgency=self.changes.converted_urgency, homepage=encoded.get('Homepage'), dsc=encoded_raw_content, dscsigningkey=self.signingkey, dsc_maintainer_rfc822=encoded['Maintainer'], dsc_format=encoded['Format'], dsc_binaries=encoded['Binary'], dsc_standards_version=encoded.get('Standards-Version'), component=self.component, changelog=changelog_lfa, changelog_entry=encoded.get('simulated_changelog'), section=self.section, archive=self.policy.archive, source_package_recipe_build=build, copyright=encoded.get('copyright'), # dateuploaded by default is UTC:now in the database user_defined_fields=user_defined_fields, buildinfo=buildinfo_lfa, ) # SourcePackageFiles should contain also the DSC source_files = self.files + [self] for uploaded_file in source_files: library_file = self.librarian.create( uploaded_file.filename, uploaded_file.size, open(uploaded_file.filepath, "rb"), uploaded_file.content_type, restricted=self.policy.archive.private) release.addFile(library_file) return release
def storeInDatabase(self, build): """Store DSC information as a SourcePackageRelease record. It reencodes all fields extracted from DSC, the simulated_changelog and the copyright, because old packages contain latin-1 text and that sucks. """ # Organize all the parameters requiring encoding transformation. pending = self._dict.copy() pending['simulated_changelog'] = self.changes.simulated_changelog pending['copyright'] = self.copyright # We have no way of knowing what encoding the original copyright # file is in, unfortunately, and there is no standard, so guess. encoded_raw_content = guess_encoding(self.raw_content) encoded = Deb822Dict() for key, value in pending.items(): if value is not None: encoded[key] = guess_encoding(value) else: encoded[key] = None # Lets upload the changelog file to librarian # We have to do this separately because we need the librarian file # alias id to embed in the SourceReleasePackage changelog_lfa = self.librarian.create( "changelog", len(self.changelog), StringIO(self.changelog), "text/x-debian-source-changelog", restricted=self.policy.archive.private) source_name = getUtility( ISourcePackageNameSet).getOrCreateByName(self.source) user_defined_fields = self.extractUserDefinedFields([ (field, encoded[field]) for field in self._dict.iterkeys()]) release = self.policy.distroseries.createUploadedSourcePackageRelease( sourcepackagename=source_name, version=self.dsc_version, maintainer=self.maintainer['person'], builddepends=encoded.get('Build-Depends', ''), builddependsindep=encoded.get('Build-Depends-Indep', ''), build_conflicts=encoded.get('Build-Conflicts', ''), build_conflicts_indep=encoded.get('Build-Conflicts-Indep', ''), architecturehintlist=encoded.get('Architecture', ''), creator=self.changes.changed_by['person'], urgency=self.changes.converted_urgency, homepage=encoded.get('Homepage'), dsc=encoded_raw_content, dscsigningkey=self.signingkey, dsc_maintainer_rfc822=encoded['Maintainer'], dsc_format=encoded['Format'], dsc_binaries=encoded['Binary'], dsc_standards_version=encoded.get('Standards-Version'), component=self.component, changelog=changelog_lfa, changelog_entry=encoded.get('simulated_changelog'), section=self.section, archive=self.policy.archive, source_package_recipe_build=build, copyright=encoded.get('copyright'), # dateuploaded by default is UTC:now in the database user_defined_fields=user_defined_fields, ) # SourcePackageFiles should contain also the DSC source_files = self.files + [self] for uploaded_file in source_files: library_file = self.librarian.create( uploaded_file.filename, uploaded_file.size, open(uploaded_file.filepath, "rb"), uploaded_file.content_type, restricted=self.policy.archive.private) release.addFile(library_file) return release
def storeInDatabase(self, build): """Insert this binary release and build into the database.""" # Reencode everything we are supplying, because old packages # contain latin-1 text and that sucks. encoded = Deb822Dict() for key, value in self.control.items(): encoded[key] = guess_encoding(value) desclines = encoded['Description'].split("\n") summary = desclines[0] description = "\n".join(desclines[1:]) # XXX: dsilvers 2005-10-14 bug 3160: erm, need to work shlibdeps out. shlibdeps = "" is_essential = encoded.get('Essential', '').lower() == 'yes' architecturespecific = not self.is_archindep installedsize = int(self.control.get('Installed-Size', '0')) binary_name = getUtility(IBinaryPackageNameSet).getOrCreateByName( self.package) if self.ddeb_file: debug_package = build.getBinaryPackageFileByName( self.ddeb_file.filename).binarypackagerelease else: debug_package = None user_defined_fields = self.extractUserDefinedFields([ (field, encoded[field]) for field in self.control.iterkeys() ]) binary = build.createBinaryPackageRelease( binarypackagename=binary_name, version=self.control_version, summary=summary, description=description, binpackageformat=self.format, component=self.component, section=self.section, priority=self.priority, shlibdeps=shlibdeps, depends=encoded.get('Depends', ''), recommends=encoded.get('Recommends', ''), suggests=encoded.get('Suggests', ''), conflicts=encoded.get('Conflicts', ''), replaces=encoded.get('Replaces', ''), provides=encoded.get('Provides', ''), pre_depends=encoded.get('Pre-Depends', ''), enhances=encoded.get('Enhances', ''), breaks=encoded.get('Breaks', ''), homepage=encoded.get('Homepage'), essential=is_essential, installedsize=installedsize, architecturespecific=architecturespecific, user_defined_fields=user_defined_fields, debug_package=debug_package) library_file = self.librarian.create( self.filename, self.size, open(self.filepath, "rb"), self.content_type, restricted=self.policy.archive.private) binary.addFile(library_file) return binary
def storeInDatabase(self, build): """Insert this binary release and build into the database.""" # Reencode everything we are supplying, because old packages # contain latin-1 text and that sucks. encoded = Deb822Dict() for key, value in self.control.items(): encoded[key] = guess_encoding(value) desclines = encoded['Description'].split("\n") summary = desclines[0] description = "\n".join(desclines[1:]) # XXX: dsilvers 2005-10-14 bug 3160: erm, need to work shlibdeps out. shlibdeps = "" is_essential = encoded.get('Essential', '').lower() == 'yes' architecturespecific = not self.is_archindep installedsize = int(self.control.get('Installed-Size', '0')) binary_name = getUtility( IBinaryPackageNameSet).getOrCreateByName(self.package) if self.ddeb_file: debug_package = build.getBinaryPackageFileByName( self.ddeb_file.filename).binarypackagerelease else: debug_package = None user_defined_fields = self.extractUserDefinedFields( [(field, encoded[field]) for field in self.control.iterkeys()]) binary = build.createBinaryPackageRelease( binarypackagename=binary_name, version=self.control_version, summary=summary, description=description, binpackageformat=self.format, component=self.component, section=self.section, priority=self.priority, shlibdeps=shlibdeps, depends=encoded.get('Depends', ''), recommends=encoded.get('Recommends', ''), suggests=encoded.get('Suggests', ''), conflicts=encoded.get('Conflicts', ''), replaces=encoded.get('Replaces', ''), provides=encoded.get('Provides', ''), pre_depends=encoded.get('Pre-Depends', ''), enhances=encoded.get('Enhances', ''), breaks=encoded.get('Breaks', ''), homepage=encoded.get('Homepage'), essential=is_essential, installedsize=installedsize, architecturespecific=architecturespecific, user_defined_fields=user_defined_fields, debug_package=debug_package) library_file = self.librarian.create(self.filename, self.size, open(self.filepath, "rb"), self.content_type, restricted=self.policy.archive.private) binary.addFile(library_file) return binary