示例#1
0
def get_readme_source (dsc_filename):
    tempdir = utils.temp_dirname()
    os.rmdir(tempdir)

    cmd = ('dpkg-source', '--no-check', '--no-copy', '-x', dsc_filename, tempdir)
    try:
        daklib.daksubprocess.check_output(cmd, stderr=1)
    except subprocess.CalledProcessError as e:
        res = "How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some\n old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?\n"
        res += "Error, couldn't extract source, WTF?\n"
        res += "'dpkg-source -x' failed. return code: %s.\n\n" % (e.returncode)
        res += e.output
        return res

    path = os.path.join(tempdir, 'debian/README.source')
    res = ""
    if os.path.exists(path):
        res += do_command(["cat", "--", path])
    else:
        res += "No README.source in this package\n\n"

    try:
        shutil.rmtree(tempdir)
    except OSError as e:
        if errno.errorcode[e.errno] != 'EACCES':
            res += "%s: couldn't remove tmp dir %s for source tree." % (dsc_filename, tempdir)

    return res
示例#2
0
def get_readme_source(dsc_filename):
    # TODO: py3: use tempfile.TemporaryDirectory
    tempdir = utils.temp_dirname()
    targetdir = os.path.join(tempdir, "source")

    cmd = ('dpkg-source', '--no-check', '--no-copy', '-x', dsc_filename,
           targetdir)
    try:
        daklib.daksubprocess.check_output(cmd, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as e:
        res = "How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some\n old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?\n"
        res += "Error, couldn't extract source, WTF?\n"
        res += "'dpkg-source -x' failed. return code: %s.\n\n" % (e.returncode)
        res += e.output
        return res

    path = os.path.join(targetdir, 'debian/README.source')
    res = ""
    if os.path.exists(path):
        with open(path, 'r') as fh:
            res += formatted_text(fh.read())
    else:
        res += "No README.source in this package\n\n"

    try:
        shutil.rmtree(tempdir)
    except OSError as e:
        if e.errno != errno.EACCES:
            res += "%s: couldn't remove tmp dir %s for source tree." % (
                dsc_filename, tempdir)

    return res
示例#3
0
def get_readme_source (dsc_filename):
    tempdir = utils.temp_dirname()
    os.rmdir(tempdir)

    cmd = "dpkg-source --no-check --no-copy -x %s %s" % (dsc_filename, tempdir)
    (result, output) = commands.getstatusoutput(cmd)
    if (result != 0):
        res = "How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some\n old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?\n"
        res += "Error, couldn't extract source, WTF?\n"
        res += "'dpkg-source -x' failed. return code: %s.\n\n" % (result)
        res += output
        return res

    path = os.path.join(tempdir, 'debian/README.source')
    res = ""
    if os.path.exists(path):
        res += do_command("cat", path)
    else:
        res += "No README.source in this package\n\n"

    try:
        shutil.rmtree(tempdir)
    except OSError as e:
        if errno.errorcode[e.errno] != 'EACCES':
            res += "%s: couldn't remove tmp dir %s for source tree." % (dsc_filename, tempdir)

    return res
示例#4
0
文件: archive.py 项目: abhi11/dak
    def prepare(self):
        """prepare upload for further processing

        This copies the files involved to a temporary directory.  If you use
        this method directly, you have to remove the directory given by the
        C{directory} attribute later on your own.

        Instead of using the method directly, you can also use a with-statement::

           with ArchiveUpload(...) as upload:
              ...

        This will automatically handle any required cleanup.
        """
        assert self.directory is None
        assert self.original_changes.valid_signature

        cnf = Config()
        session = self.transaction.session

        group = cnf.get('Dinstall::UnprivGroup') or None
        self.directory = utils.temp_dirname(parent=cnf.get('Dir::TempPath'),
                                            mode=0o2750, group=group)
        with FilesystemTransaction() as fs:
            src = os.path.join(self.original_directory, self.original_changes.filename)
            dst = os.path.join(self.directory, self.original_changes.filename)
            fs.copy(src, dst, mode=0o640)

            self.changes = upload.Changes(self.directory, self.original_changes.filename, self.keyrings)

            for f in self.changes.files.itervalues():
                src = os.path.join(self.original_directory, f.filename)
                dst = os.path.join(self.directory, f.filename)
                if not os.path.exists(src):
                    continue
                fs.copy(src, dst, mode=0o640)

            source = None
            try:
                source = self.changes.source
            except Exception:
                # Do not raise an exception here if the .dsc is invalid.
                pass

            if source is not None:
                for f in source.files.itervalues():
                    src = os.path.join(self.original_directory, f.filename)
                    dst = os.path.join(self.directory, f.filename)
                    if not os.path.exists(dst):
                        try:
                            db_file = self.transaction.get_file(f, source.dsc['Source'], check_hashes=False)
                            db_archive_file = session.query(ArchiveFile).filter_by(file=db_file).first()
                            fs.copy(db_archive_file.path, dst, mode=0o640)
                        except KeyError:
                            # Ignore if get_file could not find it. Upload will
                            # probably be rejected later.
                            pass
示例#5
0
文件: policy.py 项目: Debian/dak
    def __enter__(self):
        assert self.directory is None

        mode = 0o0700
        symlink = True
        if self.group is not None:
            mode = 0o2750
            symlink = False

        cnf = Config()
        self.directory = utils.temp_dirname(parent=cnf.get('Dir::TempPath'),
                                            mode=mode,
                                            group=self.group)
        self.export(self.directory, symlink=symlink)
        return self
示例#6
0
    def __enter__(self):
        assert self.directory is None

        mode = 0o0700
        symlink = True
        if self.group is not None:
            mode = 0o2750
            symlink = False

        cnf = Config()
        self.directory = utils.temp_dirname(parent=cnf.get('Dir::TempPath'),
                                            mode=mode,
                                            group=self.group)
        self.export(self.directory, symlink=symlink)
        return self