def check_platform():
  """Check the platform that script is running on.
  """
  if platform.startswith("win32") or platform.startswith("cygwin"):
    if version_info[0] < 3 and version_info[1] > 1:
      click.echo("Python version not supported, "
                 "Install python 3.x.x and try again")
   def __init__(self, headless = False):
      if "UNO_PATH" in os.environ:
         office = os.environ["UNO_PATH"]
      else:
         if platform.startswith("win"):
            # XXX
            office = ""
         else:
            # Lets hope that works..
            office = '/usr/bin'
      office = os.path.join(office, "soffice")
      if platform.startswith("win"):
          office += ".exe"

      self._pidfile = "/tmp/markup_renderer_OOinstance" #XXX Windows compat needed
      xLocalContext = uno.getComponentContext()
      self._resolver = xLocalContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xLocalContext)
      self._socket = "name=markupRendererPipe"

      args = ["--invisible", "--nologo", "--nodefault", "--norestore", "--nofirststartwizard"]
      if headless:
         args.append("--headless")

      if platform.startswith("win"):
         cmdArray = ['"' + office + '"']
      else:
         cmdArray = [office]
      cmdArray += args + ["--accept=pipe,%s;urp" % self._socket]
      if( not os.path.isfile(self._pidfile)):
         self.pid = os.spawnv(os.P_NOWAIT, office, cmdArray)
         f = open(self._pidfile,"w")
         f.write(str(self.pid))
Esempio n. 3
0
  def Run(self):
    if platform.startswith("win"):
      startupinfo = subprocess.STARTUPINFO()
      startupinfo.dwFlags |= STARTF_USESHOWWINDOW

    for cmd in self.script:
      evt = scriptEvent(msg = cmd, state = SCRIPT_RUNNING)
      wx.PostEvent(self.win, evt)
      args = shlex.split(str(cmd))
      try:
        if platform.startswith("win"):
          p = subprocess.Popen(args, stderr = subprocess.STDOUT,
                               stdout = subprocess.PIPE,
                               startupinfo = startupinfo)
        else:
          p = subprocess.Popen(args, stderr = subprocess.STDOUT,
                               stdout = subprocess.PIPE)
      except:
        evt = scriptEvent(msg = "Exception occurred trying to run\n\n%s" % cmd,
                          state = SCRIPT_CANCELLED)
        wx.PostEvent(self.win, evt)
        self.running = False
        return
      obuf = ''
      while not self.cancelled:
        o = p.stdout.read(1)
        if o == '': break
        if o == '\r' or o == '\n':
          if obuf.strip() != "":
            evt = scriptEvent(msg = obuf, state = SCRIPT_RUNNING)
            wx.PostEvent(self.win, evt)
          obuf = ''
        elif ord(o) < 32:
          pass
        else:
          obuf += o

      if self.cancelled:
        evt = scriptEvent(msg = None, state = SCRIPT_CANCELLED)
        wx.PostEvent(self.win, evt)
        p.kill()
        self.running = False
        p.wait()
        return

      rc = p.wait()
      if rc != 0:
        msg = "RC = " + str(rc) + " - Build terminated"
        evt = scriptEvent(msg = msg, state = SCRIPT_CANCELLED)
        wx.PostEvent(self.win, evt)
        self.running = False
        return

      evt = scriptEvent(msg = "", state = SCRIPT_RUNNING)
      wx.PostEvent(self.win, evt)

    evt = scriptEvent(msg = None, state = SCRIPT_FINISHED)
    wx.PostEvent(self.win, evt)

    self.running = False
Esempio n. 4
0
   def __init__(self, headless = False):
      if "UNO_PATH" in os.environ:
         office = os.environ["UNO_PATH"]
      else:
         if platform.startswith("win"): 
            # XXX
            office = ""
         else:
            # Lets hope that works..
            office = '/usr/bin'
      office = os.path.join(office, "soffice")
      if platform.startswith("win"): 
          office += ".exe"
	
      self._pipeName = "uno_template_foobar_23_42"
       
      xLocalContext = uno.getComponentContext()
      self._resolver = xLocalContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xLocalContext)
      self._connect = "uno:pipe,name=" + self._pipeName + ";urp;StarOffice.ComponentContext"

      args = ["-invisible", "-nologo", "-nodefault", "-norestore", "--nofirststartwizard"]
      if headless:
         args.append("-headless")

      if platform.startswith("win"):
         cmdArray = ['"' + office + '"'] 
      else:
         cmdArray = [office]
      cmdArray += args + ["-accept=pipe,name=%s;urp;" % self._pipeName]
      self.pid = os.spawnv(os.P_NOWAIT, office, cmdArray)
Esempio n. 5
0
def clearScreen():
	import os
	if _platform.startswith("linux") or _platform.startswith("darwin"):
		# linux or mac
		os.system("clear")
	else:
		# windows
		os.system("cls")
Esempio n. 6
0
def get_os():
    """
    Return system OS name.
    :return: string
    """
    if platform.startswith('linux'):
        return 'Linux'
    elif platform.startswith('win'):
        return 'Windows'
Esempio n. 7
0
def retrieve_serial_number():
    if platform.startswith("linux"):
        return ""
    elif platform.startswith("win"):
        output = check_output(["wmic", "bios", "get", "serialnumber"])
        output = output.strip().split("\n")[1]
        return output
    elif platform.startswith("darwin"):
        raise NotImplementedError
Esempio n. 8
0
 def _init_socket(self):
     try:
         if ipaddress.IPv4Address(self.announce_addr).is_multicast:
             # TTL
             self._udp_sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
             # TODO: This should only be used if we do not have inproc method! 
             self._udp_sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP, 1)
             # Usually, the system administrator specifies the 
             # default interface multicast datagrams should be 
             # sent from. The programmer can override this and
             # choose a concrete outgoing interface for a given
             # socket with this option. 
             #
             # this results in the loopback address?
             # host = socket.gethostbyname(socket.gethostname())
             # self._udp_sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(host))
             # You need to tell the kernel which multicast groups 
             # you are interested in. If no process is interested 
             # in a group, packets destined to it that arrive to 
             # the host are discarded.            
             # You can always fill this last member with the 
             # wildcard address (INADDR_ANY) and then the kernel 
             # will deal with the task of choosing the interface.
             #
             # Maximum memberships: /proc/sys/net/ipv4/igmp_max_memberships 
             # self._udp_sock.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, 
             #       socket.inet_aton("225.25.25.25") + socket.inet_aton(host))
             group = socket.inet_aton(self.announce_addr)
             mreq = struct.pack('4sL', group, socket.INADDR_ANY)
             self._udp_sock.setsockopt(socket.SOL_IP, 
                                       socket.IP_ADD_MEMBERSHIP, mreq)
             self._udp_sock.setsockopt(socket.SOL_SOCKET, 
                                       socket.SO_REUSEADDR, 1)
             #  On some platforms we have to ask to reuse the port
             try: 
                 socket.self._udp_sock.setsockopt(socket.SOL_SOCKET, 
                                       socket.SO_REUSEPORT, 1)
             except AttributeError:
                 pass
             self._udp_sock.bind((self.announce_addr, self._port))
         else:
             # Only for broadcast
             print("Setting up a broadcast beacon on %s:%s" %(self.announce_addr, self._port))
             self._udp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)       
             self._udp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
             #  On some platforms we have to ask to reuse the port
             try: 
                 self._udp_sock.setsockopt(socket.SOL_SOCKET, 
                                       socket.SO_REUSEPORT, 1)
             except AttributeError:
                 pass
             if platform.startswith("win") or  platform.startswith("darwin"):
                 self._udp_sock.bind(("0.0.0.0", self._port))
             else:
                 self._udp_sock.bind((self.announce_addr, self._port))
     except socket.error as msg:
         print(msg)
Esempio n. 9
0
def openfile(path):
    if platform.startswith('win') or platform == 'cygwin':
        subprocess.Popen(['explorer', '-p', '/select,', path])
    elif platform.startswith('linux'):
        subprocess.Popen(['xdg-open', path])
    elif platform.startswith('darwin'):
        subprocess.Popen(['open', path])
    else:
        raise NotImplementedError
Esempio n. 10
0
def get_args():
    import argparse
    from sys import platform

    # Parent parser
    mainparser = argparse.ArgumentParser(description='''Restores backups
            created by s3backup.py''')
    mainparser.add_argument('--version', action='version',
            version='s3restore %s; Suite version %s' %
            (version, config.version))
    subparsers = mainparser.add_subparsers(title='Commands',
            description='Type "command -h" for more info.')

    # Parser for the full-restore command
    fullparser = subparsers.add_parser('full-restore', help='''Restores all
            files from the backup.''')
    fullparser.add_argument('schedule', choices=['daily', 'weekly',
            'monthly'], help='Specifies the backup type to restore.')
    fullparser.add_argument('date', help='''The date the backup was made. A
            quoted string of the format "MM DD YYYY". A value of "last"
            restores the most recent backup.''')
    fullparser.add_argument('--force', action='store_true',
            help='''Restores all files, overwriting any with duplicate
            filenames.''')
    fullparser.add_argument('--force-no-overwrite', action='store_true',
            help='''Restores all file that no longer exist on the
            filesystem.''')
    fullparser.add_argument('-d', '--download-only', metavar='DIR',
            help='''Download and decrypt (if necessary) the archive to the
            given directory, but do not extract.''')
    if platform.startswith('win'):
        fullparser.add_argument('-f', '--filesystem', default='C',
                help='''The filesystem to use. Defaults to "C"''')
    fullparser.set_defaults(func=run_full_restore)

    # Parser for the browse-files command
    browseparser = subparsers.add_parser('browse-files', help='''Browse the
            archives and the archive's files and choose which to restore.
            ''')
    browseparser.add_argument('-s', '--schedule', choices=['daily',
            'weekly', 'monthly'], help='The type of backup to restore.')
    browseparser.add_argument('-d', '--date', help='''The date the backup
            was made. A string of the format "MM DD YYYY". A value of
            "last" browses the most recent backup.''')
    browseparser.add_argument('--archives', action='store_true',
            help='''Prints the list of archives. If given, all other
            arguments are ignored.''')
    if platform.startswith('win'):
        browseparser.add_argument('r', '--root', default='C',
                help='The root filesystem to restore to. Defaults to "C"')
    else:
        browseparser.add_argument('-r', '--root', default='/',
                help='''The root directory to restore to.''')
    browseparser.set_defaults(func=run_browse_files)

    return mainparser
