def test_unicode_values(self): """Deb822 objects should contain only unicode values (Technically, they are allowed to contain any type of object, but when parsed from files, and when only string-type objects are added, the resulting object should have only unicode values.) """ objects = [] objects.append(deb822.Deb822(UNPARSED_PACKAGE)) objects.append(deb822.Deb822(CHANGES_FILE)) objects.extend(deb822.Deb822.iter_paragraphs(file('test_Packages'))) objects.extend(deb822.Packages.iter_paragraphs(file('test_Packages'))) objects.extend(deb822.Deb822.iter_paragraphs(file('test_Sources'))) objects.extend( deb822.Deb822.iter_paragraphs(file('test_Sources.iso8859-1'), encoding="iso8859-1")) for d in objects: for value in d.values(): self.assert_(isinstance(value, unicode)) # The same should be true for Sources and Changes except for their # _multivalued fields multi = [] multi.append(deb822.Changes(CHANGES_FILE)) multi.append( deb822.Changes(SIGNED_CHECKSUM_CHANGES_FILE % CHECKSUM_CHANGES_FILE)) multi.extend(deb822.Sources.iter_paragraphs(file('test_Sources'))) for d in multi: for key, value in d.items(): if key.lower() not in d.__class__._multivalued_fields: self.assert_(isinstance(value, unicode))
def remove_ddebs_from_changes(changes_file): with open(changes_file, 'r') as fp: changes = deb822.Changes(fp) for section in ('Checksums-Sha1', 'Checksums-Sha256', 'Files'): if section not in changes: continue new_section = [f for f in changes[section] if not f['name'].endswith('.ddeb')] changes[section] = new_section with open(changes_file, 'w') as fp: fp.write(changes.dump())
def execute(self, client, _opt, args): if len(args) != 2: print( "usage: elbe prjrepo upload_pkg <project_dir> <deb/dsc/changes file>", file=sys.stderr) sys.exit(20) builddir = args[0] filename = args[1] print("\n--------------------------") print("Upload and Include Package") print("--------------------------") print("Check files...") filetype = os.path.splitext(filename)[1] # Check filetype if filetype not in ['.dsc', '.deb', '.changes']: print( "Error: Only .dsc, .deb or .changes files allowed to upload.") sys.exit(20) files = [filename] # list of all files which will be uploaded # Parse .dsc-File and append neccessary source files to files if filetype == '.dsc': for f in deb822.Dsc(open(filename))['Files']: files.append(f['name']) if filetype == '.changes': for f in deb822.Changes(open(filename))['Files']: files.append(f['name']) # Check whether all files are available abort = False for f in files: if not os.path.isfile(f): print("File %s not found." % f) abort = True # Abort if one or more source files are missing if abort: sys.exit(20) print("Start uploading file(s)...") for f in files: print("Upload %s..." % f) self.upload_file(client, f, builddir) print("Including Package in initvm...") client.service.include_package(builddir, os.path.basename(filename))
def test_bug487902_multivalued_checksums(self): """New multivalued field Checksums was not handled correctly, see #487902.""" changesobj = deb822.Changes(CHECKSUM_CHANGES_FILE.splitlines()) self.assertEqual(CHECKSUM_CHANGES_FILE, changesobj.dump())
def test_bug457929_multivalued_dump_works(self): """dump() was not working in multivalued classes, see #457929.""" changesobj = deb822.Changes(CHANGES_FILE.splitlines()) self.assertEqual(CHANGES_FILE, changesobj.dump())