Example #1
0
def checkChanges(repo, master, verbose=False, oldRevision=-1):
    cmd = ["svn", "log", "--non-interactive", "--xml", "--verbose",
           "--limit=1", repo]
    if verbose == True:
        print "Getting last revision of repository: " + repo

    if sys.platform == 'win32':
        f = win32pipe.popen(cmd)
        xml1 = ''.join(f.readlines())
        f.close()
    else:
        xml1 = getoutput(cmd)

    if verbose == True:
        print "XML\n-----------\n"+xml1+"\n\n"

    doc = xml.dom.minidom.parseString(xml1)
    el = doc.getElementsByTagName("logentry")[0]
    revision = el.getAttribute("revision")
    author = "".join([t.data for t in
    el.getElementsByTagName("author")[0].childNodes])
    comments = "".join([t.data for t in
    el.getElementsByTagName("msg")[0].childNodes])

    pathlist = el.getElementsByTagName("paths")[0]
    paths = []
    for p in pathlist.getElementsByTagName("path"):
            paths.append("".join([t.data for t in p.childNodes]))

    if verbose == True:
        print "PATHS"
        print paths

    if  revision != oldRevision:
        cmd = ["buildbot", "sendchange", "--master=%s"%master,
               "--revision=%s"%revision, "--username=%s"%author,
               "--comments=%s"%comments]
        cmd += paths

        if verbose == True:
            print cmd

        if sys.platform == 'win32':
            f = win32pipe.popen(cmd)
            print time.strftime("%H.%M.%S ") + "Revision "+revision+ ": "+ \
''.join(f.readlines())
            f.close()
        else:
            xml1 = getoutput(cmd)
    else:
        print time.strftime("%H.%M.%S ") + \
"nothing has changed since revision "+revision

    return revision
def checkChanges(repo, master, verbose=False, oldRevision=-1):
    cmd = ["svn", "log", "--non-interactive", "--xml", "--verbose",
           "--limit=1", repo]
    if verbose == True:
        print "Getting last revision of repository: " + repo

    if sys.platform == 'win32':
        f = win32pipe.popen(cmd)
        xml1 = ''.join(f.readlines())
        f.close()
    else:
        xml1 = getoutput(cmd)

    if verbose == True:
        print "XML\n-----------\n"+xml1+"\n\n"

    doc = xml.dom.minidom.parseString(xml1)
    el = doc.getElementsByTagName("logentry")[0]
    revision = el.getAttribute("revision")
    author = "".join([t.data for t in
    el.getElementsByTagName("author")[0].childNodes])
    comments = "".join([t.data for t in
    el.getElementsByTagName("msg")[0].childNodes])
    
    pathlist = el.getElementsByTagName("paths")[0]
    paths = []
    for p in pathlist.getElementsByTagName("path"):
            paths.append("".join([t.data for t in p.childNodes]))

    if verbose == True:
        print "PATHS"
        print paths

    if  revision != oldRevision:
        cmd = ["buildbot", "sendchange", "--master=%s"%master,
               "--revision=%s"%revision, "--username=%s"%author,
               "--comments=%s"%comments]
        cmd += paths

        if verbose == True:
            print cmd

        if sys.platform == 'win32':
            f = win32pipe.popen(cmd)
            print time.strftime("%H.%M.%S ") + "Revision "+revision+ ": "+ ''.join(f.readlines())
            f.close()
        else:
            xml1 = getoutput(cmd)
    else:
        print time.strftime("%H.%M.%S ") + "nothing has changed since revision "+revision

    return revision
Example #3
0
    def execute(self, com):
        try:
            import win32pipe

            return win32pipe.popen(com).read()
        except ImportError:
            return os.popen(com).read()
