Exemplo n.º 1
0
def sanity_check() -> int:
    """Sanity check the E3 install."""
    errors = 0
    print("YAMLCheck:", end=" ")
    try:
        import yaml

        yaml.safe_dump({"Yaml": "works"})
        print("PASSED")
    except Exception:  # defensive code
        print("FAILED")
        errors += 1

    print("HashlibCheck:", end=" ")
    try:
        from e3.hash import sha1, md5

        sha1(__file__)
        md5(__file__)
        print("PASSED")
    except Exception:  # defensive code
        print("FAILED")
        errors += 1

    print("Version:", end=" ")
    try:
        print(version())
    except Exception:  # defensive code
        errors += 1
    return errors
Exemplo n.º 2
0
def sanity_check():
    """Sanity check the E3 install."""
    errors = 0
    print('YAMLCheck:', end=' ')
    try:
        import yaml
        yaml.dump({'Yaml': 'works'})
        print('PASSED')
    except Exception:
        print('FAILED')
        errors += 1

    print('HashlibCheck:', end=' ')
    try:
        from e3.hash import sha1, md5
        sha1(__file__)
        md5(__file__)
        print('PASSED')
    except Exception:
        print('FAILED')
        errors += 1

    print('Version:', end=' ')
    try:
        print(version())
    except Exception:
        errors += 1
    return errors
def sanity_check():
    """Sanity check the E3 install."""
    errors = 0
    sys.stdout.write('YAMLCheck: ')
    try:
        import yaml
        yaml.dump({'Yaml': 'works'})
        sys.stdout.write('PASSED\n')
    except Exception:
        sys.stdout.write('FAILED\n')
        errors += 1

    sys.stdout.write('HashlibCheck: ')
    try:
        from e3.hash import sha1, md5
        sha1(__file__)
        md5(__file__)
        sys.stdout.write('PASSED\n')
    except Exception:
        sys.stdout.write('FAILED\n')
        errors += 1

    try:
        revision = version()
        major, num, git_rev = revision.split('-')
        sys.stdout.write('MajorVersion: %s\n' % major)
        sys.stdout.write('ChangeNumber: %s\n' % num)
    except Exception:
        sys.stdout.write('MajorVersion: FAILED\n')
        sys.stdout.write('ChangeNumber: FAILED\n')
    return errors
Exemplo n.º 4
0
def sanity_check():
    """Sanity check the E3 install."""
    errors = 0
    print('YAMLCheck:', end=' ')
    try:
        import yaml
        yaml.dump({'Yaml': 'works'})
        print('PASSED')
    except Exception:  # defensive code
        print('FAILED')
        errors += 1

    print('HashlibCheck:', end=' ')
    try:
        from e3.hash import sha1, md5
        sha1(__file__)
        md5(__file__)
        print('PASSED')
    except Exception:  # defensive code
        print('FAILED')
        errors += 1

    print('Version:', end=' ')
    try:
        print(version())
    except Exception:  # defensive code
        errors += 1
    return errors
Exemplo n.º 5
0
    def run(self):
        builder = self.data.builder
        cache_dir = self.sandbox.tmp_cache_dir

        skip = False
        if os.path.isfile(os.path.join(
                cache_dir, builder.filename)) and os.path.isfile(
                    os.path.join(cache_dir, builder.filename + ".sha1")):
            with open(os.path.join(cache_dir, builder.filename + ".sha1"),
                      "rb") as f:
                checksum = f.read(1024).decode()
            skip = checksum == hash.sha1(
                os.path.join(cache_dir, builder.filename))

        if skip:
            self.run_status = ReturnValue.skip
        else:
            if builder.url.startswith("https://") or builder.url.startswith(
                    "http://"):

                if os.path.isfile(os.path.join(cache_dir, builder.filename)):
                    rm(os.path.join(cache_dir, builder.filename))
                if os.path.isfile(
                        os.path.join(cache_dir, builder.filename + ".sha1")):
                    rm(os.path.join(cache_dir, builder.filename + ".sha1"))

                s = HTTPSession(base_urls=[builder.base_url])
                result = s.download_file(url=builder.filename,
                                         dest=cache_dir,
                                         filename=builder.name)
                if result is None:
                    rm(os.path.join(cache_dir, builder.filename))
                    self.run_status = ReturnValue.failure
                else:
                    self.run_status = ReturnValue.success
                    with open(
                            os.path.join(cache_dir,
                                         builder.filename + ".sha1"),
                            "w") as f:
                        f.write(
                            hash.sha1(os.path.join(cache_dir,
                                                   builder.filename)))
            else:
                cp(
                    os.path.join(self.sandbox.specs_dir, "patches",
                                 builder.url),
                    cache_dir,
                )
                self.run_status = ReturnValue.success
