def test_find_on_path_present_executable(self):
     bin_dir = os.path.join(self.temp_dir, "bin")
     program = os.path.join(bin_dir, "program")
     touch(program)
     os.chmod(program, 0o755)
     os.environ["PATH"] = bin_dir
     self.assertTrue(osextras.find_on_path("program"))
 def test_find_on_path_present_not_executable(self):
     bin_dir = os.path.join(self.temp_dir, "bin")
     os.mkdir(bin_dir)
     program = os.path.join(bin_dir, "program")
     touch(program)
     with EnvironmentVarGuard() as env:
         env["PATH"] = bin_dir
         self.assertFalse(osextras.find_on_path("program"))
Exemple #3
0
 def test_pep8_clean(self):
     if not osextras.find_on_path("pep8"):
         return
     if "SKIP_SLOW_TESTS" in os.environ:
         return
     subp = subprocess.Popen(
         ["pep8"] + self.all_paths(),
         stdout=subprocess.PIPE, universal_newlines=True)
     output = subp.communicate()[0].splitlines()
     for line in output:
         print(line)
     self.assertEqual(0, len(output))
Exemple #4
0
    def publish_source(self, date):
        for i in count(1):
            in_prefix = "%s-src-%d" % (self.config.series, i)
            out_prefix = "%s-src-%d" % (self.config.series, i)
            source_dir = os.path.join(self.image_output, "src")
            source_prefix = os.path.join(source_dir, in_prefix)
            target_dir = os.path.join(self.publish_base, date, "source")
            target_prefix = os.path.join(target_dir, out_prefix)
            if not os.path.exists("%s.raw" % source_prefix):
                break

            logger.info("Publishing source %d ..." % i)
            osextras.ensuredir(target_dir)
            shutil.move("%s.raw" % source_prefix, "%s.iso" % target_prefix)
            shutil.move("%s.list" % source_prefix, "%s.list" % target_prefix)
            with ChecksumFileSet(
                self.config, target_dir, sign=False) as checksum_files:
                checksum_files.remove("%s.iso" % out_prefix)

            # Jigdo integration
            if os.path.exists("%s.jigdo" % source_prefix):
                logger.info("Publishing source %d jigdo ..." % i)
                shutil.move(
                    "%s.jigdo" % source_prefix, "%s.jigdo" % target_prefix)
                shutil.move(
                    "%s.template" % source_prefix,
                    "%s.template" % target_prefix)
            else:
                logger.warning("No jigdo for source %d!" % i)
                osextras.unlink_force("%s.jigdo" % target_prefix)
                osextras.unlink_force("%s.template" % target_prefix)

            # zsync metafiles
            if self.try_zsyncmake and osextras.find_on_path("zsyncmake"):
                logger.info("Making source %d zsync metafile ..." % i)
                osextras.unlink_force("%s.iso.zsync" % target_prefix)
                zsyncmake(
                    "%s.iso" % target_prefix, "%s.iso.zsync" % target_prefix,
                    "%s.iso" % out_prefix)

            yield os.path.join(
                self.project, self.image_type, "%s-src" % self.config.series)
Exemple #5
0
    def test_pyflakes_clean(self):
        if sys.version < "3":
            pyflakes = "pyflakes"
        else:
            pyflakes = "pyflakes3"
        if not osextras.find_on_path(pyflakes):
            return
        if "SKIP_SLOW_TESTS" in os.environ:
            return

        # Exclude handling based on run-pyflakes.py from reviewboard,
        # licensed under the MIT License.
        cur_dir = os.path.dirname(__file__)
        exclusions_path = os.path.join(cur_dir, "%s.exclude" % pyflakes)
        exclusions = set()
        if os.path.exists(exclusions_path):
            with open(exclusions_path, "r") as f:
                for line in f:
                    if not line.startswith("#"):
                        exclusions.add(line.rstrip())

        error = False
        subp = subprocess.Popen(
            [pyflakes] + self.all_paths(),
            stdout=subprocess.PIPE, universal_newlines=True)
        output = subp.communicate()[0].splitlines()
        for line in output:
            if line.startswith("#"):
                continue
            line = line.rstrip()
            canon_line = re.sub(r":[0-9]+:(?:[0-9]+)?", ":*:", line, 1)
            canon_line = re.sub(r"line [0-9]+", "line *", canon_line)
            if canon_line not in exclusions:
                print(line)
                error = True

        self.assertFalse(error)
 def test_find_on_path_missing_environment(self):
     with EnvironmentVarGuard() as env:
         env.pop("PATH", None)
         self.assertFalse(osextras.find_on_path("ls"))
 def test_find_on_path_present_not_executable(self):
     bin_dir = os.path.join(self.temp_dir, "bin")
     touch(os.path.join(bin_dir, "program"))
     os.environ["PATH"] = bin_dir
     self.assertFalse(osextras.find_on_path("program"))
 def test_find_on_path_missing_environment(self):
     os.environ.pop("PATH", None)
     self.assertFalse(osextras.find_on_path("ls"))
