Exemplo n.º 1
0
def main(args):
    # Read in the configuration file
    config = loadConfig(CONFIG_FILE)

    # Record some data and extract the bits on-the-fly
    bits = readRTL(int(config['duration']))

    # Read in the most recent state
    db = Archive()
    tLast, output = db.getData()

    # Find the packets and save the output
    output = parseBitStream(bits,
                            elevation=config['elevation'],
                            inputDataDict=output,
                            verbose=config['verbose'])

    # Save to the database
    db.writeData(time.time(), output)

    # Upload
    wuUploader(config['ID'],
               config['PASSWORD'],
               output,
               archive=db,
               includeIndoor=config['includeIndoor'],
               verbose=config['verbose'])
Exemplo n.º 2
0
 def get(self, *args, **kwargs):
     page = int(args[0]) if int(args[0]) else 1
     offset = (page - 1) * 6
     count = Archive.select().count()
     maxpage = count / 6 + 1
     archives = Archive.select().where((Archive.status == 1) & (Archive.type == 0)).order_by(
         Archive.created_time.desc()).offset(offset).limit(6)
     self.render("list.html", archives=archives, maxpage=maxpage, page=page)
Exemplo n.º 3
0
def main(args):
	# Read in the configuration file
	config = loadConfig(CONFIG_FILE)
	
	# Record some data and extract the bits on-the-fly
	bits = readRTL(int(config['duration']))
	
	# Read in the most recent state
	db = Archive()
	tLast, output = db.getData()
	
	# Find the packets and save the output
	output = parseBitStream(bits, elevation=config['elevation'], inputDataDict=output, verbose=config['verbose'])
		
	# Save to the database
	db.writeData(time.time(), output)
	
	# Upload
	wuUploader(config['ID'], config['PASSWORD'], output, archive=db, 
				includeIndoor=config['includeIndoor'], verbose=config['verbose'])
Exemplo n.º 4
0
 def get(self, *args, **kwargs):
     tag = args[0]
     tag_query = Tag.select().where(Tag.content == tag).first()
     if tag_query:
         archives2tag_query = Archive2Tag.select(Archive2Tag.archive_id).where(Archive2Tag.tag_id == tag_query.id)
         archive_ids = [one.archive_id for one in archives2tag_query]
         archives = Archive.select().where(
             (Archive.id << archive_ids) & (Archive.status == 1) & (Archive.type == 0)).order_by(
             Archive.published_time.desc())
         archives_groups = [{'year': year, 'archives': list(archives)}
                            for year, archives in groupby(archives, key=lambda a: humantime(a.published_time, "%Y"))]
         self.render("timeline.html", archives_groups=archives_groups, first_title="Tag: %s" % tag)
