Пример #1
0
 def add_packages(self, connection, repository, packages):
     basedir = utils.get_path_from_url(repository.url)
     index_file = utils.get_path_from_url(
         self._get_url_of_metafile(repository, "Packages")
     )
     utils.ensure_dir_exist(os.path.dirname(index_file))
     index_gz = index_file + ".gz"
     count = 0
     # load existing packages
     self.get_packages(connection, repository, packages.add)
     with open(index_file, "wb") as fd1:
         with closing(gzip.open(index_gz, "wb")) as fd2:
             writer = utils.composite_writer(fd1, fd2)
             for pkg in packages:
                 filename = os.path.join(basedir, pkg.filename)
                 with closing(debfile.DebFile(filename)) as deb:
                     debcontrol = deb.debcontrol()
                 debcontrol.setdefault("Origin", repository.origin)
                 debcontrol["Size"] = str(pkg.filesize)
                 debcontrol["Filename"] = pkg.filename
                 for k, v in six.moves.zip(_CHECKSUM_METHODS, pkg.checksum):
                     debcontrol[k] = v
                 writer(debcontrol.dump())
                 writer("\n")
                 count += 1
     self.logger.info("saved %d packages in %s", count, repository)
     self._update_suite_index(repository)
 def add_packages(self, connection, repository, packages):
     basedir = utils.get_path_from_url(repository.url)
     index_file = utils.get_path_from_url(
         self._get_url_of_metafile(repository, "Packages"))
     utils.ensure_dir_exist(os.path.dirname(index_file))
     index_gz = index_file + ".gz"
     count = 0
     # load existing packages
     self.get_packages(connection, repository, packages.add)
     with open(index_file, "wb") as fd1:
         with closing(gzip.open(index_gz, "wb")) as fd2:
             writer = utils.composite_writer(fd1, fd2)
             for pkg in packages:
                 filename = os.path.join(basedir, pkg.filename)
                 with closing(debfile.DebFile(filename)) as deb:
                     debcontrol = deb.debcontrol()
                 debcontrol.setdefault("Origin", repository.origin)
                 debcontrol["Size"] = str(pkg.filesize)
                 debcontrol["Filename"] = pkg.filename
                 for k, v in six.moves.zip(_CHECKSUM_METHODS, pkg.checksum):
                     debcontrol[k] = v
                 writer(debcontrol.dump())
                 writer("\n")
                 count += 1
     self.logger.info("saved %d packages in %s", count, repository)
     self._update_suite_index(repository)
Пример #3
0
 def test_composite_writer(self):
     fds = [mock.MagicMock(), mock.MagicMock()]
     writer = utils.composite_writer(*fds)
     writer(u"text1")
     writer(b"text2")
     for fd in fds:
         fd.write.assert_any_call(b"text1")
         fd.write.assert_any_call(b"text2")
Пример #4
0
 def test_composite_writer(self):
     fds = [
         mock.MagicMock(),
         mock.MagicMock()
     ]
     writer = utils.composite_writer(*fds)
     writer(u"text1")
     writer(b"text2")
     for fd in fds:
         fd.write.assert_any_call(b"text1")
         fd.write.assert_any_call(b"text2")