Esempio n. 11
0
def openfolder(path):
    if platform.startswith('win') or platform == 'cygwin':
        subprocess.Popen(['explorer', '/select,', path])
    elif platform.startswith('linux'):
        path = path.rsplit('/', 1)[0] + '/'
        subprocess.Popen(['xdg-open', path])
    elif platform.startswith('darwin'):
        path = path.rsplit('/', 1)[0] + '/'
        subprocess.Popen(['open', path])
    else:
        raise NotImplementedError
Esempio n. 12
0
def display(image_file_name):
  '''
  opens up the image in the default image viewer.
  '''
  from sys import platform
  from subprocess import call
  if platform.startswith('linux'):
    call(['xdg-open',image_file_name])
  elif platform.startswith('darwin'):
    call(['open',image_file_name])
  elif platform.startswith('win'):
    call(['start', image_file_name], shell=True)
Esempio n. 13
0
    def reconnect_xbee(self):
    #search for available ports
        port_to_connect = ''
        while port_to_connect == '':

            #detect platform and format port names
            if _platform.startswith('win'):
                ports = ['COM%s' % (i + 1) for i in range(256)]
            elif _platform.startswith('linux'):
                # this excludes your current terminal "/dev/tty"
                ports = glob.glob('/dev/ttyUSB*')
            else:
                raise EnvironmentError('Unsupported platform: ' + _platform)

            ports_avail = []

            #loop through all possible ports and try to connect
            for port in ports:
                try:
                    s = serial.Serial(port)
                    s.close()
                    ports_avail.append(port)
                except (OSError, serial.SerialException):
                    pass

            if len(ports_avail) ==1:
                port_to_connect = ports_avail[0]

            elif len(ports_avail)==0:
                #No Serial port found, continue looping.
                print( "No serial port detected. Trying again...")
                time.sleep(1)

            elif len(ports_avail)>1:
                #Multiple serial ports detected. Get user input to decide which one to connect to
                #com_input = raw_input("Multiple serial ports available. Which serial port do you want? \n"+str(self.ports_avail)+":").upper();
                if self.default_serial == None:
                    raise EnvironmentError('Incorrect command line parameters. If there are multiple serial devices, indicate what port you want to be used using --serialport')
                elif self.default_serial.upper() in ports_avail:
                    port_to_connect = self.default_serial.upper()
                else:
                    raise EnvironmentError('Incorrect command line parameters. Serial port is not known as a valid port. Valid ports are:'+ str(ports_avail))

        #connect to xbee or uart
        ser = serial.Serial(port_to_connect, 115200)
        if self.uart_connection:
            self.xbee = UARTConnection(ser)
        else:
            self.xbee = ZigBee(ser)

        print('xbee connected to port ' + port_to_connect)
        return self
Esempio n. 14
0
    def OnPaint(self, event):

        if _plat.startswith('linux'):
            dc = wx.PaintDC(self)
            dc.Clear()
        elif _plat.startswith('darwin'):
            pass
        elif _plat.startswith('win'):
            if USE_BUFFERED_DC:
                dc = wx.BufferedPaintDC(self, self._Buffer)
            else:
                dc = wx.PaintDC(self)
                dc.DrawBitmap(self._Buffer, 0, 0)
                dc.Clear()
 def _getOS(self):
     '''
     Determins the operating system used to run code,
     and returns the terminal exit code to reset terminal features.
     :return: escape code for operating system that resets terminal print config.
     '''
     if platform.startswith("linux"): return self.reset_linux
     elif platform.startswith('darwin'): return self.reset_mac
     elif platform.startswith("win") or platform.startswith("cygwin"):
         return NotImplemented("Windows operating system does not support \
             color print nativly")
     elif platform.startswith("freebsd"): raise NotImplemented("Freebsd os \
             support is not implemented yet")
     else: raise NotImplemented("Could not find os type")
Esempio n. 16
0
def speak(what):
	if _platform.startswith("linux"):
		# linux
		import subprocess
		subprocess.call(['speech-dispatcher'])
		subprocess.call(['spd-say', what])
	elif _platform.startswith("darwin"):
		# MAC OS X
		os.system("say -v Fred " + what)
	elif _platform == "win32":
		# Windows
		import winsound
		freq = 2500 # Set Frequency To 2500 Hertz
		dur = 1000 # Set Duration To 1000 ms == 1 second
		winsound.Beep(freq, dur)
Esempio n. 17
0
def test_issue_65(sftpserver):
    '''using the .cd() context manager prior to setting a dir via chdir
    causes an error'''
    with sftpserver.serve_content(VFS):
        cnn = conn(sftpserver)
        cnn['default_path'] = None  # don't call .chdir by setting default_path
        with pysftp.Connection(**cnn) as sftp:
            assert sftp.getcwd() is None
            with sftp.cd('/home/test/pub'):
                pass

            if platform.startswith('linux'):
                assert sftp.getcwd() == '/'
            elif platform.startswith('win32'):
                assert sftp.getcwd() is None
def check_platform():

    # check target is 'winXX'

    if not platform.startswith('win'):
        print '\t[!] Not a Windows system!, exiting'
        exit(1)
Esempio n. 19
0
    def open_dir_file(self, target):
        """Open a file or a directory in the explorer of the operating system."""
        # check if the file or the directory exists
        if not path.exists(target):
            raise IOError('No such file: {0}'.format(target))

        # check the read permission
        if not access(target, R_OK):
            raise IOError('Cannot access file: {0}'.format(target))

        # open the directory or the file according to the os
        if opersys == 'win32':  # Windows
            proc = startfile(path.realpath(target))

        elif opersys.startswith('linux'):  # Linux:
            proc = subprocess.Popen(['xdg-open', target],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)

        elif opersys == 'darwin':  # Mac:
            proc = subprocess.Popen(['open', '--', target],
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)

        else:
            raise NotImplementedError(
                "Your `%s` isn't a supported operating system`." % opersys)

        # end of function
        return proc
Esempio n. 20
0
    def _install_android_sdk(self):
        sdk_dir = self.android_sdk_dir
        if self.buildozer.file_exists(sdk_dir):
            self.buildozer.info('Android SDK found at {0}'.format(sdk_dir))
            return sdk_dir

        self.buildozer.info('Android SDK is missing, downloading')
        if platform in ('win32', 'cygwin'):
            archive = 'android-sdk_r{0}-windows.zip'
            unpacked = 'android-sdk-windows'
        elif platform in ('darwin', ):
            archive = 'android-sdk_r{0}-macosx.zip'
            unpacked = 'android-sdk-macosx'
        elif platform.startswith('linux'):
            archive = 'android-sdk_r{0}-linux.tgz'
            unpacked = 'android-sdk-linux'
        else:
            raise SystemError('Unsupported platform: {0}'.format(platform))

        archive = archive.format(self.android_sdk_version)
        url = 'http://dl.google.com/android/'
        self.buildozer.download(url, archive,
                cwd=self.buildozer.global_platform_dir)

        self.buildozer.info('Unpacking Android SDK')
        self.buildozer.file_extract(archive,
                cwd=self.buildozer.global_platform_dir)
        self.buildozer.file_rename(unpacked, sdk_dir,
                cwd=self.buildozer.global_platform_dir)
        self.buildozer.info('Android SDK installation done.')
        return sdk_dir
Esempio n. 21
0
def _play(soundfile):
    if platform.startswith('win'):
        from winsound import PlaySound, SND_FILENAME, SND_ASYNC
        PlaySound(soundfile, SND_FILENAME|SND_ASYNC)
    elif 'linux' in platform:
        from wave import open as waveOpen
        from ossaudiodev import open as ossOpen
        
        s = waveOpen(soundfile,'rb')
        (nc,sw,fr,nf,comptype, compname) = s.getparams( )
        
        try:
            from ossaudiodev import AFMT_S16_NE
        except ImportError:
            if byteorder == "little":
                AFMT_S16_NE = ossaudiodev.AFMT_S16_LE
            else:
                AFMT_S16_NE = ossaudiodev.AFMT_S16_BE
        
        dsp = None
        try:
            dsp = ossOpen('/dev/dsp','w')
            dsp.setparameters(AFMT_S16_NE, nc, fr)
            data = s.readframes(nf)
            s.close()
            dsp.write(data)
        except IOError:
            print >> stderr,  _("Audio device is busy.")
        finally:
            if dsp:
                dsp.close()
