def setUp(self): self.truth_pyversion = (sys.version_info[0], sys.version_info[1], sys.version_info[2]) self.truth_pymajor = sys.version_info[0] self.truth_pyminor = sys.version_info[1] self.truth_pypatch = sys.version_info[2] self.truth_is_py2 = (self.truth_pymajor == (2)) self.truth_is_py3 = (self.truth_pymajor == (3)) self.test_pyversion = py_version() self.test_pymajor = py_major_version() self.test_pyminor = py_minor_version() self.test_pypatch = py_patch_version() self.test_is_py2 = is_py2() self.test_is_py3 = is_py3()
def __init__(self): now = datetime.datetime.now() self.py2 = py.is_py2() #truth test Python 2 interpreter self.py3 = py.is_py3() #truth test Python 3 interpreter self.py_major = py.py_major_version() #Python major version self.py_minor = py.py_minor_version() #Python minor version self.py_patch = py.py_patch_version() #Python patch version self.os = sys.platform #user operating system self.cwd = cwd() #current (present) working directory self.parent_dir = os.pardir self.default_path = os.defpath self.user_path = os.path.expanduser("~") self.string_encoding = sys.getdefaultencoding() self.file_encoding = sys.getfilesystemencoding() self.hour = now.hour self.min = now.minute self.year = now.year self.day = now.day self.month = now.month self.second = now.second
def decompress_gzip(gz_filename): """decompress gzip compressed file""" # decompress the gzip'd file f = gzip.open(gz_filename, 'rb') file_content = f.read() f.close() # monkeypatch for Python 3 byte string read issue if is_py3(): file_content = str(file_content) # get the base file name for the decompressed file write filename_split = gz_filename.split('.') if len(filename_split) == 2: basename = filename_split[0] elif len(filename_split) > 2: basename = filename_split[0] + '.' + filename_split[1] # concatenate first two parts of file name (e.g. example + '.' + 'tar' ) else: basename = gz_filename # write the file locally fw = FileWriter(basename) fw.write(file_content)