Example #1
0
    def __init__(self, path, database_file):
        self.path = path

        # parse config file(s)
        config_filename = cherrypy.config[CONFIG_KEY]
        if not os.path.exists(config_filename):
            raise IOError(errno.ENOENT,
                          "Config file '%s' not found" % config_filename)
        if cherrypy.config.has_key(CONFIG_DEFAULTS_KEY):
            defaults_filename = cherrypy.config[CONFIG_DEFAULTS_KEY]
            # if defaults file doesn't exist, then don't use it
            if not os.path.exists(defaults_filename):
                sys.stderr.write("Warning: configured defaults file "
                                 " '%s' doesn't exist\n" % defaults_filename)
                defaults_filename = None
        else:
            defaults_filename = None
        self._config = ConfigParser(config_filename, defaults_filename)

        # initialise the schedule manager
        schedule_filename = cherrypy.config[SCHEDULE_KEY]
        self._schedule = ScheduleParser(config_filename, schedule_filename)

        # initialise storage
        self._storage = BowerbirdStorage(database_file, self._config,
                                         self._schedule)
Example #2
0
def main():
    # parse commandline options
    parser = OptionParser()
    parser.add_option('-b',
                      '--base_directory',
                      dest='base_directory',
                      help='base directory',
                      default=BASE_DIRECTORY)
    parser.add_option('-c',
                      '--config',
                      dest='config',
                      help='configuration_file')
    parser.add_option('-d',
                      '--database-file',
                      dest='database',
                      help='database file')
    parser.add_option('-s',
                      '--schedule-file',
                      dest='schedule',
                      help='schedule file')
    parser.add_option('-f',
                      '--force-rescan',
                      action='store_true',
                      dest='force_rescan',
                      help='force reconstruction of recordings',
                      default=False)
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      dest='verbose',
                      help='add commentary to the process',
                      default=False)
    (options, args) = parser.parse_args()
    if not options.config:
        options.config = os.path.join(options.base_directory, DEFAULT_CONFIG)
    if not options.database:
        options.database = os.path.join(options.base_directory,
                                        DEFAULT_DATABASE)
    if not options.schedule:
        options.schedule = os.path.join(options.base_directory,
                                        DEFAULT_SCHEDULE)
    if not os.path.exists(options.config):
        print >> sys.stderr, "fatal error: config file '%s' does not exist" % options.config
        sys.exit(1)
    config = ConfigParser(options.config)
    schedule = ScheduleParser(options.config, options.schedule)
    storage = BowerbirdStorage(options.database, config, schedule)

    # if requested, clear all recordings so they are re-constructed
    if options.force_rescan:
        storage.clearRecordingFiles()
        storage.clearRecordings()

    # call the update method
    storage.updateRecordingsFromFiles(options.force_rescan, options.verbose)
Example #3
0
    def config(self,
               config_timestamp=0,
               load_defaults=False,
               cancel=False,
               apply=False,
               export_config=False,
               new_config=None,
               import_config=False,
               **data):
        error = None
        values = None

        if cancel:
            raise cherrypy.HTTPRedirect('/')
        elif export_config:
            # use cherrypy utility to push the file for download. This also
            # means that we don't have to move the config file into the
            # web-accessible filesystem hierarchy
            return cherrypy.lib.static.serve_file(
                os.path.realpath(self._config.filename),
                "application/x-download", "attachment",
                os.path.basename(self._config.filename))
        elif apply:
            # if someone else has modified the config, then warn the user
            # before saving their changes (overwriting the other's changes)
            if int(config_timestamp) == self._config.getTimestamp():
                self.updateConfigFromPostData(self._config, data)

                # update file
                try:
                    self._config.saveToFile()
                    self._config.exportForShell(self._config.filename + ".sh")
                    # bounce back to homepage
                    raise cherrypy.HTTPRedirect('/')
                except IOError as e:
                    # if save failed, put up error message and stay on the page
                    error = 'Error saving: %s' % e
            else:
                error = genshi.HTML('''WARNING:
                        Configuration has been changed externally.<br />
                        If you wish to keep your changes and lose the external
                        changes, then click on 'Apply' again. <br />
                        To lose your changes and preserve the external changes,
                        click 'Cancel'.''')
                # load the post data into a temporary configparser to preserve
                # the user's changes when the page is loaded again. This means
                # we don't have to duplicate the horrible POST-to-config code
                temp_conf = ConfigParser()
                self.updateConfigFromPostData(temp_conf, data)
                values = temp_conf.getValues()
                # the page loading below will send the new config timestamp so
                # we don't have to anything else here.

        if load_defaults:
            values = self._config.getDefaultValues()
        elif import_config:
            if new_config.filename:
                try:
                    values = self._config.parseFile(new_config.file)
                except Exception as e:
                    values = None
                    error = 'Unable to parse config file: "%s"' % e
            else:
                error = 'No filename provided for config import'

        if not values:
            values = self._config.getValues()
        return template.render(station=self.getStationName(),
                               config_timestamp=self._config.getTimestamp(),
                               error=error,
                               using_defaults=load_defaults,
                               values=values,
                               file=self._config.filename,
                               defaults_file=self._config.defaults_filename)