| Home | Trees | Indices | Help |
|---|
|
|
1 # Software License Agreement (BSD License) 2 # 3 # Copyright (c) 2012, Fraunhofer FKIE/US, Alexander Tiderko 4 # All rights reserved. 5 # 6 # Redistribution and use in source and binary forms, with or without 7 # modification, are permitted provided that the following conditions 8 # are met: 9 # 10 # * Redistributions of source code must retain the above copyright 11 # notice, this list of conditions and the following disclaimer. 12 # * Redistributions in binary form must reproduce the above 13 # copyright notice, this list of conditions and the following 14 # disclaimer in the documentation and/or other materials provided 15 # with the distribution. 16 # * Neither the name of Fraunhofer nor the names of its 17 # contributors may be used to endorse or promote products derived 18 # from this software without specific prior written permission. 19 # 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 # POSSIBILITY OF SUCH DAMAGE. 32 33 import os 34 import time 35 36 try: 37 from python_qt_binding import QtCore 38 except: 39 pass 4042 ''' 43 A class to watch for file changes. 44 ''' 45 file_changed = QtCore.Signal(str, list) 46 '''@ivar: a signal to inform the receiver about the changes on 47 launch file or included file. ParameterB{:} (changed file, list of tuples(masteruri, launch file))''' 4811150 QtCore.QObject.__init__(self) 51 self.file_watcher = QtCore.QFileSystemWatcher() 52 self.file_watcher.fileChanged.connect(self.on_file_changed) 53 self.changed = {} 54 self.launches = {}5557 # Delete to avoid segfault if the LaunchConfig class is destroyed recently 58 # after creation and xmlrpclib.ServerProxy process a method call. 59 del self.file_watcher6062 ''' 63 callback method, which is called by L{QtCore.QFileSystemWatcher} if the 64 launch file or included files are changed. In this case 65 L{FileWatcher.file_changed} signal will be emitted. 66 ''' 67 # to avoid to handle from QFileSystemWatcher fired the signal two times 68 if (not self.changed.has_key(file) or (self.changed.has_key(file) and self.changed[file] + 0.05 < time.time())): 69 self.changed[file] = time.time() 70 changes = [] 71 for (uri, lfile, _), files in self.launches.items():#_:=id 72 if file in files: 73 changes.append((uri, lfile)) 74 self.file_changed.emit(file, changes)7577 if self.launches.has_key((masteruri, launch_file, launch_id)): 78 self.launches[(masteruri, launch_file, launch_id)].extend([os.path.normpath(f) for f in files]) 79 else: 80 self.launches[(masteruri, launch_file, launch_id)] = [os.path.normpath(f) for f in files] 81 self.update_files()8284 try: 85 if launch_file: 86 if launch_id: 87 del self.launches[(masteruri, launch_file, launch_id)] 88 else: 89 for (uri, file, id), files in self.launches.items(): 90 if uri == masteruri and file == launch_file: 91 del self.launches[(uri, file, id)] 92 else: 93 for (uri, file, id), files in self.launches.items(): 94 if uri == masteruri: 95 del self.launches[(uri, file, id)] 96 except: 97 # import traceback 98 # print traceback.format_exc(1) 99 pass 100 self.update_files()101103 result = set() 104 for files in self.launches.itervalues(): 105 result.update(set(files)) 106 files = self.file_watcher.files() 107 if files: 108 self.file_watcher.removePaths(files) 109 if list(result): 110 self.file_watcher.addPaths(list(result))
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Fri Aug 28 11:39:31 2015 | http://epydoc.sourceforge.net |