def main(): running = 1 n = 0 p = 0 cm = 0 packet_list = [] mon = gamin.WatchMonitor() mon.watch_directory(src_dir, file_changed) while running: if len(packet_list) > 0: p = packet_list.pop(0) for i in range(1): sys.stdout.write(p) while len(packet_list) == 0: cm += 1 cm %= len(m) packet_list = m[cm].next_page_packets() if cm == 0: packet_list.append(packet_830()) ret = mon.event_pending() if ret > 0: ret = mon.handle_one_event() time.sleep(0.001)
def run_service(persistent=False): mainloop = gobject.MainLoop() dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) slip.dbus.mainloop.mainloop_class = slip.dbus.mainloop.GlibMainLoop system_bus = slip.dbus.SystemBus() name = dbus.service.BusName(dbus_service_name, system_bus) filemon = gamin.WatchMonitor() filemon_fd = filemon.get_fd() dbus_herder_objects = [] for herder_cls in herder_classes: herder = herder_cls(filemon) dbus_herder_object = DBusServiceHerder(name, dbus_service_path + "/ServiceHerders/%s" % herder_cls.__name__, herder, persistent=persistent) dbus_herder_objects.append(dbus_herder_object) def filemon_handle_events(source, condition, data=None): filemon.handle_events() return True gobject.io_add_watch(filemon_fd, gobject.IO_IN | gobject.IO_PRI, filemon_handle_events) slip.dbus.service.set_mainloop(mainloop) print "Running system-config-services dbus service at '%s'." % \ dbus_service_name mainloop.run()
def __init__(self, jail): FileFilter.__init__(self, jail) self.__modified = False # Gamin monitor self.monitor = gamin.WatchMonitor() fd = self.monitor.get_fd() flags = fcntl.fcntl(fd, fcntl.F_GETFD) fcntl.fcntl(fd, fcntl.F_SETFD, flags|fcntl.FD_CLOEXEC) logSys.debug("Created FilterGamin")
def testGamin(): mon = gamin.WatchMonitor() def test(filename, event): print filename, event watch = mon.watch_directory('.', test) time.sleep(1) while True: mon.handle_one_event()
def fileschanged_gamin(topDirs, callback): """version using gamin, which does not have recursive support. I'd have to find subdirs, then add dynamic watches to any new dirs that show up.""" import gamin mon = gamin.WatchMonitor() def cb(path, event, data): fullpath = os.path.join(data, path) log.debug("fileschanged: %s" % fullpath) return callback(fullpath) for d in topDirs: mon.watch_directory(d, cb, d) while 1: mon.handle_events() time.sleep(1) print "done"
def check_support(): global w_pyinotify, w_fam, w_gamin try: import pyinotify as w_pyinotify except ImportError: w_pyinotify = None else: try: wm = w_pyinotify.WatchManager() wm = w_pyinotify.Notifier(wm) wm = None except: raise w_pyinotify = None try: import gamin as w_gamin except ImportError: w_gamin = None else: try: test = w_gamin.WatchMonitor() test.disconnect() test = None except: w_gamin = None try: import _fam as w_fam except ImportError: w_fam = None else: try: test = w_fam.open() test.close() test = None except: w_fam = None
if os.getenv(tree.lower() + '_path') is None: return try: ishot = int(shot) except: return if node[0] == "\\": node = "\\" + node storeIt((sys.argv[0], path, tree, shot, node)) except Exception, e: print e if CPCI_DATA_DIR is None: print "CPCI_DATA_DIR environment variables required. The monitor will monitor the $CPCI_DATA_DIR/triggers directory" sys.exit(1) mon = gamin.WatchMonitor() mon.watch_directory("%s/triggers" % (CPCI_DATA_DIR, ), callback) time.sleep(1) while mon.handle_one_event(): pass else: from MDSplus import Tree if len(sys.argv) == 5: trigger_file = sys.argv[1] tree = sys.argv[2].upper() if os.getenv(tree.lower() + '_path') is not None: try: shot = int(sys.argv[3]) node = sys.argv[4].upper() print "%s, Doing %s (STOREFTP) in %s shot %d" % ( time.asctime(), node, tree, shot)
def __init__(self, jail): FileFilter.__init__(self, jail) self.__modified = False # Gamin monitor self.monitor = gamin.WatchMonitor() logSys.debug("Created FilterGamin")
def start(self, clustername="", copyFiles=True): if not q.system.fs.exists("/opt/qbase3/lib/libgamin-1.so.0"): #means gamin not installed q.platform.ubuntu.installFileMonitor() sys.path.append("/usr/lib/pymodules/python2.6/") import gamin answer, cluster = False, None if len(q.cluster.list()) == 0: print "No cluster found, creating one" clustername = q.gui.dialog.askString("Name for the new cluster") cluster = q.cluster.create(clustername=clustername) if clustername == "": clustername = q.console.askChoice(q.cluster.list(), "Choose cluster") answer = q.console.askYesNo( "Are you sure you want to replicate to cluster %s" % clustername) if not answer: print "Exiting replicator . . ." return if copyFiles: copyFiles = q.console.askYesNo( "Do you want to synchronize the complete development sandbox to %s now" % clustername) cluster = q.cluster.get(clustername) self.loadRecipe() if not 'all' in self.dirs2monitor.keys(): self.dirs2monitor['all'] = [] self.dirs2monitor['all'].append( q.system.fs.joinPaths("%s_all" % self.baseDir, "lib", "pylabs")) self.dirs2monitor['all'].append( q.system.fs.joinPaths("%s_all" % self.baseDir, "utils")) if copyFiles: #Make sure our basedir is rsyncShared modulename = q.system.fs.getBaseName(self.baseDir) q.codemgmt.rsyncShareQbaseDebug(clustername, modulename) localip = q.manage.rsync.cmdb.ipaddress for nodetype in ['all', 'master']: cluster.execute('/usr/bin/rsync -aL %s::%s/%s_%s/* %s' % (localip, modulename, modulename, nodetype, q.dirs.baseDir), hostnames=cluster.listnodes(nodetype)) def callback(path, event, data): if start == False: return if event == 1: #print "Modidied: %s/%s" % (data,path) pass elif event == 2: #print "Delete: %s/%s" % (data,path) pass elif event == 5: print "Added: %s/%s" % (data, path) if q.system.fs.isDir("%s/%s" % (data, path)): for type, typedirs in self.dirs.iteritems(): if data in typedirs: self.dirs[type].append("%s/%s" % (data, path)) self.monitors[-1].watch_directory( "%s/%s" % (data, path), callback, "%s/%s" % (data, path)) pass else: print "??? %s, %s/%s" % (event, data, path) path = "%s/%s" % (data, path) path = path.strip() if q.system.fs.exists(path) and start and (event == 1 or event == 2): #if q.system.fs.exists(path) and start: #if path[-3:]==".py": self._copyFile(path, cluster) start = False excludes = self.excludes self.dirs = {} starttime = q.base.time.getTimeEpoch() for nodetype, directoryList in self.dirs2monitor.iteritems(): for basedir in directoryList: if not q.system.fs.exists(basedir): raise RuntimeError( """Did not find directory which needs to be monitored. Has the code already been checked out on your filesystem? Use i.codemgmt.checkoutSSOInSandbox(... Directory not found is %s """ % basedir) subdirs = q.system.fs.listDirsInDir(basedir, True) if nodetype in self.dirs.keys(): self.dirs[nodetype].append(basedir) else: self.dirs[nodetype] = [ basedir, ] for item in subdirs: skip = False for excl in excludes: if item.find(excl) <> -1: skip = 1 if skip == False: self.dirs[nodetype].append(item) #make sure dirs are unique alluniquedirs = [] for nodetype, dirlist in self.dirs.iteritems(): uniquedirs = [] for item in dirlist: if item not in uniquedirs and item not in alluniquedirs: #print "Adding %s"%item uniquedirs.append(item) alluniquedirs += uniquedirs self.dirs[nodetype] = uniquedirs nrofdirs = sum(map(lambda l: len(l), self.dirs.itervalues())) if nrofdirs > 5000: raise RuntimeError( "Dir Monitor System max supports 5000 dirs, found %s" % len(dirs)) self.monitors = [] self.monitors.append(gamin.WatchMonitor()) counter = 0 localcounter = 0 for nodetype, dirlist in self.dirs.iteritems(): for item in dirlist: # If we need to copy do it here #if copyFiles: # self._copyDir(item, cluster, nodetype) counter += 1 localcounter += 1 if localcounter == 200: # a new monitor is needed per 200 otherwise can lock q.logger.log("Create new monitor", 2) self.monitors.append(gamin.WatchMonitor()) #time.sleep(2) localcounter = 0 q.logger.log( "%s/%s: add dir %s to monitor %s" % (counter, len(dirlist), item, len(self.monitors)), 2) self.monitors[-1].watch_directory(item, callback, item) q.console.echo('replicating ' + str(nrofdirs) + ' directories') while True: #print "w" time.sleep(1) #mon.event_pending() #ipshell() #mon.handle_one_event() for mon in self.monitors: mon.handle_events() if q.base.time.getTimeEpoch() > starttime + 5: start = True for mon in self.monitors: mon.stop_watch(".") self.monitors = []
def __init__(self): self.mon = gamin.WatchMonitor() self.scanners = [] self.dirs = {}