Ejemplo n.º 1
0
def watch(basepath):

    def callback(path, isrec):
		#print "modified"
		conn = httplib.HTTPConnection(DOMAIN)
		conn.request("GET", REFRESH_SERVLET)
		r1 = conn.getresponse()
		#print r1.status
		conn.close()


    pyfsevents.registerpath(basepath, callback)
    pyfsevents.listen()
Ejemplo n.º 2
0
    TEMPLATE_DIR = TEMPLATE_DIR
    TEMPLATE_JS = TEMPLATE_JS

    # Are we redefining the javascript var?
    if opts.var:
        TEMPLATE_VAR = opts.var

    # If we got this far, run the masher at least once
    run()

    # Do we want to watch the directory for changes?
    if opts.watch:

        # Implemented for Mac OS X
        from platform import system
        if system() != "Darwin":
            raise NotImplementedError("Watching not supported on %s" % system())

        # Try to import pyfsevents
        try:
            import pyfsevents

            # Okay, register the event and enter the loop
            print('»\tWatching %s' % TEMPLATE_DIR)
            pyfsevents.registerpath(TEMPLATE_DIR, run)
            pyfsevents.listen()
        except ImportError:
            print '\033[1;31mInstall pyfsevents http://bitbucket.org/nicdumz/fsevents\033[1;m'
            exit()
Ejemplo n.º 3
0
def monitor(path, verbose=False):

	logger = logging.getLogger('')

	handler = logging.StreamHandler()
	handler.setLevel(logging.DEBUG)
	handler.setFormatter(ColorFormatter())
	logger.addHandler(handler)

	if verbose:
		logger.setLevel(logging.DEBUG)
	else:
		logger.setLevel(logging.INFO)

	path = os.path.abspath(path)
	
	if not os.path.isdir(path):
		logging.error('Not a directory: %s' % path)
		return
	
	# We'll get a callback that the monitored directory changed. To determine
	# which file was changed we keep a checksum and compare it when the directory
	# change event is received
	checksums = {}

	files = os.listdir(path)
	for filename in files:
		
		# Only monitor files with the .xib extension
		if not isXibFile(filename):
			continue

		checksums[filename] = hashfile(os.path.join(path, filename))
	
	def rebuild(path, recursive):

		for filename in os.listdir(path):

			if not isXibFile(filename):
				continue

			checksum = hashfile(os.path.join(path, filename))
			cachedChecksum = checksums.get(filename, None)
			
			if cachedChecksum == checksum:
				continue

			# Cache the new checksum because it was changed
			checksums[filename] = checksum

			# nib2cib doesn't support absolute paths for the resource path
			# so we use the relative path for the -R option
			xibpath = os.path.join(path, filename)
			cibpath = os.path.join(path, os.path.splitext(filename)[0]) + ".cib"
			
			command = 'nib2cib %s %s -R %s' % (xibpath, cibpath, os.path.relpath(path))
			
			logging.info(command)
			
			output = commands.getstatusoutput(command)[1]
			
			# Unfortunately nib2cib doesn't return proper status so we can't log an error
			# if it exited with a non zero exit status
			# If you need to see errors, use verbose mode
			if not ' '.join(output.split()):
				logging.debug(' '.join(output.split()))
			else:
				logging.debug('No output')

	registerpath(path, rebuild)

	logging.info('Listening for changes at \'%s\'' % path)

	listen()
Ejemplo n.º 4
0
    TEMPLATE_DIR = TEMPLATE_DIR
    TEMPLATE_JS = TEMPLATE_JS

    # Are we redefining the javascript var?
    if opts.var:
        TEMPLATE_VAR = opts.var

    # If we got this far, run the masher at least once
    run()

    # Do we want to watch the directory for changes?
    if opts.watch:

        # Implemented for Mac OS X
        from platform import system
        if system() != "Darwin":
            raise NotImplementedError("Watching not supported on %s" %
                                      system())

        # Try to import pyfsevents
        try:
            import pyfsevents

            # Okay, register the event and enter the loop
            print('»\tWatching %s' % TEMPLATE_DIR)
            pyfsevents.registerpath(TEMPLATE_DIR, run)
            pyfsevents.listen()
        except ImportError:
            print '\033[1;31mInstall pyfsevents http://bitbucket.org/nicdumz/fsevents\033[1;m'
            exit()
Ejemplo n.º 5
0
 def startListening(self):
     for p in self.paths:
         pyfsevents.registerpath(p, callback2)
     pyfsevents.listen()
Ejemplo n.º 6
0
def monitor(path, verbose=False):

    logger = logging.getLogger('')

    handler = logging.StreamHandler()
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(ColorFormatter())
    logger.addHandler(handler)

    if verbose:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    path = os.path.abspath(path)

    if not os.path.isdir(path):
        logging.error('Not a directory: %s' % path)
        return

    # We'll get a callback that the monitored directory changed. To determine
    # which file was changed we keep a checksum and compare it when the directory
    # change event is received
    checksums = {}

    files = os.listdir(path)
    for filename in files:

        # Only monitor files with the .xib extension
        if not isXibFile(filename):
            continue

        checksums[filename] = hashfile(os.path.join(path, filename))

    def rebuild(path, recursive):

        for filename in os.listdir(path):

            if not isXibFile(filename):
                continue

            checksum = hashfile(os.path.join(path, filename))
            cachedChecksum = checksums.get(filename, None)

            if cachedChecksum == checksum:
                continue

            # Cache the new checksum because it was changed
            checksums[filename] = checksum

            # nib2cib doesn't support absolute paths for the resource path
            # so we use the relative path for the -R option
            xibpath = os.path.join(path, filename)
            cibpath = os.path.join(path,
                                   os.path.splitext(filename)[0]) + ".cib"

            command = 'nib2cib %s %s -R %s' % (xibpath, cibpath,
                                               os.path.relpath(path))

            logging.info(command)

            output = commands.getstatusoutput(command)[1]

            # Unfortunately nib2cib doesn't return proper status so we can't log an error
            # if it exited with a non zero exit status
            # If you need to see errors, use verbose mode
            if not ' '.join(output.split()):
                logging.debug(' '.join(output.split()))
            else:
                logging.debug('No output')

    registerpath(path, rebuild)

    logging.info('Listening for changes at \'%s\'' % path)

    listen()
Ejemplo n.º 7
0
 def startListening(self):
     for p in self.paths:
         pyfsevents.registerpath(p, callback2)
     pyfsevents.listen()