def start(self, path):
     """
     Public slot to populate the data.
     
     @param path directory name to show change lists for (string)
     """
     self.changeListsDict = {}
     self.cancelled = False
     
     self.filesLabel.setText(self.trUtf8("Files (relative to %1):").arg(path))
     
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     QApplication.processEvents()
     
     locker = QMutexLocker(self.vcs.vcsExecutionMutex)
     try:
         entries = self.client.get_changelist(path, depth=pysvn.depth.infinity)
         for entry in entries:
             file = entry[0]
             changelist = entry[1]
             if changelist not in self.changeListsDict:
                 self.changeListsDict[changelist] = []
             filename = file.replace(path + os.sep, "")
             if filename not in self.changeListsDict[changelist]:
                 self.changeListsDict[changelist].append(filename)
     except pysvn.ClientError as e:
         locker.unlock()
         self.__showError(e.args[0])
     self.__finish()
Beispiel #2
0
    def process_packet(self, feedline):
        feedline = str(feedline)
        self.status['parse_error'] = True
        packet = {}

        if not feedline.startswith("*"):
            if feedline.startswith("#"):
                self._finish_command_response()
            else:
                self._process_command_response(feedline)
            return

        parts = feedline[2:].rstrip().split(' ')
        for part in parts:
            pair = part.split('=')
            if len(pair) != 2:
                return
            packet[str(pair[0])] = str(pair[1])

        locker = QMutexLocker(self.lock)
        try:
            self.status.update({
                "rpm": int(packet['rpm']),
                "sync": True if packet['sync'] == "1" else False,
                "t0_count": int(packet['t0_count']),
                "map": float(packet['map']),
                "advance": float(packet['adv']),
                "dwell": int(packet['dwell_us'])
                })
        except:
            return
        finally:
            locker.unlock()
        self.status['parse_error'] = False
        self.feed_update.emit()
Beispiel #3
0
    def sync(self):
        # Update people from backend
        try:
            newpeople = self.backend.getPersonList()
            with QMutexLocker(self.mutex):
                self.badgeToId = {}
                for person in newpeople:
                    if person.id in self.people:
                        self.people[person.id].updateFrom(person)
                    else:
                        self.people[person.id] = person
                    self.badgeToId[person.badge] = person.id
        except IOError as e:
            # Unlikely we'll be able to do anything else
            self.statusUpdate.emit("Could not contact server to synchronize: %s" % e)
            return

        # Download photos as necessary
        for person in newpeople:
            size = 0
            if person.photo:
                try:
                    size = os.stat(person.photo).st_size
                except OSError:
                    pass
            if person.photoRemote and size != person.photoSize:
                self.statusUpdate.emit("Downloading %s" % person.photoRemote)
                try:
                    self.backend.getBadgePhoto(person.photoRemote, person.photo)
                except IOError as e:
                    self.statusUpdate.emit("Failed when downloading %s: %s" %
                            (person.photo, e))

        # Push saved time log to server
        with QMutexLocker(self.mutex):
            if self.timeLog:
                try:
                    self.statusUpdate.emit("Pushing %d time records" %
                            len(self.timeLog))
                    ok = self.backend.putTimeRecords(self.timeLog)
                except IOError as e:
                    self.statsChanged.emit()
                    self.statusUpdate.emit("Failed to push time records: %s" % e)
                    return
                self.timeLog = [v for i, v in enumerate(self.timeLog) if i not in ok]
                self.statusUpdate.emit("Pushed %d time records" % len(ok))
            else:
                self.statusUpdate.emit("Synchronization complete")

            self.statsChanged.emit()
Beispiel #4
0
 def render(self):
   locker = QMutexLocker(self.mutex)
   if not self.isRunning() and not self.countThread.isRunning() and not self.populateThread.isRunning() and not self.maxOccThread.isRunning():
     self.start(QThread.LowPriority)
   else:
     self.restart = True
     self.condition.wakeOne()
