def lib_gen_pye(self, py_code, pye_filename, folder=None, keep_py=False, keep_pyc=False): """ folder = None -> use @_tmp_dir """ if not folder: folder = self.tmp_dir self.assertTrue(pye_filename.endswith('.pye')) filename = os.path.splitext(pye_filename)[0] py_filepath = join(folder, filename + '.py') pyc_filepath = join(folder, filename + '.pyc') pye_filepath = join(folder, filename + '.pye') # create .py with open(py_filepath, 'wb') as f: f.write(py_code) # create .pyc py_compile.compile(py_filepath) # create .pye & remove .py & .pyc import pyconcrete pyconcrete.encrypt_file(pyc_filepath, pye_filepath) # remove files if not keep_py: os.remove(py_filepath) if not keep_pyc: os.remove(pyc_filepath) return pye_filepath
def _compile_pye_file(self, args, py_file): """ if there is no .pyc file, compile .pyc first then compile .pye """ import pyconcrete pyc_file = py_file + 'c' pye_file = py_file + 'e' pyc_exists = exists(pyc_file) if not pyc_exists or os.stat(py_file).st_mtime != os.stat( pyc_file).st_mtime: py_compile.compile(py_file, cfile=pyc_file) if not exists(pye_file) or os.stat(py_file).st_mtime != os.stat( pye_file).st_mtime: pyconcrete.encrypt_file(pyc_file, pye_file) if args.verbose: print('* create %s' % pye_file) else: if args.verbose: print('* skip %s' % pye_file) # .pyc doesn't exists at beginning, remove it after .pye created if not pyc_exists or args.remove_pyc: os.remove(pyc_file) if args.remove_py: os.remove(py_file)
def lib_gen_pye(self, py_code, pye_filename, folder=None, keep_py=False, keep_pyc=False): """ folder = None -> use @_tmp_dir """ if not folder: folder = self.tmp_dir self.assertTrue(pye_filename.endswith('.pye')) filename = os.path.splitext(pye_filename)[0] py_filepath = join(folder, filename + '.py') pyc_filepath = join(folder, filename + '.pyc') pye_filepath = join(folder, filename + '.pye') # create .py with open(py_filepath, 'wb') as f: f.write(to_bytes(py_code)) # create .pyc py_compile.compile(py_filepath, cfile=pyc_filepath) # create .pye & remove .py & .pyc import pyconcrete pyconcrete.encrypt_file(pyc_filepath, pye_filepath) # remove files if not keep_py: os.remove(py_filepath) if not keep_pyc: os.remove(pyc_filepath) return pye_filepath
def __do_encrypt_decrypt_file(self, py_code): py_filepath = self.lib_gen_py(py_code, 'test.py') pye_filepath = py_filepath + 'e' import pyconcrete pyconcrete.encrypt_file(py_filepath, pye_filepath) with open(pye_filepath, 'rb') as f: data = f.read() return pyconcrete.decrypt_buffer(data)
def compile_pye_file(self, py_file): pyc_file = py_file + 'c' pye_file = py_file + 'e' pyc_exists = exists(pyc_file) if not pyc_exists or os.stat(py_file).st_mtime != os.stat( pyc_file).st_mtime: py_compile.compile(py_file) if not exists(pye_file) or os.stat(py_file).st_mtime != os.stat( pye_file).st_mtime: pyconcrete.encrypt_file(pyc_file, pye_file) if self.args.verbose: print '* create %s' % pye_file else: if self.args.verbose: print '* skip %s' % pye_file # .pyc doesn't exists at begining, remove it after .pye created if not pyc_exists or self.args.remove_pyc: os.remove(pyc_file) if self.args.remove_py: os.remove(py_file)