Esempio n. 22
0
def SetViewerUserThread(env,viewername,userfn):
    """Adds a viewer to the environment if one doesn't exist yet and starts it on this thread. Then creates a new thread to call the user-defined function to continue computation.
    This function will return when the viewer and uesrfn exits. If userfn exits first, then will quit the viewer
    """
    if env.GetViewer() is not None or viewername is None:
        userfn()
    viewer = None
    if sysplatformname.startswith('darwin'):
        viewer = openravepy_int.RaveCreateViewer(env,viewername)
    else:
        # create in a separate thread for windows and linux since the signals do not get messed up
        env.SetViewer(viewername)
    if viewer is None:
        userfn()
    # add the viewer before starting the user function
    env.Add(viewer)
    threading = __import__('threading')
    Thread = threading.Thread
    def localuserfn(userfn,viewer):
        try:
            userfn()
        finally:
            # user function quit, so have to destroy the viewer
            viewer.quitmainloop()
    userthread = Thread(target=localuserfn,args=(userfn,viewer))
    userthread.start()
    sig_thread_id = 0
    for tid, tobj in threading._active.items():
        if tobj is userthread:
            sig_thread_id = tid
            break
    try:
        viewer.main(True,sig_thread_id)
    finally:
        userthread.join()
Esempio n. 23
0
    def _install_android_sdk(self):
        sdk_dir = self.android_sdk_dir
        if self.buildozer.file_exists(sdk_dir):
            self.buildozer.info('Android SDK found at {0}'.format(sdk_dir))
            return sdk_dir

        self.buildozer.info('Android SDK is missing, downloading')
        if platform in ('win32', 'cygwin'):
            archive = 'sdk-tools-windows-{}.zip'.format(DEFAULT_SDK_TAG)
            unpacked = 'android-sdk-windows'
        elif platform in ('darwin', ):
            archive = 'sdk-tools-darwin-{}.zip'.format(DEFAULT_SDK_TAG)
            unpacked = 'android-sdk-macosx'
        elif platform.startswith('linux'):
            archive = 'sdk-tools-linux-{}.zip'.format(DEFAULT_SDK_TAG)
            unpacked = 'android-sdk-linux'
        else:
            raise SystemError('Unsupported platform: {0}'.format(platform))

        if not os.path.exists(sdk_dir):
            os.makedirs(sdk_dir)

        url = 'http://dl.google.com/android/repository/'
        self.buildozer.download(url,
                                archive,
                                cwd=sdk_dir)

        self.buildozer.info('Unpacking Android SDK')
        self.buildozer.file_extract(archive,
                                    cwd=sdk_dir)

        self.buildozer.info('Android SDK tools base installation done.')

        return sdk_dir
Esempio n. 24
0
def is_linux():
    """ Returns True if is a windows system
    """
    if platform.startswith("linux"):
        return True

    return False
Esempio n. 25
0
def free_memory():
    """
    Returns the amount of free bytes of memory.
    On failure, returns +inf.

    >>> free_memory() > 0
    True
    """
    if platform.startswith('linux'):
        pattern = re.compile('^MemAvailable: +([0-9]+) kB\n$')
        with open('/proc/meminfo') as meminfo:
            for line in meminfo:
                match = pattern.match(line)
                if not match:
                    continue
                return 1024 * int(match.group(1))
        return INF

    elif platform == "darwin":
        # TODO
        return INF
    elif platform == "win32":
        # TODO
        return INF
    else:
        # unknown platform
        return INF
Esempio n. 26
0
    def _install_android_ndk(self):
        ndk_dir = self.android_ndk_dir
        if self.buildozer.file_exists(ndk_dir):
            self.buildozer.info('Android NDK found at {0}'.format(ndk_dir))
            return ndk_dir

        self.buildozer.info('Android NDK is missing, downloading')
        if platform in ('win32', 'cygwin'):
            #FIXME find a way of checking 32/64 bits os (not sys.maxint)
            archive = 'android-ndk-r{0}-windows-{1}.zip'
            is_64 = False
        elif platform in ('darwin', ):
            archive = 'android-ndk-r{0}-darwin-{1}.tar.bz2'
            is_64 = (os.uname()[4] == 'x86_64')
        elif platform.startswith('linux'):
            archive = 'android-ndk-r{0}-linux-{1}.tar.bz2'
            is_64 = (os.uname()[4] == 'x86_64')
        else:
            raise SystemError('Unsupported platform: {0}'.format(platform))

        architecture = 'x86_64' if is_64 else 'x86'
        unpacked = 'android-ndk-r{0}'
        archive = archive.format(self.android_ndk_version, architecture)
        unpacked = unpacked.format(self.android_ndk_version)
        url = 'http://dl.google.com/android/ndk/'
        self.buildozer.download(url, archive,
                cwd=self.buildozer.global_platform_dir)

        self.buildozer.info('Unpacking Android NDK')
        self.buildozer.file_extract(archive,
                cwd=self.buildozer.global_platform_dir)
        self.buildozer.file_rename(unpacked, ndk_dir,
                cwd=self.buildozer.global_platform_dir)
        self.buildozer.info('Android NDK installation done.')
        return ndk_dir
Esempio n. 27
0
def is_win():
        """ Returns True if is a windows system
        """
        if platform.startswith("win32"):
            return True

        return False
 def __init__(self,name,queue):
     super(KeyboardAndMouseWatcher,self).__init__(name,queue)
     self._queue = queue
     self._mouse_last_x = None
     self._mouse_last_y = None
     if _platform.startswith("linux"):
         self._display = Display()
Esempio n. 29
0
def get_cursor(username="", password="", host="datadb.admsec.wwu.edu",
               port=1521, db="DATAW"):
    """Prompt for username and password if they are not present, and return a
    cursor to the database connection."""

    # Get the username to use for the connection.
    if not username:

        if version_info[0] >= 3:
            get_input = input
        else:
            get_input = raw_input

        username = get_input("Enter Database Username: "******"Enter Password: "******"DRIVER={{Microsoft ODBC for Oracle}};"
                   "SERVER={};UID={};PWD={}".format(host, username, password))
        cnxn = pyodbc.connect(cnxnstr)
    else:
        import cx_Oracle

        dsn = cx_Oracle.makedsn(host, port, db)
        cnxn = cx_Oracle.connect(username, password, dsn)

    # Clear out the password.
    password = ""

    return cnxn.cursor()
Esempio n. 30
0
    def _get_uptime(self):
        from sys import platform

        if platform.startswith("win32"):
            return self._boot_time_windows()

        return self._boot_time_linux()
Esempio n. 31
0
"""Tests for lightgbm.dask module"""

import inspect
import pickle
import random
import socket
from itertools import groupby
from os import getenv
from platform import machine
from sys import platform

import pytest

import lightgbm as lgb

if not platform.startswith('linux'):
    pytest.skip('lightgbm.dask is currently supported in Linux environments',
                allow_module_level=True)
if not lgb.compat.DASK_INSTALLED:
    pytest.skip('Dask is not installed', allow_module_level=True)

import cloudpickle
import dask.array as da
import dask.dataframe as dd
import joblib
import numpy as np
import pandas as pd
import sklearn.utils.estimator_checks as sklearn_checks
from dask.array.utils import assert_eq
from dask.distributed import Client, LocalCluster, default_client, wait
from distributed.utils_test import client, cluster_fixture, gen_cluster, loop
Esempio n. 32
0
    # update conda and pip packages based on flags provided
    conda_packages = CONDA_BASE
    pip_packages = PIP_BASE
    if args.pyspark:
        conda_packages.update(CONDA_PYSPARK)
        conda_packages["pyspark"] = "pyspark=={}".format(args.pyspark_version)
        pip_packages.update(PIP_PYSPARK)
    if args.gpu:
        conda_packages.update(CONDA_GPU)
        pip_packages.update(PIP_GPU)

    # check for os platform support
    if platform == "darwin":
        pip_packages.update(PIP_DARWIN)
    elif platform.startswith("linux"):
        pip_packages.update(PIP_LINUX)
    elif platform == "win32":
        pip_packages.update(PIP_WIN32)
    else:
        raise Exception(
            "Unsupported platform, must be Windows, Linux, or macOS")

    # write out yaml file
    conda_file = "{}.yaml".format(conda_env)
    with open(conda_file, "w") as f:
        for line in HELP_MSG.format(conda_env=conda_env).split("\n"):
            f.write("# {}\n".format(line))
        f.write("name: {}\n".format(conda_env))
        f.write("channels:\n")
        for channel in CHANNELS:
