예제 #1
0
    def testInsideDirectory(self):
        from irgsh.utils import find_debian

        os.makedirs(os.path.join(self.tmp, 'python-irgsh-0.5', 'debian'))

        res = find_debian(self.tmp)

        self.assertEqual(res, os.path.join(self.tmp, 'python-irgsh-0.5'))
예제 #2
0
    def testSingleDirectoryNoDebian(self):
        from irgsh.utils import find_debian

        os.makedirs(os.path.join(self.tmp, 'python-irgsh-0.5'))

        res = find_debian(self.tmp)

        self.assertEqual(res, None)
예제 #3
0
    def testInvalidDirectory(self):
        from irgsh.utils import find_debian

        tmp = os.path.join(self.tmp, 'invalid')

        res = find_debian(tmp)

        self.assertEqual(res, None)
예제 #4
0
    def testNormal(self):
        from irgsh.utils import find_debian

        os.makedirs(os.path.join(self.tmp, 'debian'))

        res = find_debian(self.tmp)

        self.assertEqual(res, self.tmp)
예제 #5
0
    def testMultipleDirectories(self):
        from irgsh.utils import find_debian

        os.makedirs(os.path.join(self.tmp, 'python-irgsh-0.1', 'debian'))
        os.makedirs(os.path.join(self.tmp, 'python-irgsh-0.5', 'debian'))

        res = find_debian(self.tmp)

        self.assertEqual(res, None)
예제 #6
0
    def testSingleFile(self):
        from irgsh.utils import find_debian

        fname = os.path.join(self.tmp, 'python-irgsh_0.5.orig.tar.gz')
        f = open(fname, 'wb')
        f.close()

        res = find_debian(self.tmp)

        self.assertEqual(res, None)
예제 #7
0
    def combine_tarball_orig(self, source, orig, extra_orig, target, logger=None):
        # Extract orig
        orig_path = self.extract_orig(orig, target, logger)
        self.extract_extra_orig(extra_orig, orig_path, logger)

        # Remove existing debian directory
        if os.path.exists(os.path.join(orig_path, 'debian')):
            shutil.rmtree(os.path.join(orig_path, 'debian'))

        # Copy all files inside source
        self.slog(logger, '# Combining source and orig file(s)')
        cmd = 'cp -a %s/* %s/' % (source.rstrip('/'), orig_path.rstrip('/'))
        p = Popen(cmd, shell=True, stdout=logger, stderr=STDOUT,
                  preexec_fn=os.setsid)
        p.communicate()

        return find_debian(orig_path)
예제 #8
0
    def testNoDebian(self):
        from irgsh.utils import find_debian

        res = find_debian(self.tmp)

        self.assertEqual(res, None)
예제 #9
0
    def prepare_source(self, target, logger=None):
        try:
            tmp = tempfile.mkdtemp('-irgsh-srcpkg-prepare')

            self.log.debug('Preparing source code directory')

            # Download and extract source
            source_path = os.path.join(tmp, 'source')
            os.makedirs(source_path)
            self.log.debug('Downloading source code, type: %s' % self.source_type)
            source = self.download_source(source_path, logger)
            self.log.debug('Source code downloaded')

            # Download orig
            orig = None
            orig_path = os.path.join(tmp, 'orig')
            os.makedirs(orig_path)
            if self.orig is not None:
                self.log.debug('Downloading original file')
                orig = self.download_orig(orig_path, logger)
                self.log.debug('Original file downloaded')

            # Download additional orig
            extra_orig = []
            if len(self.extra_orig) > 0:
                self.log.debug('Downloading additional original files')
                extra_orig = self.download_extra_orig(orig_path, logger)
                self.log.debug('additional original files downloaded')

            # Combine source and orig(s)
            combined_path = os.path.join(tmp, 'combine')
            os.makedirs(combined_path)
            self.log.debug('Combining source and orig, type: %s' % self.source_type)
            combined_path = self.combine(source, orig, extra_orig, combined_path, logger)
            self.log.debug('Source and orig combined')

            # Check for debian directory
            combined_path = find_debian(combined_path)
            if combined_path is None:
                raise ValueError, 'Unable to find debian directory'

            # Get version information
            package, version = get_package_version(combined_path)

            self.log.debug('Package: %s_%s' % (package, version))

            # Move source directory
            self.log.debug('Moving source code directory')

            final_path = os.path.join(target, '%s-%s' % (package, version))
            shutil.move(combined_path, final_path)

            # Move and rename orig file, if available
            if orig is not None:
                upstream = version.split('-')[0]
                fname, ext = os.path.splitext(self.orig)
                orig_path = os.path.join(target, '%s_%s.orig.tar%s' % \
                                                 (package, upstream, ext))
                shutil.move(orig, orig_path)

            # Move additional orig files
            for orig in extra_orig:
                shutil.move(orig, target)

            return package, version

        except Exception, e:
            raise SourcePackagePreparationError(e)