Exemple #9
0
    def publish_binary(self, publish_type, arch, date):
        in_prefix = "%s-%s-%s" % (self.config.series, publish_type, arch)
        out_prefix = "%s-%s-%s" % (self.config.series, publish_type, arch)
        source_dir = os.path.join(self.image_output, arch)
        source_prefix = os.path.join(source_dir, in_prefix)
        target_dir = os.path.join(self.publish_base, date)
        target_prefix = os.path.join(target_dir, out_prefix)

        if not os.path.exists("%s.raw" % source_prefix):
            logger.warning("No %s image for %s!" % (publish_type, arch))
            for name in osextras.listdir_force(target_dir):
                if name.startswith("%s." % out_prefix):
                    os.unlink(os.path.join(target_dir, name))
            return

        logger.info("Publishing %s ..." % arch)
        osextras.ensuredir(target_dir)
        extension = self.detect_image_extension(source_prefix)
        shutil.move(
            "%s.raw" % source_prefix, "%s.%s" % (target_prefix, extension))
        if os.path.exists("%s.list" % source_prefix):
            shutil.move("%s.list" % source_prefix, "%s.list" % target_prefix)
        self.checksum_dirs.append(source_dir)
        with ChecksumFileSet(
            self.config, target_dir, sign=False) as checksum_files:
            checksum_files.remove("%s.%s" % (out_prefix, extension))

        # Jigdo integration
        if os.path.exists("%s.jigdo" % source_prefix):
            logger.info("Publishing %s jigdo ..." % arch)
            shutil.move("%s.jigdo" % source_prefix, "%s.jigdo" % target_prefix)
            shutil.move(
                "%s.template" % source_prefix, "%s.template" % target_prefix)
            if self.jigdo_ports(arch):
                self.replace_jigdo_mirror(
                    "%s.jigdo" % target_prefix,
                    "http://archive.ubuntu.com/ubuntu",
                    "http://ports.ubuntu.com/ubuntu-ports")
        else:
            osextras.unlink_force("%s.jigdo" % target_prefix)
            osextras.unlink_force("%s.template" % target_prefix)

        # Live filesystem manifests
        if os.path.exists("%s.manifest" % source_prefix):
            logger.info("Publishing %s live manifest ..." % arch)
            shutil.move(
                "%s.manifest" % source_prefix, "%s.manifest" % target_prefix)
        else:
            osextras.unlink_force("%s.manifest" % target_prefix)

        if (self.config["CDIMAGE_SQUASHFS_BASE"] and
            os.path.exists("%s.squashfs" % source_prefix)):
            logger.info("Publishing %s squashfs ..." % arch)
            shutil.move(
                "%s.squashfs" % source_prefix, "%s.squashfs" % target_prefix)
        else:
            osextras.unlink_force("%s.squashfs" % target_prefix)

        # Flashable Android boot images
        if os.path.exists("%s.bootimg" % source_prefix):
            logger.info("Publishing %s abootimg bootloader images ..." % arch)
            shutil.move(
                "%s.bootimg" % source_prefix, "%s.bootimg" % target_prefix)

        # zsync metafiles
        if self.try_zsyncmake and osextras.find_on_path("zsyncmake"):
            logger.info("Making %s zsync metafile ..." % arch)
            osextras.unlink_force("%s.%s.zsync" % (target_prefix, extension))
            zsyncmake(
                "%s.%s" % (target_prefix, extension),
                "%s.%s.zsync" % (target_prefix, extension),
                "%s.%s" % (out_prefix, extension))

        size = os.stat("%s.%s" % (target_prefix, extension)).st_size
        if size > self.size_limit_extension(extension):
            with open("%s.OVERSIZED" % target_prefix, "a"):
                pass
        else:
            osextras.unlink_force("%s.OVERSIZED" % target_prefix)

        yield os.path.join(self.project, self.image_type_dir, in_prefix)