Esempio n. 33
0
    def _run_remote_server(self, options):
        self.remote_server_directory = os.path.join(
            options.remote_server_directory_prefix, options.configuration)
        remote_server_binary = os.path.join(self.remote_server_directory,
                                            options.remote_server_name)

        if not os.path.isfile(remote_server_binary):
            print(
                "Robot framework remote server binary not found: '{}'! Did you forget to bootstrap and build?"
                .format(remote_server_binary))
            sys.exit(1)

        args = [
            remote_server_binary, '--robot-server-port',
            str(options.remote_server_port)
        ]
        if not options.show_monitor:
            args.append('--hide-monitor')
        if not options.show_log:
            args.append('--hide-log')
        if not options.show_analyzers:
            args.append('--hide-analyzers')
        if not options.enable_xwt and not (options.show_analyzers
                                           or options.show_monitor):
            args.append('--disable-xwt')

        if platform.startswith("linux") or platform == "darwin":
            args.insert(0, 'mono')

        if options.port is not None:
            if options.suspend:
                print('Waiting for a debugger at port: {}'.format(
                    options.port))
            args.insert(1, '--debug')
            args.insert(
                2,
                '--debugger-agent=transport=dt_socket,server=y,suspend={0},address=127.0.0.1:{1}'
                .format('y' if options.suspend else 'n', options.port))
        elif options.debug_mode:
            args.insert(1, '--debug')

        if sys.stdin.isatty():
            try:
                for proc in [psutil.Process(pid) for pid in psutil.pids()]:
                    if '--robot-server-port' in proc.cmdline() and str(
                            options.remote_server_port) in proc.cmdline():
                        if not is_process_running(proc.pid):
                            #process is zombie
                            continue
                        print(
                            'It seems that Robot process (pid {}, name {}) is currently running on port {}'
                            .format(proc.pid, proc.name(),
                                    options.remote_server_port))
                        result = raw_input('Do you want me to kill it? [y/N] ')
                        if result in ['Y', 'y']:
                            proc.kill()
                        break
            except:
                # do nothing here
                pass

        if options.run_gdb:
            args = [
                'gdb', '-nx', '-ex',
                'handle SIGXCPU SIG33 SIG35 SIG36 SIGPWR nostop noprint',
                '--args'
            ] + args
        RobotTestSuite.robot_frontend_process = subprocess.Popen(
            args, cwd=self.remote_server_directory, bufsize=1)
Esempio n. 34
0
def add_Last_Slash(pathToAlter):
    if platform.startswith('darwin'):
        return pathToAlter + "/"
    elif platform.startswith('win32'):
        return pathToAlter + "\\"
Esempio n. 35
0
def init(rate=44100, stereo=True, buffer=128):
    """setup the pyo (sound) server
    """
    global pyoSndServer, Sound, audioDriver, duplex, maxChnls
    Sound = SoundPyo
    global pyo
    try:
        assert pyo
    except NameError:  # pragma: no cover
        import pyo
        # can be needed for microphone.switchOn(), which calls init even
        # if audioLib is something else

    # subclass the pyo.Server so that we can insert a __del__ function that
    # shuts it down skip coverage since the class is never used if we have
    # a recent version of pyo

    class _Server(pyo.Server):  # pragma: no cover
        # make libs class variables so they don't get deleted first
        core = core
        logging = logging

        def __del__(self):
            self.stop()
            # make sure enough time passes for the server to shutdown
            self.core.wait(0.5)
            self.shutdown()
            # make sure enough time passes for the server to shutdown
            self.core.wait(0.5)
            # this may never get printed
            self.logging.debug('pyo sound server shutdown')

    if '.'.join(map(str, pyo.getVersion())) < '0.6.4':
        Server = _Server
    else:
        Server = pyo.Server

    # if we already have a server, just re-initialize it
    if 'pyoSndServer' in globals() and hasattr(pyoSndServer, 'shutdown'):
        pyoSndServer.stop()
        # make sure enough time passes for the server to shutdown
        core.wait(0.5)
        pyoSndServer.shutdown()
        core.wait(0.5)
        pyoSndServer.reinit(sr=rate,
                            nchnls=maxChnls,
                            buffersize=buffer,
                            audio=audioDriver)
        pyoSndServer.boot()
    else:
        if platform == 'win32':
            # check for output device/driver
            devNames, devIDs = get_output_devices()
            audioDriver, outputID = _bestDriver(devNames, devIDs)
            if outputID is None:
                # using the default output because we didn't find the one(s)
                # requested
                audioDriver = 'Windows Default Output'
                outputID = pyo.pa_get_default_output()
            if outputID is not None:
                logging.info(u'Using sound driver: %s (ID=%i)' %
                             (audioDriver, outputID))
                maxOutputChnls = pyo.pa_get_output_max_channels(outputID)
            else:
                logging.warning(
                    'No audio outputs found (no speakers connected?')
                return -1
            # check for valid input (mic)
            # If no input device is available, devNames and devIDs are empty
            # lists.
            devNames, devIDs = get_input_devices()
            audioInputName, inputID = _bestDriver(devNames, devIDs)
            # Input devices were found, but requested devices were not found
            if len(devIDs) > 0 and inputID is None:
                defaultID = pyo.pa_get_default_input()
                if defaultID is not None and defaultID != -1:
                    # default input is found
                    # use the default input because we didn't find the one(s)
                    # requested
                    audioInputName = 'Windows Default Input'
                    inputID = defaultID
                else:
                    # default input is not available
                    inputID = None
            if inputID is not None:
                msg = u'Using sound-input driver: %s (ID=%i)'
                logging.info(msg % (audioInputName, inputID))
                maxInputChnls = pyo.pa_get_input_max_channels(inputID)
                duplex = bool(maxInputChnls > 0)
            else:
                maxInputChnls = 0
                duplex = False
        # for other platforms set duplex to True (if microphone is available)
        else:
            audioDriver = prefs.hardware['audioDriver'][0]
            maxInputChnls = pyo.pa_get_input_max_channels(
                pyo.pa_get_default_input())
            maxOutputChnls = pyo.pa_get_output_max_channels(
                pyo.pa_get_default_output())
            duplex = bool(maxInputChnls > 0)

        maxChnls = min(maxInputChnls, maxOutputChnls)
        if maxInputChnls < 1:  # pragma: no cover
            msg = (u'%s.init could not find microphone hardware; '
                   u'recording not available')
            logging.warning(msg % __name__)
            maxChnls = maxOutputChnls
        if maxOutputChnls < 1:  # pragma: no cover
            msg = (u'%s.init could not find speaker hardware; '
                   u'sound not available')
            logging.error(msg % __name__)
            return -1

        # create the instance of the server:
        if platform == 'darwin' or platform.startswith('linux'):
            # for mac/linux we set the backend using the server audio param
            pyoSndServer = Server(sr=rate,
                                  nchnls=maxChnls,
                                  buffersize=buffer,
                                  audio=audioDriver)
        else:
            # with others we just use portaudio and then set the OutputDevice
            # below
            pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer)

        pyoSndServer.setVerbosity(1)
        if platform == 'win32':
            pyoSndServer.setOutputDevice(outputID)
            if inputID is not None:
                pyoSndServer.setInputDevice(inputID)
        # do other config here as needed (setDuplex? setOutputDevice?)
        pyoSndServer.setDuplex(duplex)
        pyoSndServer.boot()
    core.wait(0.5)  # wait for server to boot before starting the sound stream
    pyoSndServer.start()

    #atexit is filo, will call stop then shutdown upon closing
    atexit.register(pyoSndServer.shutdown)
    atexit.register(pyoSndServer.stop)
    try:
        Sound()  # test creation, no play
    except pyo.PyoServerStateException:
        msg = "Failed to start pyo sound Server"
        if platform == 'darwin' and audioDriver != 'portaudio':
            msg += "; maybe try prefs.general.audioDriver 'portaudio'?"
        logging.error(msg)
        core.quit()
    logging.debug('pyo sound server started')
    logging.flush()
Esempio n. 36
0
    def __init__(self, path_root=None):
        self.TwitchChannel = ""
        self.TwitchOAUTH = ""
        self.TwitchBotChannel = ""
        self.TwitchBotOAUTH = ""
        self.UseChatbot = False
        self.CurrentMascot = ""
        self.AlignMascot = ""
        self.HostMessage = ""
        self.AutohostMessage = ""
        self.FollowMessage = ""
        self.MinBits = 0
        self.AutoShoutout = False
        self.AutoShoutoutTime = 10
        self.ShoutoutAccess = "mod"
        self.GlobalVolume = 0.2
        self.NanoleafEnabled = False
        self.NanoleafIP = ""
        self.NanoleafToken = ""
        self.HueEnabled = False
        self.HueIP = ""
        self.HueToken = ""
        self.YeelightEnabled = False

        self.Styles = {}
        self.Activities = {}
        self.Enabled = {}
        self.Commands = {}
        self.Messages = {}
        self.PoseMapping = {}
        self.Bots = []
        self.ScheduledMessages = []
        self.CustomBits = []
        self.CustomSubs = []
        self.Watchdog = []
        self.scheduleTable = {}
        self.scheduleLines = 0

        self.mascotImages = {}
        self.mascotAudio = {}
        self.mascotStyles = {}

        self.twitch_client_id = "zpm94cuvrntu030mauvxvz9cv2ldja"
        self.commonBots = [
            "nightbot", "streamlabs", "streamelements", "stay_hydrated_bot",
            "botisimo", "wizebot", "moobot"
        ]
        self.encoding = "utf-8-sig"
        # Detect OS
        if platform.startswith('win'):
            self.os = 'win'
            self.slash = '\\'
        elif platform.startswith('freebsd') or platform.startswith('linux'):
            self.os = 'lx'
            self.slash = '/'
        elif platform.startswith('darwin'):
            self.os = 'osx'
            self.slash = '/'
        else:
            print("Failed to detect OS: {}".format(platform))
            exit(1)

        # Check paths
        self.pathRoot = path_root + self.slash
        self.configFile = self.pathRoot + "settings.json"
        if not path.isdir(self.pathRoot):
            print("Working directory not detected.")
            exit(1)
        if not path.isfile(self.pathRoot + "wooferbot.py") and not path.isfile(
                self.pathRoot +
                "wooferbot_cli.exe") and not path.isfile(self.pathRoot +
                                                         "wooferbot_cli"):
            print("Working directory incorrect.")
            exit(1)
        if not path.isfile(self.configFile):
            print("Configuration file is missing, recreating with defaults.")

        self.reload()
        self.reload_mascot()
