def find_gpg(): path = which('gpg') if path == None: if get_os() == 'Windows': paths = ['c:\program files\gnu\gnupg\gpg.exe','c:\program files(x86)\gnu\gnupg\gpg.exe'] for path in paths: if os.path.isfile(path): return path # If we get here then no such file exists - use our packaged version if it is present path = os.path.join(resource_path('binaries'),'gpg.exe') elif get_os() == 'Darwin': paths = ['/usr/local/bin/gpg'] #,'/usr/local/MacGPG2/bin/gpg2'] # gpg2 shipping with macpgp is not compatible - need gpg (v1) for path in paths: if os.path.isfile(path): return path # If we get here then no such file exists - use our packaged version if it is present path = os.path.join(resource_path('binaries'),'gpg') print "Info: Could not find GPG on the system - seeing if Axis Mundi bundled GPG in " + path if os.path.isfile(path): return path else: print "Error: Could not find GPG on the system - impossible to continue" return None else: return path
def check_prereqs(): ''' Validate environment & dependencies exist for script ''' error_count = 0 print("Checking script environment...") compatible_os = regex(r'Windows') if not compatible_os.match(get_os()): eprint( "FAILED: This script only works on Windows with administrator privileges." ) error_count -= 1 else: try: # Check running as administrator (only Administrator rights can see the temp dir) ls(p.join(ossep, 'Windows', 'temp')) except PermissionError: eprint( '\n' + "FAILED: Script needs to be run with administrator privileges." ) eprint( "PowerShell w/ Admin Privalages command: \n\t Start-Process powershell -Verb RunAs" ) error_count -= 1 # TODO: check for required cygwin_pubring.asc public key file # VALID Environment if error_count != 0: return (error_count) else: print("PASS") return (0)
def InitDB(self, passphrase, dbfilepath): #engine = create_engine('sqlite+pysqlcipher://:PASSPHRASE@/storage.db?cipher=aes-256-cfb&kdf_iter=64000') # This next one works although a numeric passphrase must be given # self.engine = create_engine('sqlite+pysqlcipher://:' + passphrase + '/' + dbfilepath) print "Info: Initializing database " + dbfilepath # DATABASE ENCRYPTION CAN BE DISABLED/ENABLED HERE if get_os() == 'Windows': self.engine = create_engine( r'sqlite+pysqlcipher://:'+passphrase+'@/' + dbfilepath, connect_args={'check_same_thread': False}) # Encrypted database # TESTING ONLY - THIS CREATES A CLEAR-TEXT STORAGE DATABASE! # r'sqlite:///' + dbfilepath, connect_args={'check_same_thread': False}) # Cleartext database (testing) # poolclass=StaticPool else: self.engine = create_engine( 'sqlite+pysqlcipher://:'+passphrase+'@//' + dbfilepath, connect_args={'check_same_thread': False}) # Encrypted database # TESTING ONLY - THIS CREATES A CLEAR-TEXT STORAGE DATABASE! # 'sqlite:////' + dbfilepath, connect_args={'check_same_thread': False}) # Cleartext database (testing) # poolclass=StaticPool try: self.Base.metadata.create_all(self.engine) except: print "ERROR: Error creating database" return False self.Base.metadata.bind = self.engine self.DBSession = sessionmaker(bind=self.engine) return True
def __init__(self, mypgpkeyid, pgppassphrase, pgp_dir, app_dir, gpg_binary): self.mypgpkeyid = mypgpkeyid if get_os() == 'Windows': keyring = app_dir + '\pubkeys.gpg' # TODO - account for filenames with spaces on windows else: keyring = app_dir + '/pubkeys.gpg' if os.path.dirname(gpg_binary) == resource_path('binaries'): gpg_exec_dir = '--exec-path ' + resource_path( 'binaries' ) # We are using the gpg binaries shipped with the Axis Mundi executable, make sure we set the helpers path self.gpg = gnupg.GPG( gpgbinary=gpg_binary, gnupghome=pgp_dir, options={ gpg_exec_dir, '--primary-keyring=' + keyring, '--no-emit-version', '--keyserver=hkp://127.0.0.1:5000', '--keyserver-options=auto-key-retrieve=yes,http-proxy=', '--primary-keyring="' + keyring + '"' }) # removed '--auto-key-locate=keyserver', else: self.gpg = gnupg.GPG( gpgbinary=gpg_binary, gnupghome=pgp_dir, options={ '--primary-keyring=' + keyring, '--no-emit-version', '--keyserver=hkp://127.0.0.1:5000', '--keyserver-options=auto-key-retrieve=yes,http-proxy=', '--primary-keyring="' + keyring + '"' }) # removed '--auto-key-locate=keyserver', self.pgp_passphrase = pgppassphrase
def start(self): if get_os() == 'Windows': signal.signal(signal.SIGINT, self.SIGUSR1_handler) else: signal.signal(signal.SIGUSR1,self.SIGUSR1_handler) self.app.go()
def __init__(self, parent, font=("TkHeadingFont", 10), text=None, state="normal"): tk.Text.__init__(self, parent, font=font, state=state, spacing1=2, spacing2=2, undo=True) if text is not None: self.insert(1.0, text) self.yview_moveto(1) self.rc_popup_menu = tk.Menu(self, tearoff=0) self.rc_popup_menu.add_command(label="Select all (Ctrl-a)", command=self.select_all) self.rc_popup_menu.add_separator() self.rc_popup_menu.add_command(label="Cut (Ctrl-x)", command=self.cut) self.rc_popup_menu.add_separator() self.rc_popup_menu.add_command(label="Copy (Ctrl-c)", command=self.copy) self.rc_popup_menu.add_separator() self.rc_popup_menu.add_command(label="Paste (Ctrl-v)", command=self.paste) self.bind("<1>", lambda event: self.focus_set()) if str(get_os()) == "Darwin": self.bind("<2>", self.rc) else: self.bind("<3>", self.rc)
def InitDB(self, passphrase, dbfilepath): #engine = create_engine('sqlite+pysqlcipher://:PASSPHRASE@/storage.db?cipher=aes-256-cfb&kdf_iter=64000') # This next one works although a numeric passphrase must be given # self.engine = create_engine('sqlite+pysqlcipher://:' + passphrase + '/' + dbfilepath) print dbfilepath if get_os() == 'Windows': # TESTING ONLY - THIS CREATES A CLEAR-TEXT STORAGE DATABASE! self.engine = create_engine( r'sqlite:///' + dbfilepath, connect_args={'check_same_thread': False}) # poolclass=StaticPool else: # TESTING ONLY - THIS CREATES A CLEAR-TEXT STORAGE DATABASE! self.engine = create_engine( 'sqlite:////' + dbfilepath, connect_args={'check_same_thread': False}) # poolclass=StaticPool try: self.Base.metadata.create_all(self.engine) except: print "Error creating database" return False self.Base.metadata.bind = self.engine self.DBSession = sessionmaker(bind=self.engine) return True
def __init__(self, mypgpkeyid, pgppassphrase, pgp_dir, app_dir): self.mypgpkeyid = mypgpkeyid if get_os() == 'Windows': keyring = app_dir + '\pubkeys.gpg' # TODO - account for filenames with spaces on windows else: keyring = app_dir + '/pubkeys.gpg' self.gpg = gnupg.GPG(gnupghome=pgp_dir, options={'--primary-keyring=' + keyring,'--no-emit-version', '--keyserver=hkp://127.0.0.1:5000', '--keyserver-options=auto-key-retrieve=yes,http-proxy=', '--primary-keyring="' + keyring + '"'}) # removed '--auto-key-locate=keyserver', self.pgp_passphrase = pgppassphrase
def __init__(self, *args, load_images=True, **kwargs): super().__init__(*args, load_images=load_images, **kwargs) options = ChromeOptions() if 'Windows' == get_os(): options.binary_location = HEADLESS_CHROME_PATH options.add_argument('no-sandbox') options.add_argument('headless') options.add_argument('disable-gpu') if not load_images: options.add_argument('disable-images') self.options = options
def __init__(self, settings): super().__init__(settings) self.executable_path = settings['CHROME_EXECUTABLE_PATH'] self.dcap = DesiredCapabilities.CHROME.copy() options = ChromeOptions() if 'Windows' == get_os(): options.binary_location = settings["HEADLESS_CHROME_PATH"] options.add_argument('no-sandbox') options.add_argument('headless') options.add_argument('disable-gpu') if not settings.get("CHROME_LOAD_IMAGES", False): options.add_argument('disable-images') self.options = options
def check_prereqs(): print("Checking script environment...") compatible_os = regex(r'Windows') if not compatible_os.match(get_os()): eprint( "FAILED: This script only works on Windows with cygwin installed.") exit(-1) else: try: # Check cygwin's bash.exe exist subprocess.check_call([ 'powershell.exe', 'try {{ if (-not ([System.IO.File]::Exists("{cygwin_path}"))) {{ throw "Error" }} }} catch {{ }};' .format(cygwin_path=p.join(dir_cygwin, 'bin', "bash.exe")) ], shell=False) # Check running as administrator (only Administrator rights can see the temp dir) ls(p.join(ossep, 'Windows', 'temp')) except subprocess.CalledProcessError: eprint("MISSING PREREQ: cygwin not found @ {}/".format(dir_cygwin)) exit(-2) except PermissionError: eprint( '\n' + "FAILED: Script needs to be run with administrator privileges." ) eprint( "PowerShell w/ Admin Privalages command: \n\t Start-Process powershell -Verb RunAs" ) exit(-3) # Check cygwin's package manager exists pkgmgnr = p.join(dir_cygwin, 'cyg-get', "cyg-pkg-mgnr.exe") if not p.isfile(pkgmgnr): eprint("MISSING PREREQ: cyg-pkg-mgnr.exe not found @ {}".format( p.join(dir_cygwin, 'cyg-get') + ossep)) if p.isfile( p.join( p.dirname(pkgmgnr), 'setup-x86{}.exe'.format("_64" if is_64bit else ""))): # HELPING: original download file found, not renamed. eprint( " Please rename setup-x86{}.exe to cyg-pkg-mgnr.exe and try again.\n" .format("_64" if is_64bit else "")) exit(-4) # VALID Environment print("PASS")
def __init__(self, window_size): # Creamos una variable que contenga el GUI principal self.app = gui("Redes2 - P2P", window_size) self.app.setGuiPadding(10,10) # Preparación del interfaz self.app.addLabel("title", "Cliente Multimedia P2P - Redes2") self.app.addImage("video", "imgs/webcam.gif") # Registramos la función de captura de video # Esta misma función también sirve para enviar un vídeo if get_os() == "Windows": self.cap = cv2.VideoCapture(0) else: self.cap = cv2.VideoCapture("DJI_20190416_212830") self.app.setPollTime(round(1000/self.FPS)) self.app.registerEvent(self.capturaVideo) # Añadimos los botones self.app.addButtons(["BotonA", "BotonB", "BotonC", "BotonD"], self.buttonsCallback) self.app.setButton("BotonA","Llamar") self.app.setButton("BotonB","Listar Usuarios") self.app.setButton("BotonC","Informacion de Usuarios") self.app.setButton("BotonD","Iniciar Sesion") # Barra de estado # Debe actualizarse con información útil sobre la llamada (duración, FPS, etc...) self.app.addStatusbar(fields=2) self.buffer_recepcion = queue.PriorityQueue(self.FPS*2) self.buffer_salida = queue.PriorityQueue(self.FPS*2) # Instanciamos las clase del servidor de descubrimiento self.ds = ds.servidorDescubrimiento() # Obtenemos los puertos y la IP del fichero de configuracion try: with open(ruta, "r") as fihcero_config: mensaje = fihcero_config.read() datos = mensaje.split(' ') self.puerto_origen_UDP = datos[0].split(":")[1] self.puerto_origen_TCP = datos[1].split(":")[1] except FileNotFoundError: print("Error en el fcihero de configuracion") self.IP_origen = self.conseguir_IP()
def __init__(self, mypgpkeyid, pgppassphrase, pgp_dir, app_dir, gpg_binary): self.mypgpkeyid = mypgpkeyid if get_os() == 'Windows': keyring = app_dir + '\pubkeys.gpg' # TODO - account for filenames with spaces on windows else: keyring = app_dir + '/pubkeys.gpg' if os.path.dirname(gpg_binary) == resource_path('binaries'): gpg_exec_dir = '--exec-path ' + resource_path('binaries') # We are using the gpg binaries shipped with the Axis Mundi executable, make sure we set the helpers path self.gpg = gnupg.GPG(gpgbinary=gpg_binary,gnupghome=pgp_dir, options={gpg_exec_dir,'--primary-keyring=' + keyring, '--no-emit-version', '--keyserver=hkp://127.0.0.1:5000', '--keyserver-options=auto-key-retrieve=yes,http-proxy=', '--primary-keyring="' + keyring + '"'}) # removed '--auto-key-locate=keyserver', else: self.gpg = gnupg.GPG(gpgbinary=gpg_binary,gnupghome=pgp_dir, options={'--primary-keyring=' + keyring, '--no-emit-version', '--keyserver=hkp://127.0.0.1:5000', '--keyserver-options=auto-key-retrieve=yes,http-proxy=', '--primary-keyring="' + keyring + '"'}) # removed '--auto-key-locate=keyserver', self.pgp_passphrase = pgppassphrase
def Start(self): newstoragedb = True if isfile(self.appdir + '/' + self.database): newstoragedb = False if get_os() == 'Windows': if self.InitDB(self.passphrase, self.appdir + '\\' + self.database): return True else: if newstoragedb: print "ERROR: Error creating storage database" else: print "ERROR: Error accessing storage database" return False else: if self.InitDB(self.passphrase, self.appdir + '/' + self.database): return True else: if newstoragedb: print "ERROR: Error creating storage database" else: print "ERROR: Error accessing storage database" return False
def Start(self): newstoragedb = True if isfile(self.appdir + '/' + self.database): newstoragedb = False if get_os() == 'Windows': if self.InitDB(self.passphrase, self.appdir + '\\' + self.database): return True else: if newstoragedb: print "Error creating storage database" else: print "Error accessing storage database" return False else: if self.InitDB(self.passphrase, self.appdir + '/' + self.database): return True else: if newstoragedb: print "Error creating storage database" else: print "Error accessing storage database" return False
def crawl_bank_info(process_count=1): if 'Windows' == get_os(): spider_dict = { "农业银行": ABCSpider, "建设银行": CCBSpider, "邮政银行": PsbcSpider, "工商银行": IcbcSpider, "中国银行": BocSpider, "招商银行": CmbSpider, "民生银行": CMBCSpider, "光大银行": CebSpider, "中信银行": CncbSpider, "浦发银行": SpdbSpider, "华夏银行": HxbSpider, "平安银行": PinganSpider, } else: spider_dict = { "交通银行": BocomWapSpider, "兴业银行": CibSpider, "广发银行": CgbWapSpider, } run_multiple_spider_with_process(spider_dict, process_count)
def __init__(self, parent, font = get_font(), text = None, state = "normal"): tk.Text.__init__(self, parent, font = font, state = state, spacing1 = 2, spacing2 = 2, bd = 0, highlightthickness = 0, undo = True, maxundo = 20, background = parent.parent.table_bg, foreground = parent.parent.table_fg, insertbackground = parent.parent.table_fg) self.parent = parent if text is not None: self.insert(1.0, text) self.yview_moveto(1) self.rc_popup_menu = tk.Menu(self, tearoff = 0) self.rc_popup_menu.add_command(label = "Select all", accelerator = "Ctrl+A", font = self.parent.parent.popup_menu_font, foreground = self.parent.parent.popup_menu_fg, background = self.parent.parent.popup_menu_bg, activebackground = self.parent.parent.popup_menu_highlight_bg, activeforeground = self.parent.parent.popup_menu_highlight_fg, command = self.select_all) self.rc_popup_menu.add_command(label = "Cut", accelerator = "Ctrl+X", font = self.parent.parent.popup_menu_font, foreground = self.parent.parent.popup_menu_fg, background = self.parent.parent.popup_menu_bg, activebackground = self.parent.parent.popup_menu_highlight_bg, activeforeground = self.parent.parent.popup_menu_highlight_fg, command = self.cut) self.rc_popup_menu.add_command(label = "Copy", accelerator = "Ctrl+C", font = self.parent.parent.popup_menu_font, foreground = self.parent.parent.popup_menu_fg, background = self.parent.parent.popup_menu_bg, activebackground = self.parent.parent.popup_menu_highlight_bg, activeforeground = self.parent.parent.popup_menu_highlight_fg, command = self.copy) self.rc_popup_menu.add_command(label = "Paste", accelerator = "Ctrl+V", font = self.parent.parent.popup_menu_font, foreground = self.parent.parent.popup_menu_fg, background = self.parent.parent.popup_menu_bg, activebackground = self.parent.parent.popup_menu_highlight_bg, activeforeground = self.parent.parent.popup_menu_highlight_fg, command = self.paste) self.rc_popup_menu.add_command(label = "Undo", accelerator = "Ctrl+Z", font = self.parent.parent.popup_menu_font, foreground = self.parent.parent.popup_menu_fg, background = self.parent.parent.popup_menu_bg, activebackground = self.parent.parent.popup_menu_highlight_bg, activeforeground = self.parent.parent.popup_menu_highlight_fg, command = self.undo) self.bind("<1>", lambda event: self.focus_set()) if str(get_os()) == "Darwin": self.bind("<2>", self.rc) else: self.bind("<3>", self.rc)
# -*- coding: utf-8 -*- """ 需要注意的问题。 若同时开启两个脚本,第二个脚本会调用失败。驱动会加载错误。 这个错误可以被Python捕获。 网络错误会成功启动脚本,但是按键不会有效果,需要重新启动脚本。 这个错误无法被Python捕获。 这个错误可以用dd_dll的内置函数测试是否加载成功来确定。 """ from platform import system as get_os if 'Windows' == get_os(): import win32gui from ctypes import * from os import path as os_path from win32process import GetWindowThreadProcessId import psutil from filelock import FileLock, Timeout as LockTimeout this_dir = os_path.dirname(os_path.abspath(__file__)) path = "temp_file.lock" flock = FileLock(path) def file_lock(func): """ 文件锁装饰器 :param func:
def lanzar_SIGUSR1(self): if get_os() == 'Windows': os.kill(os.getpid(), signal.CTRL_C_EVENT) else: os.kill(os.getpid(), signal.SIGUSR1)
from window.components.button import ( Button, ToggleButton, CheckBox, ToggleSwitch, ) from window.components.slider import ( Slider, ) from window.colour import colour colour = colour.flat_ui.gb if __name__ == '__main__': from os import system from platform import system as get_os os = get_os() if os == 'Windows': system('cls') else: system('clear') app = App() app += Button((100, 50, 100, 50), colour.SKIRRET_GREEN, colour.NASTURCIAN_FLOWER, lambda: print('Button'), 'Button') app += ToggleButton( (50, 150, 200, 50), colour.SKIRRET_GREEN, colour.NASTURCIAN_FLOWER, lambda state: print(f'Toggle Button: {state}'), 'Toggle Button') app += CheckBox((50, 250, 50, 50),
# AUTOTHROTTLE_MAX_DELAY = 60 # The average number of requests Scrapy should be sending in parallel to # each remote server # AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0 # Enable showing throttling stats for every response received: # AUTOTHROTTLE_DEBUG = False # Enable and configure HTTP caching (disabled by default) # See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings # HTTPCACHE_ENABLED = True # HTTPCACHE_EXPIRATION_SECS = 0 # HTTPCACHE_DIR = 'httpcache' # HTTPCACHE_IGNORE_HTTP_CODES = [] # HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage' if 'Windows' == get_os(): # 开发人员调试环境 LOG_FILE = None LOG_LEVEL = "INFO" HTML_DIR = r"e:\html_data" IMAGE_DIR = r"e:\image_data" # 亿商公益商户图片保存目录 WENSHU_DIR = r"e:\wenshu_data" # 裁判文书保存目录(1刑事案件2民事案件3行政案件4赔偿案件5执行案件) IMAGE_HTTP_SUFFIX = 'http://127.0.0.1:8000/images/xuexin/' PHANTOMJS_EXECUTABLE_PATH = os_path.join(this_dir, 'browsers', 'phantomJS', 'phantomjs.exe') CHROME_EXECUTABLE_PATH = os_path.join(this_dir, 'browsers', 'chrome', 'chromedriver.exe') IE_EXECUTABLE_PATH = os_path.join(this_dir, 'browsers', 'IE', 'IEDriverServer.exe') IE_EXECUTABLE_233_PATH = os_path.join(this_dir, 'browsers', 'IE',