Ejemplo n.º 1
0
 def __init__(self):
     # use the Borg "un-pattern", p208  of the "Python Cookbook" - since we only
     # want/need  a single connection to FAM
     self.__dict__ = self._shared_state
     import _fam
     if not self.__dict__.has_key("_fam_connection"):
         self._fam_connection = _fam.open()
Ejemplo n.º 2
0
  def __init__(self, parent, pathname, poll_time, event):
    self.suspend = None
    self.cont = None
    self.intr = None
    self.usr1 = None
    self.usr2 = None

    self.event = event

    Thread.__init__(self)
    self.parent = parent
    self.pathname = pathname
    self.poll_time = poll_time
    self.fam_conn = _fam.open()
    self.request = self.fam_conn.monitorFile(self.pathname, None)
    
    signal.signal(signal.SIGTSTP, self.handle_stop)
    signal.signal(signal.SIGCONT, self.handle_cont)
    signal.signal(signal.SIGINT, self.handle_int)
    signal.signal(signal.SIGUSR1, self.handle_usr1)
    signal.signal(signal.SIGUSR2, self.handle_usr2)

    default =  """poll_time=1
file=/var/log/errors
file=/var/log/messages"""

    conf_mgr = Conf_Manager('~/.pylogvrc', default)
Ejemplo n.º 3
0
    def initRequests(self):
        """
		Initialize all fam requests
		"""
        config = ConfigParser.SafeConfigParser()
        config.read(self.conffile)
        ignored = config.get('Main', 'ignored').split()
        logging.debug("list of ignored configurations: %s", " ".join(ignored))
        if self.fam is not None:
            self.closeRequests()
        self.fam = _fam.open()
        prefixes = sn.get_prefixes(ignored)
        logging.debug("list of prefixes found: %s", " ".join(prefixes))
        for prefix in prefixes:
            dir = sn.SZARPDIR + "/%s/szbase/Status/Meaner3/program_uruchomiony" % prefix
            self.reqs[prefix] = self.LADRequest()
            self.reqs[prefix].fr = self.fam.monitorDirectory(dir, prefix)
            params = sn.SZARPDIR + "/%s/config/params.xml" % prefix
            self.reqs[prefix].frp = self.fam.monitorFile(params, prefix)
            try:
                self.reqs[prefix].tests = sn.get_test_params(prefix)
            except SAXParseException:
                continue
            try:
                self.reqs[prefix].max_delay = int(
                    config.get(prefix, 'max_delay'))
            except ConfigParser.NoSectionError, e:
                pass
            except ConfigParser.NoOptionError, e:
                pass
Ejemplo n.º 4
0
	def initRequests(self):
		"""
		Initialize all fam requests
		"""
		config = ConfigParser.SafeConfigParser()
		config.read(self.conffile)
		ignored = config.get('Main', 'ignored').split()
		logging.debug("list of ignored configurations: %s", " ".join(ignored))
		if self.fam is not None:
			self.closeRequests()
		self.fam = _fam.open()
		prefixes = sn.get_prefixes(ignored)
		logging.debug("list of prefixes found: %s", " ".join(prefixes))
		for prefix in prefixes:
			dir = sn.SZARPDIR + "/%s/szbase/Status/Meaner3/program_uruchomiony" % prefix
			self.reqs[prefix] = self.LADRequest()
			self.reqs[prefix].fr = self.fam.monitorDirectory(dir, prefix)
			params = sn.SZARPDIR + "/%s/config/params.xml" % prefix
			self.reqs[prefix].frp = self.fam.monitorFile(params, prefix)
			try:
				self.reqs[prefix].tests = sn.get_test_params(prefix)
			except SAXParseException:
				continue
			try:
				self.reqs[prefix].max_delay = int(config.get(prefix, 'max_delay'))
			except ConfigParser.NoSectionError, e:
				pass
			except ConfigParser.NoOptionError, e:
				pass
Ejemplo n.º 5
0
 def __init__(self, verbose=0):
     # use the Borg "un-pattern", p208 of the "Python Cookbook" - since
     # we only want/need a single connection to FAM
     self.__dict__ = self._shared_state
     import _fam
     if not self.__dict__.has_key("_fam_connection"):
         self._fam_connection = _fam.open()
         self._fam_requests = {}
         self._userData = {}
Ejemplo n.º 6
0
    def doRead(self):
	"called when fam connection has data to read"
        while self._fam_connection.pending():
            try :
                fe = self._fam_connection.nextEvent()
                self._process_fam_events(fe)       
            except IOError, er:
                # sometimes we get "unable to get next event"