Esempio n. 37
0
def main_flow(*args: [argparse_namespace_object, Union[bytes, str]]):
    """Main application function.

    :param args: object <class 'argparse.Namespace'>,
    for tests param args - list with objects of <class 'str'>
    :return:
    Returns the processed data as text to the screen.
    Total number of files, table or list with file paths.
    Returns parser.exit(status=1):
    if path does not exist or there may be a typo in it,
    if the path has hidden folders and the argument --all is not specified,
    if the preview is not available for the specified file type.
    """
    args = parser.parse_args(*args)
    recursive = not args.no_recursion
    include_hidden = args.all
    sort_alpha = args.sort_alpha
    extension = args.file_extension
    current_os = get_current_os()
    if current_os.name == 'BaseOS':
        # the default option to exclude hidden files and folders is not implemented for undefined OS,
        # no need to call self.is_hidden_file_or_dir()
        include_hidden = True

    if args.supported_types:
        parser.exit(status=0, message=SUPPORTED_TYPE_INFO_MESSAGE)

    if args.help_cmd:
        hc = HelpCmd()
        hc.cmdloop()
        parser.exit(status=0)

    if os.path.abspath(args.path) == os.getcwd():
        location = os.getcwd()
        loc_text = ' the current directory'
    else:
        location = os.path.expanduser(args.path)
        loc_text = ':\n' + os.path.normpath(location)

    if not os.path.exists(location):
        parser.exit(status=1,
                    message=f'The path {location} '
                    f'does not exist, or there may be a typo in it.')

    if not include_hidden and current_os.is_hidden_file_or_dir(location):
        # skip check if path is a local drive
        if platform.startswith('win') and len(Path(location).parents) == 0:
            pass
        else:
            parser.exit(
                status=1,
                message=f'\nNot counting any files, because {loc_text[2:]}'
                f' has hidden folders.\n'
                f'Use the --all argument to include hidden files and folders.')

    print("")
    # Parser total_group
    # getting the total number of files for -t .. (all extensions), -t . and -t extension_name
    if args.extension:
        print(fill(show_start_message(args.extension, args.case_sensitive,
                                      recursive, include_hidden, location,
                                      'total'),
                   width=START_TEXT_WIDTH),
              end="\n\n")
        data = current_os.search_files(dirpath=location,
                                       extension=args.extension,
                                       include_hidden=include_hidden,
                                       recursive=recursive,
                                       case_sensitive=args.case_sensitive)
        total_result = show_result_for_total(data,
                                             total_size=args.total_size,
                                             show_folders=args.show_folders,
                                             no_feedback=args.no_feedback,
                                             recursive=recursive)
        return total_result

    # Parser search_group: search file names by pattern, --filename-match
    if args.pattern:
        print(fill(show_start_message(args.pattern, args.case_sensitive,
                                      recursive, include_hidden, location,
                                      'pattern'),
                   width=START_TEXT_WIDTH),
              end="\n\n")

        # getting data list with Unix shell-style wildcards: *, ?, [seq], [!seq]
        data = current_os.search_files_by_pattern(
            dirpath=location,
            pattern=args.pattern,
            recursive=recursive,
            include_hidden=include_hidden,
            case_sensitive=args.case_sensitive)

        # preview behavior is similar to --file-extension .. (all extensions)
        # in this case, the preview will only be displayed for files with a supported extension
        len_files = show_result_for_search_files(
            files=data,
            file_sizes=args.file_sizes,
            preview=args.preview,
            preview_size=args.preview_size)

        return len_files

    # Parser search_group: search and list files by extension, --file-extension
    if extension:
        print(fill(show_start_message(extension, args.case_sensitive,
                                      recursive, include_hidden, location),
                   width=START_TEXT_WIDTH),
              end="\n\n")
        if args.preview:
            if extension == '.' or not is_supported_filetype(
                    extension.lower()):
                parser.exit(status=1, message=NOT_SUPPORTED_TYPE_MESSAGE)

        # getting data list for -fe .. (all extensions), -fe . and -fe extension_name
        data = (f for f in current_os.search_files(
            dirpath=location,
            extension=extension,
            include_hidden=include_hidden,
            recursive=recursive,
            case_sensitive=args.case_sensitive))
        # display the result as a list
        len_files = show_result_for_search_files(
            files=data,
            file_sizes=args.file_sizes,
            preview=args.preview,
            preview_size=args.preview_size)

        return len_files

    # Parser count_group: counting all files by extension
    print(fill(show_start_message(None, args.case_sensitive, recursive,
                                  include_hidden, location),
               width=START_TEXT_WIDTH),
          end="\n\n")
    data = current_os.count_files_by_extension(
        dirpath=location,
        no_feedback=args.no_feedback,
        include_hidden=include_hidden,
        recursive=recursive,
        case_sensitive=args.case_sensitive)

    # if empty sequence
    if not data:
        parser.exit(
            status=0,
            message='No files were found in the specified directory.\n')

    total_occurrences = sum(data.values())
    max_word_width = max(map(len, data.keys()))

    # display the result as a list of two columns
    if args.group:
        if sort_alpha:
            # sort extensions alphabetically, with uppercase versions on top
            sort_key = lambda data: (data[0].casefold(), data[0])
            data = sorted(data.items(), key=sort_key)
            show_ext_grouped_by_type(data=data,
                                     ext_and_group=ext_and_group_dict)
        else:
            # sort extensions by group and by frequency in each group
            show_ext_grouped_by_type(data=data.most_common(),
                                     ext_and_group=ext_and_group_dict)
        print(f'\n  Found {total_occurrences} file(s).')
        parser.exit(status=0)
    # display the result as a table
    elif sort_alpha:
        # sort extensions alphabetically, with uppercase versions on top
        sort_key = lambda data: (data[0].casefold(), data[0])
        data = sorted(data.items(), key=sort_key)
        show_2columns(data, max_word_width, total_occurrences)
        parser.exit(status=0)
    else:
        # sort extensions by frequency for each file extension
        data = data.most_common()
        show_2columns(data, max_word_width, total_occurrences)
        parser.exit(status=0)
