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
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)
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