Exemplo n.º 5
0
def main(args):
    # Parse the command line and read in the configuration file
    cmdConfig = parseOptions(args)
    
    # Setup logging
    logger = logging.getLogger(__name__)
    logFormat = logging.Formatter('%(asctime)s [%(levelname)-8s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
    logFormat.converter = time.gmtime
    logHandler = WatchedFileHandler(cmdConfig['logfile'])
    logHandler.setFormatter(logFormat)
    logger.addHandler(logHandler)
    if cmdConfig['debug']:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
        
    # PID file
    if cmdConfig['pidFile'] is not None:
        fh = open(cmdConfig['pidFile'], 'w')
        fh.write("%i\n" % os.getpid())
        fh.close()
        
    # CherryPy configuration
    cherrypy.config.update({'server.socket_host': '0.0.0.0', 'server.socket_port': 80, 'environment': 'production'})
    cpConfig = {'/css': {'tools.staticdir.on': True,
                         'tools.staticdir.dir': CSS_PATH},
                  '/js':  {'tools.staticdir.on': True,
                           'tools.staticdir.dir': JS_PATH}
                  }
                
    # Report on who we are
    logger.info('Starting Pi2O.py with PID %i', os.getpid())
    logger.info('All dates and times are in UTC except where noted')
     
    # Load in the configuration
    config = loadConfig(cmdConfig['configFile'])
    
    # Initialize the archive
    history = Archive(config)
    history.start()
    
    # Initialize the hardware
    hardwareZones = initZones(config)
    for previousRun in history.getData(scheduledOnly=True):
        logger.info('Previous run of zone %i was on %s LT', previousRun['zone'], datetime.fromtimestamp(previousRun['dateTimeStart']))
        
        if hardwareZones[previousRun['zone']-1].lastStart == 0:
            hardwareZones[previousRun['zone']-1].lastStart = previousRun['dateTimeStart']
            hardwareZones[previousRun['zone']-1].lastStop = previousRun['dateTimeStop']
            
    # Initialize the scheduler
    bg = ScheduleProcessor(config, hardwareZones, history)
    bg.start()
    
    # Initialize the web interface
    ws = Interface(config, hardwareZones, history)
    #cherrypy.quickstart(ws, config=cpConfig)
    cherrypy.tree.mount(ws, "/", config=cpConfig)
    cherrypy.engine.start()
    cherrypy.engine.block()
    
    # Shutdown process
    logger.info('Shutting down Pi2O, please wait...')
    
    # Stop the scheduler thread
    bg.cancel()
    
    # Make sure the sprinkler zones are off
    for i,zone in enumerate(hardwareZones):
        if zone.isActive():
            zone.off()
            history.writeData(time.time(), i, 'off')
            
    # Shutdown the archive
    history.cancel()
    
    # Save the final configuration
    saveConfig(cmdConfig['configFile'], config)
Exemplo n.º 6
0
def main(args):
	# Parse the command line and read in the configuration file
	cmdConfig = parseOptions(args)
	
	# Setup logging
	logger = logging.getLogger(__name__)
	logFormat = logging.Formatter('%(asctime)s [%(levelname)-8s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
	logFormat.converter = time.gmtime
	logHandler = WatchedFileHandler(cmdConfig['logfile'])
	logHandler.setFormatter(logFormat)
	logger.addHandler(logHandler)
	if cmdConfig['debug']:
		logger.setLevel(logging.DEBUG)
	else:
		logger.setLevel(logging.INFO)
		
	# PID file
	if cmdConfig['pidFile'] is not None:
		fh = open(cmdConfig['pidFile'], 'w')
		fh.write("%i\n" % os.getpid())
		fh.close()
		
	# CherryPy configuration
	cherrypy.config.update({'server.socket_host': '0.0.0.0', 'environment': 'production'})
	cpConfig = {'/css': {'tools.staticdir.on': True,
						 'tools.staticdir.dir': CSS_PATH},
          		'/js':  {'tools.staticdir.on': True,
          				 'tools.staticdir.dir': JS_PATH}
          		}
				
	# Report on who we are
	logger.info('Starting wxPi.py with PID %i', os.getpid())
	logger.info('All dates and times are in UTC except where noted')
	
	# Load in the configuration
	config = loadConfig(cmdConfig['configFile'])
	
	# Get the latest from the database
	db = Archive()
	db.start()
	
	tData, sensorData = db.getData()
	if time.time() - tData > 2*config.getfloat('Station', 'duration'):
		sensorData = {}
		
	# Initialize the LEDs
	leds = initLEDs(config)
	
	# Make sure the database has provided something useful.  If not, we need to
	# run several iterations to build up the current picture of what is going on.
	if len(sensorData.keys()) == 0:
		buildState = True
		loopsForState = 3
	else:
		buildState = False
		loopsForState = 1
		
	# Start the sensor polling
	bg = PollingProcessor(config, db, leds, buildState=buildState, loopsForState=loopsForState, sensorData=sensorData)
	bg.start()
	
	# Initialize the web interface
	ws = Interface(config, db, leds)
	#cherrypy.quickstart(ws, config=cpConfig)
	cherrypy.tree.mount(ws, "/", config=cpConfig)
	cherrypy.engine.start()
	cherrypy.engine.block()
	
	# Shutdown process
	logger.info('Shutting down wxPi, please wait...')
	
	# Stop the polling thread
	bg.cancel()
	
	# Make sure the LEDs are off
	for color in leds.keys():
		leds[color].off()
		
	# Shutdown the archive
	db.cancel()
Exemplo n.º 7
0
 def get(self, *args, **kwargs):
     archives = Archive.select().where((Archive.status == 1) & (Archive.type == 0)).order_by(
         Archive.published_time.desc())
     self.set_header("Content-Type", "application/xml")
     self.render("feed.xml", archives=archives)
Exemplo n.º 8
0
 def get(self, *args, **kwargs):
     count = Archive.select().count()
     maxpage = int(count / 6) + 1
     archives = Archive.select().where((Archive.status == 1) & (Archive.type == 0)).order_by(
         Archive.created_time.desc()).offset(0).limit(6)
     self.render("list.html", archives=archives, maxpage=maxpage, page=1)
Exemplo n.º 9
0
def main(args):
    # Parse the command line and read in the configuration file
    cmdConfig = parseOptions(args)

    # Setup logging
    logger = logging.getLogger(__name__)
    logFormat = logging.Formatter('%(asctime)s [%(levelname)-8s] %(message)s',
                                  datefmt='%Y-%m-%d %H:%M:%S')
    logFormat.converter = time.gmtime
    logHandler = WatchedFileHandler(cmdConfig['logfile'])
    logHandler.setFormatter(logFormat)
    logger.addHandler(logHandler)
    if cmdConfig['debug']:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    # PID file
    if cmdConfig['pidFile'] is not None:
        fh = open(cmdConfig['pidFile'], 'w')
        fh.write("%i\n" % os.getpid())
        fh.close()

    # CherryPy configuration
    cherrypy.config.update({
        'server.socket_host': '0.0.0.0',
        'environment': 'production'
    })
    cpConfig = {
        '/css': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': CSS_PATH
        },
        '/js': {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': JS_PATH
        }
    }

    # Report on who we are
    logger.info('Starting wxPi.py with PID %i', os.getpid())
    logger.info('All dates and times are in UTC except where noted')

    # Load in the configuration
    config = loadConfig(cmdConfig['configFile'])

    # Get the latest from the database
    db = Archive()
    db.start()

    tData, sensorData = db.getData()
    if time.time() - tData > 2 * config.getfloat('Station', 'duration'):
        sensorData = {}

    # Initialize the LEDs
    leds = initLEDs(config)

    # Make sure the database has provided something useful.  If not, we need to
    # run several iterations to build up the current picture of what is going on.
    if len(sensorData.keys()) == 0:
        buildState = True
        loopsForState = 3
    else:
        buildState = False
        loopsForState = 1

    # Start the sensor polling
    bg = PollingProcessor(config,
                          db,
                          leds,
                          buildState=buildState,
                          loopsForState=loopsForState,
                          sensorData=sensorData)
    bg.start()

    # Initialize the web interface
    ws = Interface(config, db, leds)
    #cherrypy.quickstart(ws, config=cpConfig)
    cherrypy.tree.mount(ws, "/", config=cpConfig)
    cherrypy.engine.start()
    cherrypy.engine.block()

    # Shutdown process
    logger.info('Shutting down wxPi, please wait...')

    # Stop the polling thread
    bg.cancel()

    # Make sure the LEDs are off
    for color in leds.keys():
        leds[color].off()

    # Shutdown the archive
    db.cancel()