Example #4
0
def run(args_list):
    global _CurrentProcess
    if _CurrentProcess is not None:
        dhnio.Dprint(4, 'run_upnpc.run WARNING only one process at once')
        return None

    if dhnio.Windows():
        cmdargs = ['upnpc.exe']
    elif dhnio.Linux():
        cmdargs = ['upnpc']
    else:
        return None

    cmdargs += args_list

    if dhnio.Windows():
        # if we run from svn - upnpc.exe is in the p2p folder
        if not os.path.isfile(cmdargs[0]):
            if os.path.isfile(os.path.join('p2p', cmdargs[0])):
                cmdargs[0] = os.path.join('p2p', cmdargs[0])
            else:
                dhnio.Dprint(1, 'run_upnpc.run ERROR can not find executable file ' + cmdargs[0])
                return None

    dhnio.Dprint(6, 'run_upnpc.run is going to execute: %s' % cmdargs)

    try:
        if dhnio.Windows() and dhnio.isFrozen():
            import win32pipe
            _CurrentProcess = win32pipe.popen(subprocess.list2cmdline(cmdargs))
        else:
            _CurrentProcess = nonblocking.Popen(cmdargs, shell=False,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,)
    except OSError:
        dhnio.Dprint(1, 'run_upnpc.run ERROR can not start executable file ' + cmdargs[0])
        return None
    except:
        dhnio.DprintException()
        return None

    try:
        if dhnio.Windows() and dhnio.isFrozen():
            out_data = _CurrentProcess.read()
            returncode = _CurrentProcess.close() or 0
        else:
            out_data = _CurrentProcess.communicate()[0]
            returncode = _CurrentProcess.returncode
    except:
        dhnio.DprintException()
        return None

    dhnio.Dprint(6, 'run_upnpc.run %s finished with return code: %s' % (str(_CurrentProcess), str(returncode)))
    _CurrentProcess = None

    return out_data
Example #5
0
def checkChanges(repo, master, oldRevision=-1):
    cmd = [
        "svn", "log", "--non-interactive", "--xml", "--verbose", "--limit=1",
        repo
    ]

    if opts.verbose:
        print("Getting last revision of repository: " + repo)

    if sys.platform == 'win32':
        f = win32pipe.popen(cmd)
        xml1 = ''.join(f.readlines())
        f.close()
    else:
        xml1 = getoutput(cmd)

    if opts.verbose:
        print("XML\n-----------\n" + xml1 + "\n\n")

    revisionData = parseChangeXML(xml1)

    if opts.verbose:
        print("PATHS")
        print(revisionData['paths'])

    if revisionData['revision'] != oldRevision:

        cmd = sendchange_cmd(master, revisionData)

        if sys.platform == 'win32':
            f = win32pipe.popen(cmd)
            pretty_time = time.strftime("%H.%M.%S ")
            print("%s Revision %s: %s" %
                  (pretty_time, revisionData['revision'], ''.join(
                      f.readlines())))
            f.close()
        else:
            xml1 = getoutput(cmd)
    else:
        pretty_time = time.strftime("%H.%M.%S ")
        print("%s nothing has changed since revision %s" %
              (pretty_time, revisionData['revision']))

    return revisionData['revision']
Example #6
0
def checkChanges(repo, master, oldRevision=-1):
    cmd = ["svn", "log", "--non-interactive", "--xml", "--verbose",
           "--limit=1", repo]

    if opts.verbose:
        print("Getting last revision of repository: " + repo)

    if sys.platform == 'win32':
        f = win32pipe.popen(cmd)
        xml1 = ''.join(f.readlines())
        f.close()
    else:
        xml1 = getoutput(cmd)

    if opts.verbose:
        print("XML\n-----------\n" + xml1 + "\n\n")

    revisionData = parseChangeXML(xml1)

    if opts.verbose:
        print("PATHS")
        print(revisionData['paths'])

    if revisionData['revision'] != oldRevision:

        cmd = sendchange_cmd(master, revisionData)

        if sys.platform == 'win32':
            f = win32pipe.popen(cmd)
            pretty_time = time.strftime("%H.%M.%S ")
            print("%s Revision %s: %s" % (pretty_time, revisionData['revision'],
                                          ''.join(f.readlines())))
            f.close()
        else:
            xml1 = getoutput(cmd)
    else:
        pretty_time = time.strftime("%H.%M.%S ")
        print("%s nothing has changed since revision %s" % (pretty_time,
                                                            revisionData['revision']))

    return revisionData['revision']
Example #7
0
 def Execute(self, cmd, returnStream=True):
     """
     execute the current path with popen and returns std out
     """
     s = popen(self._path + " " + cmd, "r")
     if returnStream:
         return s
     r = ""
     while 1:
         d = s.readline()
         if not d or d == ".\n" or d == ".\r":
             break
         r += d
     return r