Beispiel #5
0
    def log(self, level, msg):
        """
        Logs the inputed message with the given level.
        
        :param      level | <int> | logging level value
                    msg   | <unicode>
        
        :return     <bool> success
        """
        locker = QMutexLocker(self._mutex)

        if (not self.isLoggingEnabled(level)):
            return False

        if isinstance(msg, QtCore.QString):
            msg = unicode(msg.toUtf8(), "UTF-8")

        msg = self._blankCache + msg
        if msg.endswith('\n'):
            self._blankCache = '\n'
            msg = msg[:-1]
        else:
            self._blankCache = ''

        self.setCurrentMode(level)
        self.insertPlainText(msg)

        if not self.signalsBlocked():
            self.messageLogged.emit(level, msg)

        self.scrollToEnd()

        return True
Beispiel #6
0
 def save(self):
     with QMutexLocker(self.mutex):
         with open("DataStore.pickle", "wb") as f:
             pickler = pickle.Pickler(f)
             pickler.dump(self.people)
             pickler.dump(self.clockedIn)
             pickler.dump(self.timeLog)
Beispiel #7
0
    def sorted_active_runnable(self, query, hwnds):
        with QMutexLocker(self.mutex):
            # update query and collect active ones
            self._refresh_tasks(hwnds, query)
            active_tasks = [self.tasks[h] for h in hwnds]

            # sort by last use
            if not query:
                return sorted(active_tasks,
                              key=lambda t: t.usetime,
                              reverse=True)

            titles = [task.fullname.lower() for task in active_tasks]

            def f(task, title):
                return task.query.distance_to(title)

            ds = [
                f(task, title) * (10**len(query))
                for task, title in zip(active_tasks, titles)
            ]
            best = ds[0]

            for i in itertools.takewhile(lambda i: ds[i] == best,
                                         range(len(ds))):
                ds[i] -= len(lcs(query, titles[i]))

            #return sorted(active_tasks, key=f)
            return [
                task for i, task in sorted(enumerate(active_tasks),
                                           key=lambda i: ds[i[0]])
            ]
Beispiel #8
0
 def signOutAll(self):
     """Sign out all clocked in records."""
     with QMutexLocker(self.mutex):
         while self.clockedIn:
             record = self.clockedIn.popitem()[1]
             record.signOut()
             self.timeLog.append(record)
         self.save()
         self.statsChanged.emit()
Beispiel #9
0
 def handle_signout(self):
     record = self.sender()
     id = record.person.id
     print("handling %d signing out" % id)
     with QMutexLocker(self.mutex):
         record = self.clockedIn.pop(id, None)
         if record is not None:
             self.timeLog.append(record)
         self.statsChanged.emit()