Esempio n. 38
0
class UpdateLiveStatsTestCase(unittest.TestCase):
    config = {
        'min_interval': 20,
        'stats': ['login', 'username', 'pokemon_evolved', 'pokemon_encountered', 'uptime',
                  'pokemon_caught', 'stops_visited', 'km_walked', 'level', 'stardust_earned',
                  'level_completion', 'xp_per_hour', 'pokeballs_thrown', 'highest_cp_pokemon',
                  'level_stats', 'xp_earned', 'pokemon_unseen', 'most_perfect_pokemon',
                  'pokemon_stats', 'pokemon_released', 'captures_per_hour'],
        'terminal_log': True,
        'terminal_title': False
    }
    # updated to account for XP levels
    player_stats = {
        'level': 25,
        'prev_level_xp': 710000,
        'next_level_xp': 900000,
        'experience': 753700
    }

    def setUp(self):
        self.bot = FakeBot()
        self.bot._player = {'username': '******'}
        self.bot.config.username = '******'
        self.worker = UpdateLiveStats(self.bot, self.config)

    def mock_metrics(self):
        self.bot.metrics = MagicMock()
        self.bot.metrics.runtime.return_value = timedelta(hours=15, minutes=42, seconds=13)
        self.bot.metrics.distance_travelled.return_value = 42.05
        self.bot.metrics.xp_per_hour.return_value = 1337.42
        self.bot.metrics.xp_earned.return_value = 424242
        self.bot.metrics.visits = {'latest': 250, 'start': 30}
        self.bot.metrics.num_encounters.return_value = 130
        self.bot.metrics.num_captures.return_value = 120
        self.bot.metrics.captures_per_hour.return_value = 75
        self.bot.metrics.releases = 30
        self.bot.metrics.num_evolutions.return_value = 12
        self.bot.metrics.num_new_mons.return_value = 3
        self.bot.metrics.num_throws.return_value = 145
        self.bot.metrics.earned_dust.return_value = 24069
        self.bot.metrics.highest_cp = {'desc': 'highest_cp'}
        self.bot.metrics.most_perfect = {'desc': 'most_perfect'}

    def test_config(self):
        self.assertEqual(self.worker.min_interval, self.config['min_interval'])
        self.assertEqual(self.worker.displayed_stats, self.config['stats'])
        self.assertEqual(self.worker.terminal_title, self.config['terminal_title'])
        self.assertEqual(self.worker.terminal_log, self.config['terminal_log'])

    def test_should_display_no_next_update(self):
        self.worker.next_update = None

        self.assertTrue(self.worker._should_display())

    @patch('pokemongo_bot.cell_workers.update_live_stats.datetime')
    def test_should_display_no_terminal_log_title(self, mock_datetime):
        # _should_display should return False if both terminal_title and terminal_log are false
        # in configuration, even if we're past next_update.
        now = datetime.now()
        mock_datetime.now.return_value = now + timedelta(seconds=20)
        self.worker.next_update = now
        self.worker.terminal_log = False
        self.worker.terminal_title = False

        self.assertFalse(self.worker._should_display())

    @patch('pokemongo_bot.cell_workers.update_live_stats.datetime')
    def test_should_display_before_next_update(self, mock_datetime):
        now = datetime.now()
        mock_datetime.now.return_value = now - timedelta(seconds=20)
        self.worker.next_update = now

        self.assertFalse(self.worker._should_display())

    @patch('pokemongo_bot.cell_workers.update_live_stats.datetime')
    def test_should_display_after_next_update(self, mock_datetime):
        now = datetime.now()
        mock_datetime.now.return_value = now + timedelta(seconds=20)
        self.worker.next_update = now

        self.assertTrue(self.worker._should_display())

    @patch('pokemongo_bot.cell_workers.update_live_stats.datetime')
    def test_should_display_exactly_next_update(self, mock_datetime):
        now = datetime.now()
        mock_datetime.now.return_value = now
        self.worker.next_update = now

        self.assertTrue(self.worker._should_display())

    @patch('pokemongo_bot.cell_workers.update_live_stats.datetime')
    def test_compute_next_update(self, mock_datetime):
        now = datetime.now()
        mock_datetime.now.return_value = now
        old_next_display_value = self.worker.next_update
        self.worker._compute_next_update()

        self.assertNotEqual(self.worker.next_update, old_next_display_value)
        self.assertEqual(self.worker.next_update,
                         now + timedelta(seconds=self.config['min_interval']))

    @patch('pokemongo_bot.cell_workers.update_live_stats.stdout')
    @patch('pokemongo_bot.cell_workers.UpdateLiveStats._compute_next_update')
    def test_update_title_linux_cygwin(self, mock_compute_next_update, mock_stdout):
        self.worker._update_title('new title linux', 'linux')

        self.assertEqual(mock_stdout.write.call_count, 1)
        self.assertEqual(mock_stdout.write.call_args, call('\x1b]2;new title linux\x07'))
        self.assertEqual(mock_compute_next_update.call_count, 1)

        self.worker._update_title('new title linux2', 'linux2')

        self.assertEqual(mock_stdout.write.call_count, 2)
        self.assertEqual(mock_stdout.write.call_args, call('\x1b]2;new title linux2\x07'))
        self.assertEqual(mock_compute_next_update.call_count, 2)

        self.worker._update_title('new title cygwin', 'cygwin')

        self.assertEqual(mock_stdout.write.call_count, 3)
        self.assertEqual(mock_stdout.write.call_args, call('\x1b]2;new title cygwin\x07'))
        self.assertEqual(mock_compute_next_update.call_count, 3)

    @patch('pokemongo_bot.cell_workers.update_live_stats.stdout')
    @patch('pokemongo_bot.cell_workers.UpdateLiveStats._compute_next_update')
    def test_update_title_darwin(self, mock_compute_next_update, mock_stdout):
        self.worker._update_title('new title darwin', 'darwin')

        self.assertEqual(mock_stdout.write.call_count, 1)
        self.assertEqual(mock_stdout.write.call_args, call('\033]0;new title darwin\007'))
        self.assertEqual(mock_compute_next_update.call_count, 1)

    @unittest.skipUnless(_platform.startswith("win"), "requires Windows")
    @patch('pokemongo_bot.cell_workers.update_live_stats.ctypes')
    @patch('pokemongo_bot.cell_workers.UpdateLiveStats._compute_next_update')
    def test_update_title_win32(self, mock_compute_next_update, mock_ctypes):
        self.worker._update_title('new title win32', 'win32')

        self.assertEqual(mock_ctypes.windll.kernel32.SetConsoleTitleA.call_count, 1)
        self.assertEqual(mock_ctypes.windll.kernel32.SetConsoleTitleA.call_args,
                         call('new title win32'))
        self.assertEqual(mock_compute_next_update.call_count, 1)

    @patch('pokemongo_bot.cell_workers.update_live_stats.BaseTask.emit_event')
    @patch('pokemongo_bot.cell_workers.UpdateLiveStats._compute_next_update')
    def test_log_on_terminal(self, mock_compute_next_update, mock_emit_event):
        #self.worker._log_on_terminal('stats')

        self.assertEqual(mock_emit_event.call_count, 0)
        #self.assertEqual(mock_emit_event.call_args,
        #                 call('log_stats', data={'stats': 'stats', 'stats_raw':'stats_raw'}, formatted='{stats},{stats_raw}'))
        self.assertEqual(mock_compute_next_update.call_count, 0)

    def test_get_stats_line_player_stats_none(self):
        line = self.worker._get_stats_line(None)

        self.assertEqual(line, '')

    def test_get_stats_line_no_displayed_stats(self):
        self.mock_metrics()

        self.worker.displayed_stats = []
        line = self.worker._get_stats_line(self.worker._get_stats(self.player_stats))

        self.assertEqual(line, '')

    def test_get_stats_line(self):
        self.mock_metrics()

        line = self.worker._get_stats_line(self.worker._get_stats(self.player_stats))
        expected = 'Login | Username | Evolved 12 pokemon | Encountered 130 pokemon | ' \
                   'Uptime : 15:42:13 | Caught 120 pokemon | Visited 220 stops | ' \
                   '42.05km walked | Level 25 | Earned 24,069 Stardust | ' \
                   '43,700 / 190,000 XP (23%) | 1,337 XP/h | Threw 145 pokeballs | ' \
                   'Highest CP pokemon : highest_cp | Level 25 (43,700 / 190,000, 23%) | ' \
                   '+424,242 XP | Encountered 3 new pokemon | ' \
                   'Most perfect pokemon : most_perfect | ' \
                   'Encountered 130 pokemon, 120 caught, 30 released, 12 evolved, ' \
                   '3 never seen before | Released 30 pokemon | 75 pokemon/h'

        self.assertEqual(line, expected)
Esempio n. 39
0
from setuptools import setup
from sys import platform


if platform.startswith('win'):
    import py2exe

# set up common things
APP = ['IDFVersionUpdater.py']

# then setup specific things
py2app_options = {'argv_emulation': True,
                  'includes': ['wx', 'subprocess'],
                  'iconfile': 'resources/ep-logo-3d-transparent.icns'}
setup(
    name='idfversionupdater',
    description='A wxPython-based tool for transition EnergyPlus input files',
    url='https://github.com/myoldmopar/idfversionupdater2',
    author='Edwin Lee via NREL via United States Department of Energy',
    app=APP,
    options={'py2app': py2app_options},
    version="2.0.0",
    console='IDFVersionUpdator',
)

# TODO: Fix cross platform support

                       (2, numpy.int64, 66)]

    for idx, int_type, bit_exponent in test_parameters:
        test_df = DataFrame(numpy.arange(7, 11), dtype=int_type)
        model = DataFrameModel(test_df.copy())
        index = model.createIndex(2, 0)
        assert not model.setData(index, str(int(2**bit_exponent)))
        MockQMessageBox.critical.assert_called_with(ANY, "Error", ANY)
        assert MockQMessageBox.critical.call_count == idx
        assert numpy.sum(
            test_df[0].as_matrix() == model.df.as_matrix()) == len(test_df)


@flaky(max_runs=3)
@pytest.mark.skipif(os.environ.get('CI', None) is None
                    and platform.startswith('linux'),
                    reason="Fails on some Linux platforms locally.")
def test_dataframeeditor_edit_overflow(qtbot, monkeypatch):
    """Test #6114: Entry of an overflow int is caught and handled properly"""
    MockQMessageBox = Mock()
    attr_to_patch = ('spyder.widgets.variableexplorer' +
                     '.dataframeeditor.QMessageBox')
    monkeypatch.setattr(attr_to_patch, MockQMessageBox)

    # Numpy doesn't raise the OverflowError for ints smaller than 64 bits
    if platform.startswith('linux'):
        int32_bit_exponent = 66
    else:
        int32_bit_exponent = 34
    test_parameters = [(1, numpy.int32, int32_bit_exponent),
                       (2, numpy.int64, 66)]
Esempio n. 41
0
#       have entirely different names. The right way would be to fetch pin
#       names from the compiler environment and/or header files.
pinNames = ["AIO%d" % x for x in range(16)] + \
           ["DIO%d" % x for x in range(64)] + \
           ["P%c%d" % (c, x) for c in range(ord('A'), ord('L') + 1) \
                             for x in range(8)]

sensorTypes = {'MAX6675': "TT_MAX6675", 'Thermistor': "TT_THERMISTOR",
               'AD595': "TT_AD595", 'PT100': "TT_PT100",
               'Intercom': "TT_INTERCOM", 'MCP3008': "TT_MCP3008"}

BSIZE = (100, 60)
BSIZESMALL = (90, 30)


if platform.startswith("win"):
  offsetTcLabel = 4
  offsetChLabel = 4
else:
  offsetTcLabel = 6
  offsetChLabel = 8

TYPE_GENERAL = 0
TYPE_FLOAT = 1

reDefQSm = re.compile("\s*#define\s+(\S+)\s+(.*)")
reDefQSm2 = re.compile("\s*(\"[^\"]*\")")