Example #8
0
 def Execute(self, cmd, returnStream = True):
     """
     execute the current path with popen and returns std out
     """
     s = popen(self._path + " " + cmd, "r")
     if returnStream:
         return s
     r = ""
     while 1:
         d = s.readline()
         if not d or d == ".\n" or d == ".\r":
             break
         r += d
     return r
Example #9
0
def _route_read_win32_default_ifaceaddr():
    """return the IP address of the interface used by the first default route"""
    # the win32pipe interface hopefully doesn't bluescreen norton antivirus
    try:
        route_output = win32pipe.popen(__win32_route_path + ' print 0.0.0.0').read()
    except:
        debugprint('WARNING: win32pipe.popen() failed reverting to os.popen() to call ROUTE to obtain IP address\n', vs='ipaddresslib.win32')
        route_output = os.popen(__win32_route_path + ' print 0.0.0.0').read()
    def_route_re = re.compile('^\s*0\.0\.0\.0\s.+\s(?P<address>\d+\.\d+\.\d+\.\d+)\s+(?P<metric>\d+)\s*$', flags=re.M|re.I|re.S)

    m = def_route_re.search(route_output)
    if m:
        return m.group('address')
    else:
        return None
Example #10
0
def getoutput(cmd):
    timeout = 120
    maxtries = 3
    if sys.platform == 'win32':
        f = win32pipe.popen(cmd)
        stdout = ''.join(f.readlines())
        f.close()
    else:
        currentry = 1
        while True:  # retry loop
            p = subprocess.Popen(cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
            waited = 0
            while True:  # wait loop
                if p.poll() != None:
                    break  # process ended.
                if waited > timeout:
                    print(
                        "WARNING: Timeout of %s seconds reached while trying to run: %s"
                        % (timeout, ' '.join(cmd)))
                    break
                waited += 1
                time.sleep(1)

            if p.returncode != None:  # process has endend
                stdout = p.stdout.read()
                if p.returncode == 0:
                    break  # ok: exit retry loop
                else:
                    print('WARNING: "%s" returned status code: %s' %
                          (' '.join(cmd), p.returncode))
                    if stdout is not None:
                        print(stdout)
            else:
                p.kill()

            if currentry > maxtries:
                print(
                    "ERROR: Reached maximum number of tries (%s) to run: %s" %
                    (maxtries, ' '.join(cmd)))
                sys.exit(1)
            currentry += 1
    return stdout
Example #11
0
def execute_command(cmd):
    """
    Execute a command-line command and return the screen output as a string.

    """
    _log.debug("Executing: %s" % repr(cmd))
    
    cmd = """\
@echo OFF
%s
""" % cmd

    write('temp.bat', cmd)

    with win32pipe.popen('temp.bat') as f:
        lines = f.readlines()

    print "Output: %s" % "".join(lines)
    return lines
Example #12
0
 def execute(self, com):
     try:
         import win32pipe
         return win32pipe.popen(com).read()
     except ImportError:
         return os.popen(com).read()
Example #13
0
    def UriMethod(self, event):
        try:
            from agw import pybusyinfo as PBI
        except ImportError:  # if it's not there locally, try the wxPython lib.
            import wx.lib.agw.pybusyinfo as PBI

        # Create an open file dialog
        dialog = wx.DirDialog(self,
                              message='Pick a directory.',
                              style=wx.DD_NEW_DIR_BUTTON)

        # Show the dialog and get user input
        if dialog.ShowModal() == wx.ID_OK:
            outpath = dialog.GetPath()
            outpath = "/".join(outpath.split('\\'))
            print 'Selected:', outpath
        else:
            print 'Nothing was selected.'
            return
        dialog.Destroy()
        # Only destroy a dialog after you're done with it.

        _expID, expDesc = self.GetCurrentExpID()
        dialog2 = wx.TextEntryDialog(self,
                                     'Choose a prefix for the result files.',
                                     'Choose prefix', expDesc)
        if dialog2.ShowModal() == wx.ID_OK:
            prefix = dialog2.GetValue()
            outfname = outpath + '/' + prefix
        else:
            return

        csv_fname = outfname + '.csv'
        self.GenerateCSV(csv_fname)

        if sys.platform == "win32":
            message = "Please wait while generating figures... (May take a few minutes)"
            busy = PBI.PyBusyInfo(message,
                                  parent=self,
                                  title="ATP - Automatic TECAN Pipeline")
            print "WINDWOS FOUND !!!"  # on a Windows port
            command = PLOT_EXP_DATA_EXE + ' -i %s -o %s' % (csv_fname,
                                                            outfname)
            print command
            try:
                import win32pipe
            except ImportError:
                raise ImportError, "The win32pipe module could not be found"
            #popen = win32pipe.popen
            win32pipe.popen(command, 'r')
            print "win32"
            del busy
        else:
            if not os.path.exists(PLOT_EXP_DATA_LINUX):
                dlg = wx.MessageDialog(
                    self, 'Cannot locate PlotExpData executable: %s' %
                    PLOT_EXP_DATA_LINUX, 'File not found',
                    wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
                return
            args = [PLOT_EXP_DATA_LINUX, '-i', csv_fname, '-o', outfname]
            print ' '.join(args)
            subprocess.call(args=args, executable=PLOT_EXP_DATA_LINUX)

        reportString = "Files generated:\n"
        for filename in os.listdir(outpath):
            try:
                basename, extension = filename.rsplit('.', 1)
            except ValueError:
                continue
            if basename[:len(prefix)] == prefix and extension == 'svg':
                reportString += filename + "\n"

        dlg = wx.MessageDialog(self, reportString, 'Report',
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
Example #14
0
    def UriMethod(self, event):
        try:
            from agw import pybusyinfo as PBI
        except ImportError: # if it's not there locally, try the wxPython lib.
            import wx.lib.agw.pybusyinfo as PBI
        
        # Create an open file dialog
        dialog = wx.DirDialog(self, message='Pick a directory.', style=wx.DD_NEW_DIR_BUTTON)
        
        # Show the dialog and get user input
        if dialog.ShowModal() == wx.ID_OK:
            outpath = dialog.GetPath()
            outpath = "/".join(outpath.split('\\'))
            print 'Selected:', outpath
        else:
            print 'Nothing was selected.'
            return
        dialog.Destroy()
        # Only destroy a dialog after you're done with it.
        
        _expID, expDesc = self.GetCurrentExpID()
        dialog2 = wx.TextEntryDialog(self, 'Choose a prefix for the result files.',
                                     'Choose prefix', expDesc)
        if dialog2.ShowModal() == wx.ID_OK:
            prefix = dialog2.GetValue()
            outfname = outpath +'/' + prefix
        else:
            return

        csv_fname = outfname + '.csv'
        self.GenerateCSV(csv_fname)
        
        
        if sys.platform == "win32":   
            message = "Please wait while generating figures... (May take a few minutes)"
            busy = PBI.PyBusyInfo(message, parent=self, title="ATP - Automatic TECAN Pipeline")
            print "WINDWOS FOUND !!!"             # on a Windows port
            command = PLOT_EXP_DATA_EXE + ' -i %s -o %s' % (csv_fname, outfname)
            print command
            try:
                import win32pipe
            except ImportError:
                    raise ImportError, "The win32pipe module could not be found"
            #popen = win32pipe.popen
            win32pipe.popen(command,'r')
            print "win32"
            del busy
        else:
            if not os.path.exists(PLOT_EXP_DATA_LINUX):
                dlg = wx.MessageDialog(self, 
                    'Cannot locate PlotExpData executable: %s' % PLOT_EXP_DATA_LINUX,
                    'File not found', wx.OK | wx.ICON_ERROR)
                dlg.ShowModal()
                dlg.Destroy()
                return
            args = [PLOT_EXP_DATA_LINUX, '-i', csv_fname, '-o', outfname]
            print ' '.join(args)
            subprocess.call(args=args, executable=PLOT_EXP_DATA_LINUX)
        
        reportString = "Files generated:\n"
        for filename in os.listdir(outpath):
            try:
                basename, extension = filename.rsplit('.', 1)
            except ValueError:
                continue
            if basename[:len(prefix)] == prefix and extension == 'svg':
                reportString += filename + "\n"
        
        dlg = wx.MessageDialog(self, reportString,
                               'Report', wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()