Python sys.platform.startswith() Examples
The following are 22
code examples of sys.platform.startswith().
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
sys.platform
, or try the search function
.
Example #1
Source File: selescrape.py From anime-downloader with The Unlicense | 6 votes |
def get_browser_config(): ''' Decides what browser selescrape will use. ''' os_browser = { #maps os to a browser 'linux':'firefox', 'darwin':'chrome', 'win32':'chrome' } for a in os_browser: if platform.startswith(a): browser = os_browser[a] else: browser = 'chrome' value = data['dl']['selescrape_browser'] value = value.lower() if value else value if value in ['chrome', 'firefox']: browser = value return browser
Example #2
Source File: configurator.py From awesometts-anki-addon with GNU General Public License v3.0 | 6 votes |
def _ui_tabs(self): """Returns tab widget w/ Playback, Text, MP3s, Advanced.""" use_icons = not platform.startswith('darwin') tabs = QtWidgets.QTabWidget() for content, icon, label in [ (self._ui_tabs_playback, 'player-time', "Playback"), (self._ui_tabs_text, 'editclear', "Text"), (self._ui_tabs_mp3gen, 'document-new', "MP3s"), (self._ui_tabs_windows, 'kpersonalizer', "Windows"), (self._ui_tabs_advanced, 'configure', "Advanced"), ]: if use_icons: tabs.addTab(content(), QtGui.QIcon(f'{ICONS}/{icon}.png'), label) else: # active tabs do not display correctly on Mac OS X w/ icons tabs.addTab(content(), label) tabs.currentChanged.connect(lambda: (tabs.adjustSize(), self.adjustSize())) return tabs
Example #3
Source File: util.py From botamusique with MIT License | 5 votes |
def add_file(self, file): if file.startswith(self.name + '/'): file = file.replace(self.name + '/', '', 1) if '/' in file: # This file is in a subdir subdir = file.split('/')[0] if subdir in self.subdirs: self.subdirs[subdir].add_file(file) else: self.subdirs[subdir] = Dir(os.path.join(self.fullpath, subdir)) self.subdirs[subdir].add_file(file) else: self.files.append(file) return True
Example #4
Source File: test_mkldnn.py From SNIPER-mxnet with Apache License 2.0 | 5 votes |
def test_mkldnn_install(): """ This test will verify that MXNet is built/installed correctly when compiled with Intel MKL-DNN library. The method will try to import the mxnet module and see if the mkldnn library is mapped to this process's address space. """ logging.basicConfig(level=logging.INFO) if not platform.startswith('linux'): logging.info("Bypass mkldnn install test for non-Linux OS") return try: #pylint: disable=unused-variable import mxnet as mx except (ImportError, OSError) as e: assert 0, "Import mxnet error: %s. Please double check your build/" \ "install steps or environment variable settings" % str(e) pid = os.getpid() rc = os.system("cat /proc/" + str(pid) + "/maps | grep libmkldnn > /dev/null") if rc == 0: logging.info("MXNet is built/installed correctly with MKL-DNN") else: assert 0, "MXNet is built/installed incorrectly with MKL-DNN, please " \ "double check your build/install steps or environment " \ "variable settings"
Example #5
Source File: setup.py From mochi with MIT License | 5 votes |
def is_windows(): from sys import platform return platform.startswith('win') or platform.startswith('cygwin')
Example #6
Source File: pomodoro.py From pomodoro with MIT License | 5 votes |
def _open_terminal(python_script, time_to_close=5): """Open a new terminal with the python script passed :param python_script: The path of the python script to be executed :param time_to_close: the number of seconds before closing the new terminal """ if _platform == "darwin": #macOS os.system("xterm -e 'bash -c \"python %s %d; exec bash\"'" % (python_script, time_to_close)) elif _platform.startswith('linux'): #linux if platform.linux_distribution()[0] == "arch": # Arch Linux support os.system( "xterm -e 'bash -c \"python %s %d; exec bash\"'" % (python_script, time_to_close)) else: # Debian based distros os.system( "x-terminal-emulator -e 'bash -c \"python %s %d; exec bash\"'" % (python_script, time_to_close)) elif os.name == 'nt': #Windows os.system("start cmd /c python %s %d" % (python_script, time_to_close)) else: os.system( "x-terminal-emulator -e 'bash -c \"python %s %d; exec bash\"'" % (python_script, time_to_close))
Example #7
Source File: bar.py From InfiniDrive with GNU General Public License v3.0 | 5 votes |
def getpatchedprogress(): # Import a clean version of the entire package. import progress # Import the wraps decorator for copying over the name, docstring, and other metadata. from functools import wraps # Get the current platform. from sys import platform # Check if we're on Windows. if platform.startswith("win"): # Disable HIDE_CURSOR and SHOW_CURSOR characters. progress.HIDE_CURSOR = '' progress.SHOW_CURSOR = '' # Create a patched clearln function that wraps the original function. @wraps(progress.Infinite.clearln) def patchedclearln(self): # Get the current platform. from sys import platform # Some sort of check copied from the source. if self.file and self.is_tty(): # Check if we're on Windows. if platform.startswith("win"): # Don't use the character. print('\r', end='', file=self.file) else: # Use the character. print('\r\x1b[K', end='', file=self.file) # Copy over the patched clearln function into the imported clearln function. progress.Infinite.clearln = patchedclearln # Return the modified version of the entire package. return progress
Example #8
Source File: test_ssl.py From pyopenssl with Apache License 2.0 | 5 votes |
def test_set_tmp_ecdh(self): """ `Context.set_tmp_ecdh` sets the elliptic curve for Diffie-Hellman to the specified curve. """ context = Context(TLSv1_METHOD) for curve in get_elliptic_curves(): if curve.name.startswith(u"Oakley-"): # Setting Oakley-EC2N-4 and Oakley-EC2N-3 adds # ('bignum routines', 'BN_mod_inverse', 'no inverse') to the # error queue on OpenSSL 1.0.2. continue # The only easily "assertable" thing is that it does not raise an # exception. context.set_tmp_ecdh(curve)
Example #9
Source File: test_tty.py From mnamer with MIT License | 5 votes |
def test_chars(): bullet = "►" if platform.startswith("win") else "❱" tty.verbose = False tty.no_style = False expected = { "arrow": f"\x1b[35m{bullet}\x1b[0m", "block": "█", "left-edge": "▐", "right-edge": "▌", "selected": "●", "unselected": "○", } actual = tty._chars() assert actual == expected
Example #10
Source File: quota_supervisor.py From bot with GNU General Public License v3.0 | 5 votes |
def get_icons(): """ Return the locations of icons according to the operating system """ # get full location of icons folder inside package icons_path = get_pkg_resource_path("instapy", "icons/") windows_ico = [ "Windows/qs_sleep_windows.ico", "Windows/qs_wakeup_windows.ico", "Windows/qs_exit_windows.ico", ] linux_png = [ "Linux/qs_sleep_linux.png", "Linux/qs_wakeup_linux.png", "Linux/qs_exit_linux.png", ] mac_icns = [ "Mac/qs_sleep_mac.icns", "Mac/qs_wakeup_mac.icns", "Mac/qs_exit_mac.icns", ] # make it full path now windows_ico = [icons_path + icon for icon in windows_ico] linux_png = [icons_path + icon for icon in linux_png] mac_icns = [icons_path + icon for icon in mac_icns] (sleep_icon, wakeup_icon, exit_icon) = ( windows_ico if platform.startswith("win32") else linux_png if platform.startswith("linux") else mac_icns if platform.startswith("darwin") else [None, None, None] ) icons = {"sleep": sleep_icon, "wakeup": wakeup_icon, "exit": exit_icon} return icons
Example #11
Source File: quota_supervisor.py From bot with GNU General Public License v3.0 | 5 votes |
def toast_notification(notify, alert, job, interval): """ Send toast notifications about supervising states directly to OS using 'plyer' module """ platform_matches = platform.startswith(("win32", "linux", "darwin")) if notify is True and platform_matches: icons = get_icons() delay = 9 if alert == "exit" else 7 label = job.replace("_", " ").capitalize() expr = ( "Yawn! {} filled {} quotient!\t~falling asleep a little bit :>" if alert == "sleep" else "Yikes! {} just woke up from {} quotient bandage!\t~let's " "chill again wakey ;)" if alert == "wakeup" else "D'oh! {} finished {} quotient!\t~exiting ~,~" ) try: notification.notify( title="Quota Supervisor", message=expr.format(label, interval), app_name="InstaPy", app_icon=icons[alert], timeout=delay, ticker="To switch supervising methods, please review " "quickstart script", ) except Exception: # TypeError: out of 'plyer' bug in python 2 - INNER EXCEPTION # NotImplementedError: when 'plyer' is not supported # DBusException: dbus-display issue on linux boxes # turn off toast notification for the rest of the session configuration.update(nofity=False)
Example #12
Source File: util.py From botamusique with MIT License | 5 votes |
def get_url_from_input(string): string = string.strip() if not (string.startswith("http") or string.startswith("HTTP")): res = re.search('href="(.+?)"', string, flags=re.IGNORECASE) if res: string = res.group(1) else: return False match = re.search("(http|https)://(\S*)?/(\S*)", string, flags=re.IGNORECASE) if match: url = match[1].lower() + "://" + match[2].lower() + "/" + match[3] return url else: return False
Example #13
Source File: __main__.py From vpn-slice with GNU General Public License v3.0 | 5 votes |
def get_default_providers(): global platform try: from .dnspython import DNSPythonProvider except ImportError: DNSPythonProvider = None if platform.startswith('linux'): from .linux import ProcfsProvider, Iproute2Provider, IptablesProvider, CheckTunDevProvider from .posix import DigProvider, PosixHostsFileProvider return dict( process = ProcfsProvider, route = Iproute2Provider, firewall = IptablesProvider, dns = DNSPythonProvider or DigProvider, hosts = PosixHostsFileProvider, prep = CheckTunDevProvider, ) elif platform.startswith('darwin'): from .mac import PsProvider, BSDRouteProvider from .posix import PosixHostsFileProvider from .dnspython import DNSPythonProvider return dict( process = PsProvider, route = BSDRouteProvider, dns = DNSPythonProvider or DigProvider, hosts = PosixHostsFileProvider, ) else: return dict( platform = OSError('Your platform, {}, is unsupported'.format(platform)) )
Example #14
Source File: test_basic_network.py From python with Apache License 2.0 | 5 votes |
def test_anon_unix(self): if platform.startswith("linux"): self.do_run("unix:@org.varlink.service_anon_test" + str(os.getpid()) + threading.current_thread().getName() )
Example #15
Source File: __init__.py From AstroBox with GNU Affero General Public License v3.0 | 5 votes |
def externalDriveManager(): global _instance if _instance is None: if platform.startswith("linux"): from .linux import ExternalDriveManager _instance = ExternalDriveManager() elif platform == "darwin": from .mac_dev import ExternalDriveManager _instance = ExternalDriveManager() return _instance
Example #16
Source File: configurator.py From awesometts-anki-addon with GNU General Public License v3.0 | 5 votes |
def _get_pressed_shortcut_buttons(self): """Returns all shortcut buttons that are pressed.""" return [button for button in self.findChildren(QtWidgets.QPushButton) if (button.isChecked() and (button.objectName().startswith('launch_') or button.objectName().startswith('tts_key_')))]
Example #17
Source File: frameForms.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self,dialog='anyFile.ui'): dialogPath=join(dirname(abspath(__file__)),"dialogs",dialog) FreeCAD.Console.PrintMessage(dialogPath+"\n") self.form=FreeCADGui.PySideUic.loadUi(dialogPath) FreeCAD.Console.PrintMessage(dialogPath+" loaded\n") if platform.startswith('win'):# or vQt>=5: FreeCAD.Console.PrintWarning("No keyboard shortcuts.\n No callback on SoEvent") else: FreeCAD.Console.PrintMessage('Keyboard shortcuts available.\n"S" to select\n"RETURN" to perform action\n') try: self.view=FreeCADGui.activeDocument().activeView() # get3DView() self.call=self.view.addEventCallback("SoEvent", self.action) except: FreeCAD.Console.PrintError('No view available.\n')
Example #18
Source File: polarUtilsCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self): self.arrow=None super(handleDialog,self).__init__('disp.ui') self.form.edit1.setValidator(QDoubleValidator()) #self.form.edit1.hide()# #self.form.lab1.hide()# self.form.btn1.clicked.connect(self.selectAction) from sys import platform if platform.startswith('win'): self.form.lab2.hide()
Example #19
Source File: img_utils.py From pdftotree with MIT License | 5 votes |
def lazy_load_font(font_size=default_font_size): """ Lazy loading font according to system platform """ if font_size not in _font_cache: if _platform.startswith("darwin"): font_path = "/Library/Fonts/Arial.ttf" elif _platform.startswith("linux"): font_path = "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf" elif _platform.startswith("win32"): font_path = "C:\\Windows\\Fonts\\arial.ttf" _font_cache[font_size] = ImageFont.truetype(font_path, font_size) return _font_cache[font_size]
Example #20
Source File: util.py From importmagic with BSD 2-Clause "Simplified" License | 5 votes |
def get_cache_dir(): if platform.startswith('linux'): cache_dir = '~/.cache/importmagic/' elif platform == 'darwin': cache_dir = '~/Library/Caches/importmagic' elif platform in ('win32', 'cygwin'): cache_dir = '%APPDATA%\importmagic' cache_dir = os.path.expanduser(cache_dir) if not os.path.exists(cache_dir): os.makedirs(cache_dir) return cache_dir
Example #21
Source File: cozmo_tts.py From letsrobot with Apache License 2.0 | 4 votes |
def run(coz_conn): global coz global ffmpeg_location coz = coz_conn.wait_for_robot() coz.enable_stop_on_cliff(True) # Turn on image receiving by the camera coz.camera.image_stream_enabled = True coz.say_text( "hey everyone, lets robot!", in_parallel=True) while True: time.sleep(0.25) from subprocess import Popen, PIPE from sys import platform #Frames to file #p = Popen(['ffmpeg', '-y', '-f', 'image2pipe', '-vcodec', 'png', '-r', '25', '-i', '-', '-vcodec', 'mpeg1video', '-qscale', '5', '-r', '25', 'outtest.mpg'], stdin=PIPE) if platform.startswith('linux') or platform == "darwin": #MacOS/Linux p = Popen([ffmpeg_location, '-y', '-f', 'image2pipe', '-vcodec', 'png', '-r', '25', '-i', '-', '-vcodec', 'mpeg1video', '-r', '25', "-f","mpegts","http://letsrobot.tv:"+str(video_port)+"/"+stream_key+"/320/240/"], stdin=PIPE) elif platform.startswith('win'): #Windows import os if not os.path.isfile(ffmpeg_location): print("Error: cannot find " + str(ffmpeg_location) + " check ffmpeg is installed. Terminating controller") thread.interrupt_main() thread.exit() p = Popen([ffmpeg_location, '-nostats', '-y', '-f', 'image2pipe', '-vcodec', 'png', '-r', '25', '-i', '-', '-vcodec', 'mpeg1video', '-r', '25','-b:v', '400k', "-f","mpegts","http://letsrobot.tv:"+str(video_port)+"/"+stream_key+"/320/240/"], stdin=PIPE) try: while True: if coz: image = coz.world.latest_image if image: if annotated: image = image.annotate_image() else: image = image.raw_image image.save(p.stdin, 'PNG') else: time.sleep(.1) p.stdin.close() p.wait() except cozmo.exceptions.SDKShutdown: p.stdin.close() p.wait() pass
Example #22
Source File: util.py From botamusique with MIT License | 4 votes |
def pipe_no_wait(): """ Generate a non-block pipe used to fetch the STDERR of ffmpeg. """ if platform == "linux" or platform == "linux2" or platform == "darwin" or platform.startswith("openbsd"): import fcntl import os pipe_rd = 0 pipe_wd = 0 if hasattr(os, "pipe2"): pipe_rd, pipe_wd = os.pipe2(os.O_NONBLOCK) else: pipe_rd, pipe_wd = os.pipe() try: fl = fcntl.fcntl(pipe_rd, fcntl.F_GETFL) fcntl.fcntl(pipe_rd, fcntl.F_SETFL, fl | os.O_NONBLOCK) except: print(sys.exc_info()[1]) return None, None return pipe_rd, pipe_wd elif platform == "win32": # https://stackoverflow.com/questions/34504970/non-blocking-read-on-os-pipe-on-windows import msvcrt import os from ctypes import windll, byref, wintypes, WinError, POINTER from ctypes.wintypes import HANDLE, DWORD, BOOL pipe_rd, pipe_wd = os.pipe() LPDWORD = POINTER(DWORD) PIPE_NOWAIT = wintypes.DWORD(0x00000001) ERROR_NO_DATA = 232 SetNamedPipeHandleState = windll.kernel32.SetNamedPipeHandleState SetNamedPipeHandleState.argtypes = [HANDLE, LPDWORD, LPDWORD, LPDWORD] SetNamedPipeHandleState.restype = BOOL h = msvcrt.get_osfhandle(pipe_rd) res = windll.kernel32.SetNamedPipeHandleState(h, byref(PIPE_NOWAIT), None, None) if res == 0: print(WinError()) return None, None return pipe_rd, pipe_wd