Beispiel #10
0
 def clearAll(self):
     """Clear all clocked in records.  They will be saved in the time log
     but with no hours credit."""
     with QMutexLocker(self.mutex):
         while self.clockedIn:
             record = self.clockedIn.popitem()[1]
             record.clear()
             self.timeLog.append(record)
         self.save()
         self.statsChanged.emit()
    def __init__(self, parent=None):
        """
        Constructor

        @param parent reference to the parent widget
        @type QWidget
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)

        self.sock = sserver(upMainSig=self.updateMainSignal,
                            recSignal=self.fromSocketfuncSignal,
                            readySignal=self.serverCreateSignal)
        self.SERVER_RUN = False
        self.host = 'localhost'
        self.port = 9876
        self.mode = 'TCP'

        ##地图加载完成标志
        self.LOAD_FINISH = False

        self.mutex = QMutex()
        self.log = log.logfile('log')
        self.orderDict = {}
        if self.log is not None:
            with QMutexLocker(self.mutex):
                self.log.write('enter-socketFuc-class-INIT-' + str(self))

        self.updateMainSignal.connect(self.say_hi)
        self.fromSocketfuncSignal.connect(self.sockToYingyan)
        #try to make sub dialog constant
        self.YingyanDailog = YingyanFunc(
            updateMainSignal=self.updateMainSignal,
            recDataSignal=self.toYingyanFuncSignal,
            toPickSignal=self.toPickPointSignal,
            sendOrderSignal=self.sendOrderSignal)

        self.PickPointDialog = PickPointfunc(
            upsignal=self.fromPickPointSignal,
            downsignal=self.toPickPointSignal,
            updateMainSignal=self.updateMainSignal,
            sendOrderSignal=self.sendOrderSignal,
            toDebugWindowSingal=self.toDebugWindowSignal)
        #todo:发送到socket的信号统一为sendOrderSignal
        #self.fromPickPointSignal.connect(self.processPickData)

        self.sendOrderSignal.connect(self.SendOrder)

        #调试窗口
        self.debugWindow = DebugWindow(self.toDebugWindowSignal)
        self.ReadConfigFromFile()

        #server成功建立
        self.serverCreateSignal.connect(self.ServerCreated)
 def say_hi(self, words):
     ##show in the info area in dialog
     if str(words) == 'Loading map done':
         self.LOAD_FINISH = True
     try:
         self.sock_show_tb.append(str(words))
     except Exception as e:
         self.sock_show_tb.append('<ERROR: invalid input from client>')
     ##add log
     with QMutexLocker(self.mutex):
         self.log.write(str(words))
Beispiel #13
0
    def load_search_result_t(self, dic_file_lines, cases_num):
        """
		:param dic_file_lines: dictionary, key = file path, value = lines matched
		:param cases_num: int, the number of cases matched
		:return: void
		"""
        from PyQt4.QtCore import QMutexLocker, QMutex

        mutex = QMutex()
        lock = QMutexLocker(mutex)

        self.ui.statusbar.showMessage('Start loading results.')
        self.ui.treeWidget_search_result.clear()
        self.load_search_result(dic_file_lines, cases_num)
Beispiel #14
0
 def process2(self, obj):
     """
     This function stops the thread calling this object.
     """
     print(">> process():", os.getpid(), QThread.currentThread(),
           QThread.currentThreadId())
     self.stopWorking = False
     while not self.stopWorking:
         try:
             with QMutexLocker(self.mutex):
                 self._process()
         except Exception as ex:
             print(ex)
             self.stopWorking = True
     self.do_something.emit(self.data)
     self.finished.emit()
Beispiel #15
0
 def find_files_in_path(self):
     self.filenames = []
     for path, dirs, files in os.walk(self.rootpath):
         with QMutexLocker(self.mutex):
             if self.stopped:
                 return False
         for d in dirs[:]:
             dirname = os.path.join(path, d)
             if re.search(self.exclude, dirname + os.sep):
                 dirs.remove(d)
         for f in files:
             filename = os.path.join(path, f)
             if re.search(self.exclude, filename):
                 continue
             if re.search(self.include, filename):
                 self.filenames.append(filename)
     return True
Beispiel #16
0
 def find_files_in_hg_manifest(self):
     p = Popen(['hg', 'manifest'], stdout=PIPE, cwd=self.rootpath)
     self.filenames = []
     hgroot = get_hg_root(self.rootpath)
     for path in p.stdout.read().splitlines():
         with QMutexLocker(self.mutex):
             if self.stopped:
                 return False
         dirname = osp.dirname(path)
         if re.search(self.exclude, dirname + os.sep):
             continue
         filename = osp.basename(path)
         if re.search(self.exclude, filename):
             continue
         if re.search(self.include, filename):
             self.filenames.append(osp.join(hgroot, path))
     return True
Beispiel #17
0
 def find_string_in_files(self):
     self.results = {}
     self.nb = 0
     self.error_flag = False
     for fname in self.filenames:
         with QMutexLocker(self.mutex):
             if self.stopped:
                 return
         try:
             for lineno, line in enumerate(open(fname)):
                 for text, enc in self.texts:
                     if self.text_re:
                         found = re.search(text, line)
                         if found is not None:
                             break
                     else:
                         found = line.find(text)
                         if found > -1:
                             break
                 try:
                     line_dec = line.decode(enc)
                 except UnicodeDecodeError:
                     line_dec = line
                 if self.text_re:
                     for match in re.finditer(text, line):
                         res = self.results.get(osp.abspath(fname), [])
                         res.append((lineno+1, match.start(), line_dec))
                         self.results[osp.abspath(fname)] = res
                         self.nb += 1
                 else:
                     while found > -1:
                         res = self.results.get(osp.abspath(fname), [])
                         res.append((lineno+1, found, line_dec))
                         self.results[osp.abspath(fname)] = res
                         for text, enc in self.texts:
                             found = line.find(text, found+1)
                             if found > -1:
                                 break
                         self.nb += 1
         except IOError, (_errno, _strerror):
             self.error_flag = _("permission denied errors were encountered")
         except re.error:
             self.error_flag = _("invalid regular expression")
Beispiel #18
0
 def find_files_in_python_path(self):
     self.filenames = []
     directories = [path for path in sys.path \
                    if not path.startswith(sys.prefix)]
     for path in directories:
         if not path:
             path = os.getcwdu()
         with QMutexLocker(self.mutex):
             if self.stopped:
                 return False
         dirname = osp.dirname(path)
         if re.search(self.exclude, dirname + os.sep):
             continue
         filename = osp.dirname(path)
         if re.search(self.exclude, filename):
             continue
         if re.search(self.include, filename):
             self.filenames.append(path)
     return True
Beispiel #19
0
 def process(self):
     """
     This function is to be connected with a pyqtSignal object on another thread.
     """
     # print(">> process():", os.getpid(), QThread.currentThread(), QThread.currentThreadId())
     # self.stopWorking = False
     # while not self.stopWorking:
     st = time.time()
     try:
         with QMutexLocker(self.mutex):
             self._process()
     except Exception as ex:
         print(ex)
         # self.stopWorking = True
     self.do_something.emit(self.data)
     elapsed = time.time() - st
     print("Elapsed time of process:{0:.4f} sec.".format(elapsed))
     # if elapsed < self.sleepInterval:
     #     time.sleep(self.sleepInterval - elapsed)
     self.finished.emit()
Beispiel #20
0
 def find_files_in_hg_manifest(self):
     p = Popen(['hg', 'manifest'], stdout=PIPE,
               cwd=self.rootpath, shell=True)
     hgroot = get_vcs_root(self.rootpath)
     self.pathlist = [hgroot]
     for path in p.stdout.read().splitlines():
         with QMutexLocker(self.mutex):
             if self.stopped:
                 return False
         dirname = osp.dirname(path)
         try:
             if re.search(self.exclude, dirname+os.sep):
                 continue
             filename = osp.basename(path)
             if re.search(self.exclude, filename):
                 continue
             if re.search(self.include, filename):
                 self.filenames.append(osp.join(hgroot, path))
         except re.error:
             self.error_flag = _("invalid regular expression")
             return False
     return True
Beispiel #21
0
 def process(self):
     print(">> process():", os.getpid(), QThread.currentThread(),
           QThread.currentThreadId())
     self.isInterrupted = False
     count = 0
     while not self.isInterrupted:
         if count == 10:
             self.isInterrupted = True
             continue
         try:
             with QMutexLocker(self.mutex):
                 self.addA()
                 self.addOne()
             time.sleep(1)
             count += 1
         except Exception as ex:
             print(ex)
             self.isInterrupted = True
     print("<< process():", os.getpid(), QThread.currentThread(),
           QThread.currentThreadId())
     self.do_something.emit(self.data)
     self.finished.emit()
Beispiel #22
0
 def find_string_in_files(self):
     self.results = {}
     self.nb = 0
     self.error_flag = False
     for fname in self.filenames:
         with QMutexLocker(self.mutex):
             if self.stopped:
                 return
         try:
             for lineno, line in enumerate(file(fname)):
                 for text in self.texts:
                     if self.text_re:
                         found = re.search(text, line)
                         if found is not None:
                             break
                     else:
                         found = line.find(text)
                         if found > -1:
                             break
                 if self.text_re:
                     for match in re.finditer(text, line):
                         res = self.results.get(osp.abspath(fname), [])
                         res.append((lineno + 1, match.start(), line))
                         self.results[osp.abspath(fname)] = res
                         self.nb += 1
                 else:
                     while found > -1:
                         res = self.results.get(osp.abspath(fname), [])
                         res.append((lineno + 1, found, line))
                         self.results[osp.abspath(fname)] = res
                         for text in self.texts:
                             found = line.find(text, found + 1)
                             if found > -1:
                                 break
                         self.nb += 1
         except IOError, (_errno, _strerror):
             self.error_flag = translate(
                 "FindInFiles", "permission denied errors were encountered")
    def __init__(self,
                 parent=None,
                 mutex=None,
                 host='localhost',
                 port=9876,
                 mode='TCP',
                 upMainSig=None,
                 recSignal=None,
                 readySignal=None):
        super(sserver, self).__init__(parent)
        self.mutex = mutex
        self.host = host
        self.port = port
        self.mode = mode
        self.sserver = None
        self.RUN_FLAG = True
        self.client = None
        self.updateMain = upMainSig
        self.recDataSignal = recSignal
        self.readySignal = readySignal

        with QMutexLocker(self.mutex):
            self.updateMain.emit('new socket server- ' + str(self))
Beispiel #24
0
 def find_files_in_path(self, path):
     if self.pathlist is None:
         self.pathlist = []
     self.pathlist.append(path)
     for path, dirs, files in os.walk(path):
         with QMutexLocker(self.mutex):
             if self.stopped:
                 return False
         try:
             for d in dirs[:]:
                 dirname = os.path.join(path, d)
                 if re.search(self.exclude, dirname+os.sep):
                     dirs.remove(d)
             for f in files:
                 filename = os.path.join(path, f)
                 if re.search(self.exclude, filename):
                     continue
                 if re.search(self.include, filename):
                     self.filenames.append(filename)
         except re.error:
             self.error_flag = _("invalid regular expression")
             return False
     return True
Beispiel #25
0
 def signInOut(self, badge):
     """Sign person in or out (based on their current state).
     Returns None if person was previously signed in,
     otherwise returns created TimeRecord."""
     with QMutexLocker(self.mutex):
         id = self.badgeToId[badge]
         person = self.people[id]
         record = self.clockedIn.pop(id, None)
         if record is not None:
             # signing out
             record.signOut()
             self.timeLog.append(record)
             self.save()
             self.statsChanged.emit()
             return None
         else:
             # signing in
             record = TimeRecord(person)
             record.completed.connect(self.handle_signout)
             self.clockedIn[id] = record
             self.save()
             self.statsChanged.emit()
             return record
Beispiel #26
0
 def load(self):
     # Load pickles or create fresh if no pickle file
     with QMutexLocker(self.mutex):
         try:
             with open("DataStore.pickle", "rb") as f:
                 unpickler = pickle.Unpickler(f)
                 self.people = unpickler.load()
                 self.clockedIn = unpickler.load()
                 self.timeLog = unpickler.load()
             self.statusUpdate.emit(
                     "Loaded %d people (%d clocked in) and %d time records." %
                     (len(self.people), len(self.clockedIn),
                      len(self.timeLog)))
             for record in self.clockedIn.values():
                 record.completed.connect(self.handle_signout)
             for person in self.people.values():
                 self.badgeToId[person.badge] = person.id
         except (IOError, EOFError):
             self.people = {}
             self.timeLog = []
             self.clockedIn = {}
             self.badgeToId = {}
         self.statsChanged.emit()
    def run(self):
        # print(self.hello)
        # print (self.para)

        #get lock
        with QMutexLocker(self.GPSMutex):
            up_count = 0
            del_count = 0
            fail_count = 0
            # fail_list = []
            if len(self.points) != 0:
                for point in self.points:
                    if self.set_point(long= point[0], lat=point[1]):
                        if self.upload_one_point():
                            up_count += 1
                        else:
                            fail_count += 1
                            # fail_list.append(point)
                    else:
                        del_count +=1
                self.points = []
                self.update_main(
                'enter-func-GpsUploader-run: ' + str(up_count) + ' uploaded, ' + str(fail_count) + ' failed, ' + str(
                    del_count) + ' deleted.')
 def add_point(self, point_tuple):
     #get lock
     with QMutexLocker(self.GPSMutex):
         self.points.append(point_tuple)
 def jobFinished(self):
     lock = QMutexLocker(self.parent.mutex)
     self.parent.shutterReplied = True
Beispiel #30
0
 def getNumClockedIn(self):
     with QMutexLocker(self.mutex):
         return len(self.clockedIn)
Beispiel #31
0
 def getNumTimeEntries(self):
     with QMutexLocker(self.mutex):
         return len(self.timeLog)
Beispiel #32
0
 def getNumPeople(self):
     with QMutexLocker(self.mutex):
         return len(self.people)