def clear_dll_directory(): """ Push current Dll Directory. There are two cases that can happen related to setting a dll directory: 1: Project is using different python then Desktop, in which case the desktop will set the dll directory to none for the project's python interpreter. In this case, the following code is redundant and not needed. 2: Desktop is using same python as Project. In which case we need to keep the desktop dll directory. """ dll_directory = None if sgtk.util.is_windows(): # This 'try' block will fail silently if user is using # a different python interpreter then Desktop, in which # case it will be fine since the Desktop will have set # the correct Dll folder for this interpreter. Refer to # the comments in the method's header for more information. try: import win32api # GetDLLDirectory throws an exception if none was set try: dll_directory = win32api.GetDllDirectory(None) except Exception: dll_directory = None win32api.SetDllDirectory(None) except Exception: pass return dll_directory
def _clear_dll_directory(self): """ Push current Dll Directory There are two cases that can happen related to setting a dll directory. 1: Project is using different python then Desktop, in which case the desktop will set the dll directory to none for the project's python interpreter. In this case, the following code is redundant and not needed. 2: Desktop is using same python as Project. In which case we need to keep the desktop dll directory. """ if sys.platform == "win32": # This 'try' block will fail silently if user is using a different python interpreter then Desktop, # in which case it will be fine since the Desktop will have set the correct Dll folder for this # interpreter. Refer to the comments in the method's header for more information. try: import win32api # GetDLLDirectory throws an exception if none was set try: self._previous_dll_directory = win32api.GetDllDirectory( None) except StandardError: self._previous_dll_directory = None win32api.SetDllDirectory(None) except StandardError: pass
def _restore_dll_directory(self): """ Pop the previously pushed DLL Directory """ if sys.platform == "win32": # This may fail silently, which is the correct behavior. Refer to the comments in # _clear_dll_directory for additional information. try: import win32api win32api.SetDllDirectory(self._previous_dll_directory) except StandardError: pass
def _pop_dll_state(self): ''' Pop the previously pushed DLL Directory ''' if sys.platform == "win32": try: import win32api win32api.SetDllDirectory(self._previous_dll_directory) except StandardError: engine = sgtk.platform.current_engine() engine.log_warning( 'Could not restore DllDirectory under Windows.')
def _MainLoadDll(opts): """Main entry point for this script when executed with --load-dll. Args: opts: the parsed and validated arguments. Returns: 0 on success, a non-zero value on failure. """ # Put the build directory in the search path so we find export_dll.dll and # the various instrumentation binaries. win32api.SetDllDirectory(opts.build_dir) if _LoadDll(opts.instrumented_dll): return 0 return 1
def restore_dll_directory(dll_directory): """ Pop the previously pushed DLL Directory :param dll_directory: The previously pushed DLL directory """ if sgtk.util.is_windows(): # This may fail silently, which is the correct behavior. # Refer to the comments in _clear_dll_directory() for # additional information. try: import win32api win32api.SetDllDirectory(dll_directory) except Exception: pass
def _load_library(self): """Return the fortran library, loaded with """ path = self._library_path() logger.info("Loading library from path {}".format(path)) library_dir = os.path.dirname(path) if platform.system() == 'Windows': import win32api olddir = os.getcwd() os.chdir(library_dir) win32api.SetDllDirectory('.') result = cdll.LoadLibrary(path) if platform.system() == 'Windows': os.chdir(olddir) return result
def load_library(path): """Return the native library, loaded with """ library_dir = os.path.dirname(path) library_path = os.path.abspath(path) if platform.system() == 'Windows': olddir = os.getcwd() os.chdir(library_dir) import win32api win32api.SetDllDirectory('.') result = cdll.LoadLibrary(library_path) if platform.system() == 'Windows': os.chdir(olddir) return result
def _push_dll_state(self): ''' Push current Dll Directory ''' if sys.platform == "win32": try: import win32api # GetDLLDirectory throws an exception if none was set try: self._previous_dll_directory = win32api.GetDllDirectory( None) except StandardError: self._previous_dll_directory = None win32api.SetDllDirectory(None) except StandardError: engine = sgtk.platform.current_engine() engine.log_warning( 'Could not push DllDirectory under Windows.')
def _MainLoadImage(opts): """Main entry point for this script when executed with --load-image. Args: opts: the parsed and validated arguments. Returns: 0 on success, a non-zero value on failure. """ # Put the build directory in the search path so we find export_dll.dll and # the various instrumentation binaries. win32api.SetDllDirectory(opts.build_dir) ext = os.path.splitext(opts.instrumented_image)[1] if ext.lower() == '.dll': if _LoadDll(opts.instrumented_image): return 0 else: if _RunImage(opts.instrumented_image): return 0 return 1
% '\n'.join(searched)) else: log.info("Found 'libleveldb.so' in %s" % pth) else: pth = os.path.dirname(os.path.abspath(__file__)) _ldb = ctypes.CDLL(os.path.join(pth, 'libleveldb.so')) elif plat == 'darwin': # since on OSX the program is bundled in a .app archive, shall we use the same (or approching) thecnique as for Linux? _ldb = ctypes.CDLL( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'libleveldb.dylib')) elif plat == 'win32': if getattr(sys, '_MEIPASS', False): import win32api win32api.SetDllDirectory(sys._MEIPASS) DLL_NAME = 'LevelDB-MCPE-32bit.dll' if platform.architecture()[0] == '64bit' or sys.maxsize > 2**32: DLL_NAME = 'LevelDB-MCPE-64bit.dll' # _ldb = ctypes.CDLL(os.path.join(os.path.dirname(os.path.abspath(__file__)), "LevelDB-MCPE.dll")) _ldb = ctypes.CDLL(str(directories.getDataFile('pymclevel', DLL_NAME))) log.debug("Binary support v%s.%s for PE 1+ world succesfully loaded." % (_ldb.leveldb_major_version(), _ldb.leveldb_minor_version())) except Exception as e: # What shall we do if the library is not found? # If the library is not loaded, the _ldb object does not exists, and every call to it will crash MCEdit... # We may import this module using try/except statement. log.error("The binary support for PE 1+ worlds could not be loaded:") log.error(e) raise e
# p = Process(target=global_create_user, args=(i,)) # self.__dict_total_user_process,)) # 创建user独立进程 # # self.__dict_total_user_process[i['userid']].append(p) # user独立进程 # p.start() # 开始进程 if __name__ == '__main__': multiprocessing.freeze_support() frozen = 'not' if getattr(sys, 'frozen', False): # we are running in a bundle frozen = 'ever so' bundle_dir = sys._MEIPASS else: # we are running in a normal Python environment bundle_dir = os.path.dirname(os.path.abspath(__file__)) win32api.SetDllDirectory(bundle_dir) sys.path.append(bundle_dir) # 删除log文件夹,创建log文件夹 if os.path.exists('log'): pass # 已存在文件夹,什么都不用操作 # print("ClientMin.'__main__' log文件夹存在,删除重建log文件夹") # shutil.rmtree('log') else: # print("ClientMin.'__main__' log文件夹不存在,创建log文件夹") os.mkdir('log') # print全部存到log本地文件 time_str = datetime.datetime.now().strftime('%Y%m%d %H%M%S') file_path_error = 'log/error_' + time_str + '.log' stderr_handler = open(file_path_error, 'w')
DWORD SGFPM_WriteData(HSGFPM hFpm, unsigned char index, unsigned char data); """) # noqa try: import sys # PyInstaller creates a temp folder and stores path in _MEIPASS base_path = sys._MEIPASS current_dirname = os.path.join(base_path, "secugen") except Exception: current_dirname = os.path.dirname(os.path.abspath(__file__)) try: import win32api win32api.SetDllDirectory(current_dirname) except: # noqa pass platform_name = platform.system().lower() def get_libraries(config): if platform_name == "linux": ffi.dlopen("libstdc++.so.6", ffi.RTLD_GLOBAL) ffi.dlopen("libusb-0.1.so.4", ffi.RTLD_GLOBAL) ffi.dlopen(config['LIBSGFDU03'], ffi.RTLD_GLOBAL) ffi.dlopen(config['LIBSGFPAMX'], ffi.RTLD_GLOBAL) sgfplib = ffi.dlopen(config['LIBSGFPLIB']) elif platform_name == "darwin":
if arch_id == "64bit": sys.path.append('/usr/lib64/python3.6/site-packages') sys.path.append('/usr/lib/python3.6/site-packages') else: pass if getattr(sys, 'frozen', False): application_path = os.path.dirname(sys.executable) else: application_path = os.path.dirname(os.path.abspath(__file__)) if sys.platform == 'darwin': application_path = os.path.dirname(application_path) application_path = os.path.join(application_path, 'Frameworks') sys.path.append(application_path) os.environ['PATH'] = application_path + os.pathsep + os.environ.get('PATH', '') os.environ['PYTHONPATH'] = \ application_path + os.pathsep + os.environ.get('PYTHONPATH', '') if os.name == 'nt': import win32api win32api.SetDllDirectory(application_path) try: from PySide2.QtCore import QCoreApplication QCoreApplication.addLibraryPath(application_path) except: pass