compress.py
1 """ 2 Compress module 3 """ 4 5 import os 6 7 8 class Compress: 9 """ 10 Base class for Compress instances. 11 """ 12 13 def pack(self, path, output): 14 """ 15 Compresses files in directory path to file output. 16 17 Args: 18 path: input directory path 19 output: output file 20 """ 21 22 raise NotImplementedError 23 24 def unpack(self, path, output): 25 """ 26 Extracts all files in path to output. 27 28 Args: 29 path: input file path 30 output: output directory 31 """ 32 33 raise NotImplementedError 34 35 def validate(self, directory, path): 36 """ 37 Validates path is under directory. 38 39 Args: 40 directory: base directory 41 path: path to validate 42 43 Returns: 44 True if path is under directory, False otherwise 45 """ 46 47 directory = os.path.abspath(directory) 48 path = os.path.abspath(path) 49 prefix = os.path.commonprefix([directory, path]) 50 51 return prefix == directory