#                errnumber, strerr = er
#                print "FAM_Reader.doRead() ", strerr
                print "FAM_Reader.doRead() ", er
                # attempt to recover - otherwise we may just call
                # this repeatedly
                _fam.close()
                self._fam_connection = _fam.open()
		return
    def fileMonitorThreadLoopFAM(self, getmtime=os.path.getmtime):
        modloader.notifyOfNewFiles(self.monitorNewModule)
        self._fc = fc = _fam.open()

        # for all of the modules which have _already_ been loaded, we check
        # to see if they've already been modified or deleted
        for f, mtime in modloader.fileList().items():
            if mtime < getmtime(f):
                try:
                    if mtime < getmtime(f):
                        print '*** The file', f, 'has changed.  The server is restarting now.'
                        self._autoReload = 0
                        return self.shouldRestart()
                except OSError:
                    print '*** The file', f, 'is no longer accessible  The server is restarting now.'
                    self._autoReload = 0
                    return self.shouldRestart()
            # request that this file be monitored for changes
            self._requests.append(fc.monitorFile(f, f))

        # create a pipe so that this thread can be notified when the
        # server is shutdown.  We use a pipe because it needs to be an object
        # which will wake up the call to 'select'
        r, w = os.pipe()
        r = os.fdopen(r, 'r')
        w = os.fdopen(w, 'w')
        self._pipe = pipe = (r, w)
        while self._autoReload:
            try:
                # we block here until a file has been changed, or until
                # we receive word that we should shutdown (via the pipe)
                ri, ro, re = select.select([fc, pipe[0]], [], [])
            except select.error, er:
                errnumber, strerr = er
                if errnumber == errno.EINTR:
                    continue
                else:
                    print strerr
                    sys.exit(1)
            while fc.pending():
                fe = fc.nextEvent()
                if fe.code2str() in ['changed', 'deleted', 'created']:
                    print '*** The file %s has changed.  The server is restarting now.' % fe.userData
                    self._autoReload = 0
                    return self.shouldRestart()
Ejemplo n.º 8
0
    def doRead(self):
        "called when fam connection has data to read"
        while self._fam_connection.pending():
            try:
                fe = self._fam_connection.nextEvent()
                self._process_fam_events(fe)
            except IOError, er:
                # sometimes we get "unable to get next event"
                print "FAM_Reader.doRead():", er
                # close and re-open the FAM connection
                print "FAM_Reader.doRead() closing FAM connection"
                self._fam_connection.close()
                import _fam
                print "FAM_Reader.doRead() opening new FAM connection"
                self._fam_connection = _fam.open()

                for dir in self._fam_requests.keys():
                    self.monitorDirectory(dir, self._userData[dir])
                return
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
class FileMonitorNotAvailable(Exception):
    """Raised when neither gamin nor fam backends are available."""


if gio:
    _gio_file_monitors = {}
    EVENT_CREATED = gio.FILE_MONITOR_EVENT_CREATED
    EVENT_DELETED = gio.FILE_MONITOR_EVENT_DELETED
    EVENT_CHANGED = gio.FILE_MONITOR_EVENT_CHANGED
elif gamin:
    _monitor = gamin.WatchMonitor()
    EVENT_CREATED = gamin.GAMCreated
    EVENT_DELETED = gamin.GAMDeleted
    EVENT_CHANGED = gamin.GAMChanged
elif _fam:
    _fam_conn = _fam.open()
    _fam_requests = {}
    EVENT_CREATED = _fam.Created
    EVENT_DELETED = _fam.Deleted
    EVENT_CHANGED = _fam.Changed

Handler = namedtuple('Handler', [
    'watched_path', 'on_file_deleted', 'on_file_changed', 'on_child_created',
    'on_child_deleted'
])


def _handlers_method(name):
    def _method(self, *args):
        for handler in self.copy():
            handler_func = getattr(handler, name)
Ejemplo n.º 12
0
	def __init__(self, client):
		self.fam = _fam.open()
		self.mon = None
		self.client = client
Ejemplo n.º 13
0
            print 'FAMMonitorDirectory("%s")' % path
        else:
            print 'FAMMonitorFile("%s")' % path

def processDirEvents(fe):
    if fe.userData:
        print fe.userData,
    if showreqid:
        print 'req %d' % fe.requestID,
    print fe.filename, fe.code2str()

if len(sys.argv) < 2:
    print 'usage: %s [-r] [-f <filename>] [-d <dirname>]' % sys.argv[0]
    sys.exit(1)

fc = _fam.open()

optlist, args = getopt.getopt(sys.argv[1:], 'f:d:r')

for arg, value in optlist:
    if arg == '-r':
        showreqid = 1

for arg, filename in optlist:
    if arg == '-f':
        requests[filename] = TestRequest('FILE %s: ' % filename, None)
    if arg == '-d':
        requests[filename] = TestRequest('DIR %s: ' % filename, 1)
        
signal.signal(signal.SIGTSTP, handle_stop)
signal.signal(signal.SIGCONT, handle_cont)
Ejemplo n.º 14
0
 def __init__(self, ignore=None, debug=False):
     FileMonitor.__init__(self, ignore=ignore, debug=debug)
     self.fm = _fam.open()
     self.users = {}
Ejemplo n.º 15
0
 def __init__(self, ignore=None, debug=False):
     FileMonitor.__init__(self, ignore=ignore, debug=debug)
     self.filemonitor = _fam.open()
     self.users = {}
Ejemplo n.º 16
0
 def __init__(self, ignore=None, debug=False):
     FileMonitor.__init__(self, ignore=ignore, debug=debug)
     self.filemonitor = _fam.open()
     self.users = {}
     LOGGER.warning("The Fam file monitor backend is deprecated. Please "
                    "switch to a supported file monitor.")