Python os.startfile() Examples
The following are 30
code examples of os.startfile().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: tray.py From superpaper with MIT License | 6 votes |
def open_config(self, event): """Opens Superpaper config folder, CONFIG_PATH.""" if platform.system() == "Windows": try: os.startfile(sp_paths.CONFIG_PATH) except BaseException: show_message_dialog("There was an error trying to open the config folder.") elif platform.system() == "Darwin": try: subprocess.check_call(["open", sp_paths.CONFIG_PATH]) except subprocess.CalledProcessError: show_message_dialog("There was an error trying to open the config folder.") else: try: subprocess.check_call(['xdg-open', sp_paths.CONFIG_PATH]) except subprocess.CalledProcessError: show_message_dialog("There was an error trying to open the config folder.")
Example #2
Source File: LPHK.py From LPHK with GNU General Public License v3.0 | 6 votes |
def shutdown(): if lp_events.timer != None: lp_events.timer.cancel() scripts.to_run = [] for x in range(9): for y in range(9): if scripts.threads[x][y] != None: scripts.threads[x][y].kill.set() if window.lp_connected: scripts.unbind_all() lp_events.timer.cancel() launchpad_connector.disconnect(lp) window.lp_connected = False logger.stop() if window.restart: if IS_EXE: os.startfile(sys.argv[0]) else: os.execv(sys.executable, ["\"" + sys.executable + "\""] + sys.argv) sys.exit("[LPHK] Shutting down...")
Example #3
Source File: image_from_mapfile.py From mappyfile with MIT License | 6 votes |
def create_image_from_map(map_file, dll_location): of = tempfile.NamedTemporaryFile(delete=False, suffix=".png", prefix="tmp_") of.close() logging.debug("Creating file %s", of.name) # [SHP2IMG] -m [MAPFILE] -i png -o [RESULT] params = ["shp2img","-m", map_file,"-i","png","-o", of.name] os.environ['PATH'] = dll_location + ';' + os.environ['PATH'] os.environ['PROJ_LIB'] = os.path.join(dll_location, "proj\SHARE") logging.debug(" ".join(params)) p = Popen(params, stdout=PIPE, bufsize=1) with p.stdout: print(map_file) for line in iter(p.stdout.readline, b''): print(line) p.wait() # wait for the subprocess to exit os.startfile(of.name)
Example #4
Source File: helper.py From mappyfile with MIT License | 6 votes |
def _create_image_from_map(map_file, out_img, format): out_img += ".%s" % format #print out_img params = ["shp2img", "-m", map_file, "-i", format, "-o", out_img] os.environ['PATH'] = DLL_LOCATION + ';' + os.environ['PATH'] p = Popen(params, stdout=PIPE, bufsize=1) with p.stdout: for line in iter(p.stdout.readline, b''): print(line) p.wait() # wait for the subprocess to exit #os.startfile(out_img) return out_img
Example #5
Source File: utilities.py From svviz with MIT License | 6 votes |
def launchFile(filepath): if sys.platform.startswith('darwin'): subprocess.call(('open', filepath)) elif os.name == 'nt': os.startfile(filepath) elif os.name == 'posix': subprocess.call(('xdg-open', filepath)) ############################ String utilities ############################
Example #6
Source File: weixin.py From WeixinBot with Apache License 2.0 | 6 votes |
def _showQRCodeImg(self, str): if self.commandLineQRCode: qrCode = QRCode('https://login.weixin.qq.com/l/' + self.uuid) self._showCommandLineQRCode(qrCode.text(1)) else: url = 'https://login.weixin.qq.com/qrcode/' + self.uuid params = { 't': 'webwx', '_': int(time.time()) } data = self._post(url, params, False) if data == '': return QRCODE_PATH = self._saveFile('qrcode.jpg', data, '_showQRCodeImg') if str == 'win': os.startfile(QRCODE_PATH) elif str == 'macos': subprocess.call(["open", QRCODE_PATH]) else: return
Example #7
Source File: wechat_apis.py From WeixinBot with Apache License 2.0 | 6 votes |
def genqrcode(self): """ @brief outprint the qrcode to stdout on macos/linux or open image on windows """ if sys.platform.startswith('win'): url = self.wx_conf['API_qrcode_img'] + self.uuid params = { 't': 'webwx', '_': int(time.time()) } data = post(url, params, False) if data == '': return qrcode_path = save_file('qrcode.jpg', data, './') os.startfile(qrcode_path) else: str2qr_terminal(self.wx_conf['API_qrcode'] + self.uuid)
Example #8
Source File: base_classes.py From scapy with GNU General Public License v2.0 | 6 votes |
def psdump(self, filename=None, **kargs): """ psdump(filename=None, layer_shift=0, rebuild=1) Creates an EPS file describing a packet. If filename is not provided a temporary file is created and gs is called. :param filename: the file's filename """ from scapy.config import conf from scapy.utils import get_temp_file, ContextManagerSubprocess canvas = self.canvas_dump(**kargs) if filename is None: fname = get_temp_file(autoext=kargs.get("suffix", ".eps")) canvas.writeEPSfile(fname) if WINDOWS and conf.prog.psreader is None: os.startfile(fname) else: with ContextManagerSubprocess(conf.prog.psreader): subprocess.Popen([conf.prog.psreader, fname]) else: canvas.writeEPSfile(filename) print()
Example #9
Source File: base_classes.py From scapy with GNU General Public License v2.0 | 6 votes |
def pdfdump(self, filename=None, **kargs): """ pdfdump(filename=None, layer_shift=0, rebuild=1) Creates a PDF file describing a packet. If filename is not provided a temporary file is created and xpdf is called. :param filename: the file's filename """ from scapy.config import conf from scapy.utils import get_temp_file, ContextManagerSubprocess canvas = self.canvas_dump(**kargs) if filename is None: fname = get_temp_file(autoext=kargs.get("suffix", ".pdf")) canvas.writePDFfile(fname) if WINDOWS and conf.prog.pdfreader is None: os.startfile(fname) else: with ContextManagerSubprocess(conf.prog.pdfreader): subprocess.Popen([conf.prog.pdfreader, fname]) else: canvas.writePDFfile(filename) print()
Example #10
Source File: base_classes.py From scapy with GNU General Public License v2.0 | 6 votes |
def svgdump(self, filename=None, **kargs): """ svgdump(filename=None, layer_shift=0, rebuild=1) Creates an SVG file describing a packet. If filename is not provided a temporary file is created and gs is called. :param filename: the file's filename """ from scapy.config import conf from scapy.utils import get_temp_file, ContextManagerSubprocess canvas = self.canvas_dump(**kargs) if filename is None: fname = get_temp_file(autoext=kargs.get("suffix", ".svg")) canvas.writeSVGfile(fname) if WINDOWS and conf.prog.svgreader is None: os.startfile(fname) else: with ContextManagerSubprocess(conf.prog.svgreader): subprocess.Popen([conf.prog.svgreader, fname]) else: canvas.writeSVGfile(filename) print()
Example #11
Source File: files.py From pipeline with MIT License | 6 votes |
def run(filename): if filename: if os.path.exists(filename): if sys.platform == "win32": os.startfile(filename) return True else: opener ="open" if sys.platform == "darwin" else "xdg-open" subprocess.call([opener, filename]) return True log.info("File dose not exist") return False log.info("No file name spacified") return False
Example #12
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_deprecated(self): import nt filename = os.fsencode(support.TESTFN) with warnings.catch_warnings(): warnings.simplefilter("error", DeprecationWarning) for func, *args in ( (nt._getfullpathname, filename), (nt._isdir, filename), (os.access, filename, os.R_OK), (os.chdir, filename), (os.chmod, filename, 0o777), (os.getcwdb,), (os.link, filename, filename), (os.listdir, filename), (os.lstat, filename), (os.mkdir, filename), (os.open, filename, os.O_RDONLY), (os.rename, filename, filename), (os.rmdir, filename), (os.startfile, filename), (os.stat, filename), (os.unlink, filename), (os.utime, filename), ): self.assertRaises(DeprecationWarning, func, *args)
Example #13
Source File: functions.py From mrz with GNU General Public License v3.0 | 6 votes |
def open_image(directory, image): answer = input("Would you like to open the image of the computed passport file? [y] / n : ").lower() if answer in ("y", "yes") or answer == "": try: # TODO: Test abspath() on Windows image_path = os.path.join(os.pardir, os.pardir, "docs", "images", directory, image) print(image_path) if sys.platform.startswith('darwin'): subprocess.call(('open', image_path)) elif os.name == 'nt': os.startfile(image_path) elif os.name == 'posix': subprocess.call(('xdg-open', image_path)) except Exception: print("%s- An unexpected error occurred. The file could not be opened%s" % RED) for msg in sys.exc_info(): print("\033[31m!", str(msg)) elif answer in ("n", "no"): exit() else: print("%sInvalid response%s" % RED) open_image(directory, image)
Example #14
Source File: utils.py From TARS with MIT License | 5 votes |
def print_qr(fileDir): if config.OS == 'Darwin': subprocess.call(['open', fileDir]) elif config.OS == 'Linux': subprocess.call(['xdg-open', fileDir]) else: os.startfile(fileDir)
Example #15
Source File: webbrowser.py From Imogen with MIT License | 5 votes |
def open(self, url, new=0, autoraise=True): try: os.startfile(url) except OSError: # [Error 22] No application is associated with the specified # file for this operation: '<URL>' return False else: return True # # Platform support for MacOS #
Example #16
Source File: wm.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): import sys import os import subprocess filepath = self.filepath if not filepath: self.report({'ERROR'}, "File path was not set") return {'CANCELLED'} filepath = bpy.path.abspath(filepath) filepath = os.path.normpath(filepath) if not os.path.exists(filepath): self.report({'ERROR'}, "File '%s' not found" % filepath) return {'CANCELLED'} if sys.platform[:3] == "win": os.startfile(filepath) elif sys.platform == "darwin": subprocess.check_call(["open", filepath]) else: try: subprocess.check_call(["xdg-open", filepath]) except: # xdg-open *should* be supported by recent Gnome, KDE, Xfce import traceback traceback.print_exc() return {'FINISHED'}
Example #17
Source File: wm.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def execute(self, context): import sys import os import subprocess filepath = self.filepath if not filepath: self.report({'ERROR'}, "File path was not set") return {'CANCELLED'} filepath = bpy.path.abspath(filepath) filepath = os.path.normpath(filepath) if not os.path.exists(filepath): self.report({'ERROR'}, "File '%s' not found" % filepath) return {'CANCELLED'} if sys.platform[:3] == "win": os.startfile(filepath) elif sys.platform == "darwin": subprocess.check_call(["open", filepath]) else: try: subprocess.check_call(["xdg-open", filepath]) except: # xdg-open *should* be supported by recent Gnome, KDE, Xfce import traceback traceback.print_exc() return {'FINISHED'}
Example #18
Source File: main_window.py From Blender-Version-Manager with GNU General Public License v3.0 | 5 votes |
def open_root_folder(self): root_folder = self.settings.value('root_folder') if self.platform == 'Windows': os.startfile(root_folder) elif self.platform == 'Linux': subprocess.call(["xdg-open", root_folder])
Example #19
Source File: app.py From syncthing-gtk with GNU General Public License v2.0 | 5 votes |
def cb_browse_folder(self, box, *a): """ Handler for 'browse' action """ path = os.path.expanduser(box["path"]) if IS_WINDOWS: # Don't attempt anything, use registry settigns on Windows # (defaults to Windows Explorer) path = path.replace("/", "\\") os.startfile(path, self.config["file_browser"]) else: # Try to use any of following, known commands to # display directory contents for x in ('xdg-open', 'gnome-open', 'kde-open'): if os.path.exists("/usr/bin/%s" % x): os.system( ("/usr/bin/%s '%s' &" % (x, path)).encode('utf-8') ) break
Example #20
Source File: show.py From cauldron with MIT License | 5 votes |
def open_folder(path: str): """Opens the local project folder.""" if sys.platform == 'darwin': subprocess.check_call(['open', '--', path]) elif sys.platform == 'linux2': subprocess.check_call(['xdg-open', '--', path]) elif sys.platform == 'win32': os.startfile(path)
Example #21
Source File: EditorWindow.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def python_docs(self, event=None): if sys.platform[:3] == 'win': try: os.startfile(self.help_url) except OSError as why: tkMessageBox.showerror(title='Document Start Failure', message=str(why), parent=self.text) else: webbrowser.open(self.help_url) return "break"
Example #22
Source File: webwxapi.py From WxRobot with MIT License | 5 votes |
def _safe_open(self,file_path): try: if sys.platform.find('darwin') >= 0: subprocess.call(['open',file_path]) elif sys.platform.find('linux') >= 0: subprocess.call(['xdg-open',file_path]) else: os.startfile(file_path) return True except: return False
Example #23
Source File: _dragonfly_utils.py From dragonfly-commands with GNU Lesser General Public License v3.0 | 5 votes |
def _execute_events(self, repeat): if platform.release() >= "8": # Work around security restrictions in Windows 8. # Credit: https://autohotkey.com/board/topic/84771-alttab-mapping-isnt-working-anymore-in-windows-8/ os.startfile("C:/Users/Default/AppData/Roaming/Microsoft/Internet Explorer/Quick Launch/Window Switcher.lnk") Pause("10").execute() if platform.release() == "8": Key("tab:%d/10, enter" % (repeat - 1)).execute() else: Key("right:%d/10, enter" % repeat).execute() else: Key("alt:down, tab:%d/10, alt:up" % repeat).execute()
Example #24
Source File: fgoGui.py From FGO-py with MIT License | 5 votes |
def openFolder(self):os.startfile(os.getcwd())
Example #25
Source File: test_validation.py From mappyfile with MIT License | 5 votes |
def _create_image_from_map(map_file, out_img, format): out_img += ".%s" % format params = [ "shp2img", "-m", map_file, "-i", format, "-o", out_img, "-s", 256, 256] # , # "-e", "0 0 5 5" params = [str(p) for p in params] logging.info(" ".join(params)) os.environ['PATH'] = DLL_LOCATION + ';' + os.environ['PATH'] p = Popen(params, stdout=PIPE, stderr=STDOUT) errors = [] with p.stdout: for line in iter(p.stdout.readline, b''): errors.append(line) p.wait() # wait for the subprocess to exit if errors: logging.error("\n".join(errors)) return None else: logging.info("Created %s", out_img) os.startfile(out_img) return out_img
Example #26
Source File: misc_functions.py From FontSelector_blender_addon with GNU General Public License v3.0 | 5 votes |
def open_folder_in_explorer(path) : if platform.system() == "Windows": os.startfile(path) elif platform.system() == "Darwin": subprocess.Popen(["open", path]) else: subprocess.Popen(["xdg-open", path]) # export menu
Example #27
Source File: dtfind.py From dfirtriage with The Unlicense | 5 votes |
def log_results(): ''' writes results to log file with search term in name ''' global search_string log_file = "search_results({}).txt".format(search_string.replace(":", ".")) search_list_log = search_file_list_no_highlight(curr_dir, search_string) original = sys.stdout sys.stdout = open(log_file, 'w', errors="surrogateescape") time_stamp = datetime.now().strftime('%m-%d-%Y %H:%M') print("# DFIR Triage Search LOG\n# dtfind v1.0\n# Time of search: {} \n# Keyword: '{}'\n".format(time_stamp, search_string)) print("\n[BEGIN LOG]") for x in search_list_log: try: print("\n--------------------------------------------------------------------------------------------------" "-----\n") print("Data File Name: ", x[0]) print("Info: ", x[1]) print("Line Number: ", x[2]) except UnicodeEncodeError: continue print("\n\n[END LOG]") sys.stdout.close() sys.stdout = original os.startfile(".") sys.exit(0) # writes results to log file with search term in name -------------------------------------------------------# ########################################################################## ################ All function calls defined above ################ ########################################################################## # functions called everytime --------------------------------------------------------------------------------#
Example #28
Source File: acecore.py From program.plexus with GNU General Public License v2.0 | 5 votes |
def startWin(self): try: needed_value='ace_engine.exe' path_value=os.path.join(pastaperfil,'acestream',needed_value) self.log.out("Try to start %s"%needed_value) self.progress.update(0,'Starting ASEngine','') os.startfile(path_value) self.log.out('AceStream Engine starting') except: self.sm('Not Installed') self.log.out('Not Installed') self.progress.update(0,'AceStream not installed','') return False return True
Example #29
Source File: yify.py From pyYify with MIT License | 5 votes |
def start_downlod(self): if os.name=='nt': os.startfile(self.magnet) ; else: os.system("xdg-open "+self.magnet) ;
Example #30
Source File: dot.py From pydeps with BSD 2-Clause "Simplified" License | 5 votes |
def display_svg(kw, fname): # pragma: nocover """Try to display the svg file on this platform. """ if kw['display'] is None: cli.verbose("Displaying:", fname) if sys.platform == 'win32': os.startfile(fname) else: opener = "open" if sys.platform == "darwin" else "xdg-open" subprocess.call([opener, fname]) else: cli.verbose(kw['display'] + " " + fname) os.system(kw['display'] + " " + fname)