Exemplo n.º 6
0
    def add_file(self, filename):
        """Add a file element to the fingerprint.

        :param filename: a path
        :type filename: str

        Adding a filename element to a fingerprint is equivalent to do add
        an element for which key is the basename of the file and value is
        is the sha1 of the content
        """
        assert os.path.isfile(filename), \
            'filename %s does not exist' % filename
        self.elements[os.path.basename(filename)] = sha1(filename)
Exemplo n.º 7
0
    def add_file(self, filename):
        """Add a file element to the fingerprint.

        :param filename: a path
        :type filename: str

        Adding a filename element to a fingerprint is equivalent to do add
        an element for which key is the basename of the file and value is
        is the sha1 of the content
        """
        assert os.path.isfile(filename), \
            'filename %s does not exist' % filename
        self.elements[os.path.basename(filename)] = sha1(filename)
Exemplo n.º 8
0
    def load_fingerprint(self, kind, sha1_only=False):
        """Load the content of the fingerprint from disc.

        :param kind: the primitive name
        :type kind: str
        :param sha1_only: if true returns only the checksum of the
            fingerprint file
        :type sha1_only: bool

        :return: if sha1_only is True, returns a sha1 hexdigest else returns
            a Fingerprint object (the content of the fingerprint file or an
            empty Fingerprint when the fingerprint is invalid or does not
            exist)
        :rtype: str | Fingerprint
        """
        fingerprint_file = os.path.join(self.meta_dir,
                                        kind + '_fingerprint.yaml')
        if sha1_only:
            return sha1(fingerprint_file)

        result = None
        if os.path.exists(fingerprint_file):
            with open(fingerprint_file) as f:
                try:
                    result = yaml.load(f)
                except (ParserError, ReaderError) as e:
                    logger.warning(e)
                    # Invalid fingerprint
                    logger.warning('invalid fingerprint, discard it')
                    result = None

        if not isinstance(result, Fingerprint):
            # The fingerprint file did not exist or was invalid
            # returns an empty fingerprint
            result = Fingerprint()
        return result
Exemplo n.º 9
0
    def load_fingerprint(self, kind, sha1_only=False):
        """Load the content of the fingerprint from disc.

        :param kind: the primitive name
        :type kind: str
        :param sha1_only: if true returns only the checksum of the
            fingerprint file
        :type sha1_only: bool

        :return: if sha1_only is True, returns a sha1 hexdigest else returns
            a Fingerprint object (the content of the fingerprint file or an
            empty Fingerprint when the fingerprint is invalid or does not
            exist)
        :rtype: str | Fingerprint
        """
        fingerprint_file = os.path.join(
            self.meta_dir, kind + '_fingerprint.yaml')
        if sha1_only:
            return sha1(fingerprint_file)

        result = None
        if os.path.exists(fingerprint_file):
            with open(fingerprint_file) as f:
                try:
                    result = yaml.load(f)
                except ReaderError as e:
                    logger.warning(e)
                    # Invalid fingerprint
                    logger.warning('invalid fingerprint, discard it')
                    result = None

        if not isinstance(result, Fingerprint):
            # The fingerprint file did not exist or was invalid
            # returns an empty fingerprint
            result = Fingerprint()
        return result