Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /harvester/pandaharvester/harvestermisc/selfcheck.py was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 import errno
0002 import hashlib
0003 import json
0004 
0005 import psutil
0006 from pandaharvester.commit_timestamp import timestamp as commitTimestamp
0007 from pandaharvester.panda_pkg_info import release_version as releaseVersion
0008 
0009 
0010 class harvesterPackageInfo(object):
0011     """ """
0012 
0013     _attributes = ("commit_info", "version", "info_digest")
0014 
0015     def __init__(self, local_info_file):
0016         self.local_info_file = local_info_file
0017         self.commit_info = commitTimestamp
0018         self.version = releaseVersion
0019 
0020     @staticmethod
0021     def _get_hash(data):
0022         h = hashlib.md5()
0023         h.update(str(data).encode("utf-8"))
0024         return h.hexdigest()
0025 
0026     @property
0027     def info_digest(self):
0028         return self._get_hash(self.commit_info)
0029 
0030     @property
0031     def _local_info_dict(self):
0032         info_dict = {}
0033         try:
0034             with open(self.local_info_file, "r") as f:
0035                 info_dict = json.load(f)
0036         except IOError as e:
0037             if e.errno == errno.ENOENT:
0038                 pass
0039             else:
0040                 raise
0041         return info_dict
0042 
0043     def renew_local_info(self):
0044         info_dict = {}
0045         for attr in self._attributes:
0046             info_dict[attr] = getattr(self, attr)
0047         with open(self.local_info_file, "w") as f:
0048             json.dump(info_dict, f)
0049 
0050     @property
0051     def package_changed(self):
0052         return self.info_digest != self._local_info_dict.get("info_digest")