reInclude = re.compile("^\s*#include\s+\"([^\"]*)")
reFloatAttr = re.compile("/\*\s*float\s*\*/")
reDefine = re.compile("\s*#define\s+(\w+)\s+(\S+)")
Esempio n. 42
0
COMMAND += ['-v', OUTPUT_DIR + ':/OUTPUT_DIR']
if CN_FILE is not None:  # mount contact network file (if need be)
    COMMAND += ['-v', CN_FILE + ':' + CONFIG_DICT['contact_network_file']]
if TN_FILE is not None:  # mount transmission network file (if need be)
    COMMAND += ['-v', TN_FILE + ':' + CONFIG_DICT['transmission_network_file']]
if SAMPLE_TIME_FILE is not None:
    COMMAND += ['-v', SAMPLE_TIME_FILE + ':' + CONFIG_DICT['sample_time_file']]
if TREE_FILE is not None:
    COMMAND += ['-v', TREE_FILE + ':' + CONFIG_DICT['tree_file']]
if ERRORFREE_SEQ_FILE is not None:
    COMMAND += [
        '-v', ERRORFREE_SEQ_FILE + ':' + CONFIG_DICT['errorfree_sequence_file']
    ]
if HMMBUILD_MSA_FILE is not None:
    COMMAND += [
        '-v', HMMBUILD_MSA_FILE + ':' + CONFIG_DICT['hmmbuild_msafile']
    ]
if not platform.startswith('win'):  # if not Windows,
    from os import geteuid, getegid
    COMMAND += ['-u', str(geteuid()) + ':' + str(getegid())
                ]  # make output files owned by user instead of root
COMMAND += [version]  # Docker image
try:
    if args.verbose:
        print("\n\nRunning FAVITES Docker command:\n%s\n\n" %
              ' '.join(COMMAND))
    call(COMMAND)
except:
    exit(-1)
TMP_CONFIG.close()
Esempio n. 43
0
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from sys import platform
from os import system

win = platform.startswith("win")
darwin = platform.startswith("darwin")
lin = platform.startswith("lin")


def clear():
    '''
    Clears Console
    '''
    if win:
        system("CLS")
    else:
        system("clear")


def map(value, old_min, old_max, new_min, new_max):
Esempio n. 44
0
from sys import platform
if (not platform.startswith("linux")):
    raise (Exception("Interface not supported by OS."))

from veripy.networking.interface_adapter import InterfaceAdapter
from scapy.arch.linux import get_if_list, get_if, SIOCGIFFLAGS, IFF_UP
import struct


class NixInterfaceAdapter(InterfaceAdapter):
    """
	A NetworkInterface is an class used to implement OS-specific network interface functionality required to communicate with a node.
	"""
    @classmethod
    def get_physical_interfaces(cls):
        """
		Used to retrieve a list of active physical network interfaces, such as eth0, wlan1 etc.

		Returns:        an array of strings such as 'eth0', 'wlan0'
		"""
        interfaces = get_if_list()
        active_interfaces = []
        for i in interfaces:
            if (struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
                    & IFF_UP) and i <> "lo":
                active_interfaces.append(i)
        return active_interfaces
Esempio n. 45
0
def link_flags():
    flags = "-lQt5Core -lQt5Gui -lQt5Widgets"
    if _platform.startswith('linux'):
        flags += " -lstdc++"
    return flags
Esempio n. 46
0
def install_software_updates(remote_version, base_dir, window):
    mkdir(f'{base_dir}/tmp')

    if platform.startswith('win'):
        try:
            exe = get(
                f'https://github.com/YariKartoshe4ka/Space-Way/releases/download/{remote_version}/Space-Way-{remote_version}-portable.exe'
            )
            zip = get(
                f'https://github.com/YariKartoshe4ka/Space-Way/archive/{remote_version}.zip'
            )
        except:
            quit(window)

        unlink(f'{base_dir}/Space Way.exe')
        with open(f'{base_dir}/Space Way.exe', 'wb') as file:
            file.write(exe.content)

        with open(f'{base_dir}/tmp/update.zip', 'wb') as file:
            file.write(zip.content)

        with ZipFile(f'{base_dir}/tmp/update.zip') as file:
            file.extractall(f'{base_dir}/tmp/')

        rmtree(f'{base_dir}/assets')
        unlink(f'{base_dir}/icon.ico')
        unlink(f'{base_dir}/config/config.json')

        copytree(f'{base_dir}/tmp/Space-Way-{remote_version}/assets',
                 f'{base_dir}/assets')

        copyfile(
            f'{base_dir}/tmp/Space-Way-{remote_version}/config/config.json',
            f'{base_dir}/config/config.json')
        copyfile(f'{base_dir}/tmp/Space-Way-{remote_version}/icon.ico',
                 f'{base_dir}/icon.ico')

        quit(window)

    elif platform.startswith('linux') or platform == 'darwin':
        try:
            zip = get(
                f'https://github.com/YariKartoshe4ka/Space-Way/archive/{remote_version}.zip'
            )
        except:
            quit(window)

        with open(f'{base_dir}/tmp/update.zip', 'wb') as file:
            file.write(zip.content)

        with ZipFile(f'{base_dir}/tmp/update.zip') as file:
            file.extractall(f'{base_dir}/tmp/')

        Popen([
            'pip3', 'install', '-r',
            f'{base_dir}/tmp/Space-Way-{remote_version}/requirements.txt'
        ]).wait()

        rmtree(f'{base_dir}/assets')
        rmtree(f'{base_dir}/scenes')
        unlink(f'{base_dir}/main.py')
        unlink(f'{base_dir}/icon.ico')
        unlink(f'{base_dir}/config/config.json')

        copytree(f'{base_dir}/tmp/Space-Way-{remote_version}/assets',
                 f'{base_dir}/assets')
        copytree(f'{base_dir}/tmp/Space-Way-{remote_version}/scenes',
                 f'{base_dir}/scenes')
        copyfile(f'{base_dir}/tmp/Space-Way-{remote_version}/main.py',
                 f'{base_dir}/main.py')
        copyfile(f'{base_dir}/tmp/Space-Way-{remote_version}/icon.ico',
                 f'{base_dir}/icon.ico')
        copyfile(
            f'{base_dir}/tmp/Space-Way-{remote_version}/config/config.json',
            f'{base_dir}/config/config.json')

        quit(window)
Esempio n. 47
0
    def Run(self):
        if platform.startswith("win"):
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= STARTF_USESHOWWINDOW

        for cmd in self.script:
            evt = scriptEvent(msg=cmd, state=SCRIPT_RUNNING)
            wx.PostEvent(self.win, evt)
            args = shlex.split(str(cmd))
            try:
                if platform.startswith("win"):
                    p = subprocess.Popen(args,
                                         stderr=subprocess.STDOUT,
                                         stdout=subprocess.PIPE,
                                         startupinfo=startupinfo)
                else:
                    p = subprocess.Popen(args,
                                         stderr=subprocess.STDOUT,
                                         stdout=subprocess.PIPE)
            except:
                evt = scriptEvent(
                    msg="Exception occurred trying to run\n\n%s" % cmd,
                    state=SCRIPT_CANCELLED)
                wx.PostEvent(self.win, evt)
                self.running = False
                return
            obuf = ''
            while not self.cancelled:
                o = p.stdout.read(1)
                if o == '': break
                if o == '\r' or o == '\n':
                    if obuf.strip() != "":
                        evt = scriptEvent(msg=obuf, state=SCRIPT_RUNNING)
                        wx.PostEvent(self.win, evt)
                    obuf = ''
                elif ord(o) < 32:
                    pass
                else:
                    obuf += o

            if self.cancelled:
                evt = scriptEvent(msg=None, state=SCRIPT_CANCELLED)
                wx.PostEvent(self.win, evt)
                p.kill()
                self.running = False
                p.wait()
                return

            rc = p.wait()
            if rc != 0:
                msg = "RC = " + str(rc) + " - Build terminated"
                evt = scriptEvent(msg=msg, state=SCRIPT_CANCELLED)
                wx.PostEvent(self.win, evt)
                self.running = False
                return

            evt = scriptEvent(msg="", state=SCRIPT_RUNNING)
            wx.PostEvent(self.win, evt)

        evt = scriptEvent(msg=None, state=SCRIPT_FINISHED)
        wx.PostEvent(self.win, evt)

        self.running = False
Esempio n. 48
0
from sys import platform

if platform.startswith('linux'):
    from veripy.networking.arch.nix import NixInterfaceAdapter as OSInterfaceAdapter
elif platform.startswith('win32'):
    from veripy.networking.arch.nt import NtInterfaceAdapter as OSInterfaceAdapter
else:
    raise (Exception("OS not supported."))

__all__ = ['OSInterfaceAdapter']
Esempio n. 49
0
def is_int(s):
    try:
        return int(s) == float(s)
    except:
        return False


# Natural Sorting key
def natsort(s):
    return [int(i) if i.isdigit() else i for i in re.split(r'(\d+)', s)]


# check os is windows
from sys import platform
is_win = platform.startswith('win')

# or
from platform import platform
is_win = platform().lower().startswith('win')

# return command output
from subprocess import check_output
from commands import getoutput


# 顯示錯誤資訊
def errmess(n=1):
    from traceback import format_exc
    return '\n'.join(format_exc().split('\n')[-n - 1:-1])
Esempio n. 50
0
@pytest.mark.skipif(numpy_installed is False, reason='requires numpy')
def test_image_to_string_with_numpy_array(test_file):
    assert 'The quick brown dog' in image_to_string(
        np.array(Image.open(test_file)),
        'eng',
    )


@pytest.mark.lang_fra
def test_image_to_string_european(test_file_european):
    assert 'La volpe marrone' in image_to_string(test_file_european, 'fra')


@pytest.mark.skipif(
    platform.startswith('win32'),
    reason='used paths with `/` as separator',
)
def test_image_to_string_batch():
    batch_file = path.join(DATA_DIR, 'images.txt')
    assert 'The quick brown dog' in image_to_string(batch_file)


def test_image_to_string_multiprocessing():
    """Test parallel system calls."""
    test_files = [
        'test.jpg',
        'test.pgm',
        'test.png',
        'test.ppm',
        'test.tiff',
Esempio n. 51
0
def transform_path(path):
    if platform.startswith("win32"):
        return path.replace("/", "\\")
    else:
        return path
Esempio n. 52
0
import wx.lib.newevent
import thread, shlex, subprocess
import os, re
from os.path import isfile, join
from sys import platform

if platform.startswith("win"):
    from _subprocess import STARTF_USESHOWWINDOW

(scriptEvent, EVT_SCRIPT_UPDATE) = wx.lib.newevent.NewEvent()
SCRIPT_RUNNING = 1
SCRIPT_FINISHED = 2
SCRIPT_CANCELLED = 3

TOOLPATHS_INSIDE_ARDUINO = [
    "hardware/tools/avr/bin/",
    "hardware/tools/"  # avrdude in Arduino 1.0.x
]
if platform.startswith("darwin"):
    # That's an OS property, the Applicaton Bundle hierarchy.
    pathsCopy = TOOLPATHS_INSIDE_ARDUINO
    TOOLPATHS_INSIDE_ARDUINO = []
    for path in pathsCopy:
        TOOLPATHS_INSIDE_ARDUINO.append("Contents/Resources/Java/" + path)
        TOOLPATHS_INSIDE_ARDUINO.append("Contents/Java/" + path)


class ScriptTools:
    def __init__(self, settings):
        self.settings = settings
Esempio n. 53
0
            'moviepy',
            'python-gitlab', 'gitpython',
            'astunparse',
            'freetype-py']

# `opencv` package should be installed via conda instead
# cf. https://github.com/ContinuumIO/anaconda-issues/issues/1554
if 'CONDA_PREFIX' not in os.environ:
    required.append('opencv-python')

# some optional dependencies
if platform == 'win32':
    required.extend(['pypiwin32'])
if platform == 'darwin':
    required.extend(['pyobjc-core', 'pyobjc-framework-Quartz'])
if platform.startswith('linux'):
    required.remove('wxPython')  # on linux this fails

# `pyqt` package should be installed via conda instead
# cf. https://github.com/ContinuumIO/anaconda-issues/issues/1554
if PY3 and ('CONDA_PREFIX' not in os.environ):
    required.append('pyqt5')

# for dev you also want:
# 'sphinx','pytest'
# 'lxml', 'pyopengl'


# compress psychojs to a zip file for packaging
# only takes 0.5s but could skip if you prefer
if ('-noJS' in argv) or not exists('psychojs') or ('clean' in argv):
Esempio n. 54
0
def build_executable_windows(session):
    if not platform.startswith("win32"):
        raise Exception(f"Unexpected platform {platform}")
    session.notify("build_executable_current_platform")
Esempio n. 55
0
    endpreprocessor = 0
    current_instruction = 0
    stacksize = b"\xff\xff\xff\xff"
    options = 0
    custom_datasec_addr = False
    custom_codesec_addr = False
    datasec_addr = 0
    codesec_addr = 0
    include_paths = []
    output_filename = "out.oxy"


try:
    environment.include_paths.append(os.environ["OXY_LIBS"])
except KeyError:
    if platform.startswith("linux"):
        if os.path.isdir("/usr/local/OxyLibs"):
            environment.include_paths.append("/usr/local/OxyLibs")
    elif platform.startswith("win32"):
        if os.path.isdir(os.environ["LOCALAPPDATA"] + "\\OxyLibs"):
            environment.include_paths.append(os.environ["LOCALAPPDATA"] +
                                             "\\OxyLibs")

for arg in argv:
    if arg.startswith("--output=") or arg.startswith("-o="):
        environment.output_filename = "=".join(npart
                                               for npart in arg.split("=")[1:])
    elif arg == "-v" or arg == "--verbose":
        environment.verbose = True
    elif arg.startswith("--include=") or arg.startswith("-i="):
        environment.include_paths += "=".join(
from numpy import pi
from math import *

# libraries and data
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd
import array as arr

# command line options
from optparse import OptionParser

from sys import platform
if any([
        platform.startswith(os_name)
        for os_name in ['linux', 'darwin', 'freebsd']
]):
    import zugbruecke as ctypes
elif platform.startswith('win'):
    import ctypes
else:
    # Handle unsupported platforms
    print("Unknown platform")
    exit(1)
# Linux version:
# import zugbruecke as ctypes

# parse command line arguments

parser = OptionParser()
Esempio n. 57
0
try:
    import pyx
    if test_pyx():
        PYX = 1
    else:
        log_loading.warning(
            "PyX dependencies are not installed ! Please install TexLive or MikTeX."
        )
        PYX = 0
except ImportError:
    log_loading.info(
        "Can't import PyX. Won't be able to use psdump() or pdfdump().")
    PYX = 0

LINUX = platform.startswith("linux")
OPENBSD = platform.startswith("openbsd")
FREEBSD = "freebsd" in platform
NETBSD = platform.startswith("netbsd")
DARWIN = platform.startswith("darwin")
SOLARIS = platform.startswith("sunos")
WINDOWS = platform.startswith("win32")
BSD = DARWIN or FREEBSD or OPENBSD or NETBSD
# See https://docs.python.org/3/library/platform.html#cross-platform
IS_64BITS = maxsize > 2**32

if WINDOWS:
    try:
        if float(platform_lib.release()) >= 8.1:
            LOOPBACK_NAME = "Microsoft KM-TEST Loopback Adapter"
        else:
Esempio n. 58
0
    if element.parent.name in ['style', 'script', 'head', 'title', 'meta', '[document]']:
        return False
    if isinstance(element, Comment):
        return False
    return True


def checkPathExists(path):
    if os.path.exists(path):
        return True
    return False


if __name__ == '__main__':

    if platform.startswith("linux"):
        display = Display(visible=0, size=(1920, 1080))
        display.start()
        chromeOptions = webdriver.ChromeOptions()
        chromeOptions.add_argument('headless')
        chromeOptions.add_argument('window-size=1920x1080')
        chromeOptions.add_argument('--no-sandbox')
        driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=chromeOptions)
    elif platform.startswith("darwin") or platform.startswith("win32"):
        driver = webdriver.Chrome(executable_path="Driver/chromedriver")

    if not checkPathExists("results"):
        os.mkdir("results")
    if not checkPathExists("diagnostics"):
        os.mkdir("diagnostics")
    schools = readCSV("data/micro-sample13_coded.csv")
Esempio n. 59
0
    generate_client_id,
    generate_client_secret,
)
from authentik.providers.oauth2.models import ClientTypes, OAuth2Provider, ScopeMapping
from tests.e2e.utils import (
    USER,
    SeleniumTestCase,
    apply_migration,
    object_manager,
    retry,
)

LOGGER = get_logger()


@skipUnless(platform.startswith("linux"), "requires local docker")
class TestProviderOAuth2OIDCImplicit(SeleniumTestCase):
    """test OAuth with OpenID Provider flow"""

    def setUp(self):
        self.client_id = generate_client_id()
        self.client_secret = generate_client_secret()
        self.application_slug = "test"
        super().setUp()

    def setup_client(self) -> Container:
        """Setup client saml-sp container which we test SAML against"""
        sleep(1)
        client: DockerClient = from_env()
        container = client.containers.run(
            image="beryju/oidc-test-client",
Esempio n. 60
0
    """Test that tab works in find/replace dialog. Regression test for #3674.
    Mock test—more isolated but less flimsy."""
    editor_stack, editor, finder, qtbot = editor_find_replace_bot
    text = '  \nspam \nspam \nspam '
    editor.set_text(text)
    finder.show()
    finder.show_replace()

    finder.focusNextChild = MagicMock(name="focusNextChild")
    qtbot.keyPress(finder.search_text, Qt.Key_Tab)
    finder.focusNextChild.assert_called_once_with()


@flaky(max_runs=3)
@pytest.mark.skipif(os.environ.get('CI', None) is None and
                    platform.startswith('linux'),
                    reason="Fails on some Linux platforms locally.")
def test_tab_moves_focus_from_search_to_replace(editor_find_replace_bot):
    """Test that tab works in find/replace dialog. Regression test for #3674.
    "Real world" test—more comprehensive but potentially less robust."""
    editor_stack, editor, finder, qtbot = editor_find_replace_bot
    text = '  \nspam \nspam \nspam '
    editor.set_text(text)
    finder.show()
    finder.show_replace()

    qtbot.wait(100)
    finder.search_text.setFocus()
    qtbot.wait(100)
    assert finder.search_text.hasFocus()
    assert not finder.replace_text.hasFocus()