Beispiel #1
0
 def test_filepath_exists(self):
     self.assertTrue(Helper.filepath_exists('/etc/passwd'))
     self.assertTrue(Helper.filepath_exists('/etc/bullshit'))
     self.assertFalse(Helper.filepath_exists('/complete_bullshit/bs'))
     self.assertTrue(Helper.filepath_exists('/blubb'))
     self.assertTrue(Helper.filepath_exists('test/__init__.py'))
     self.assertTrue(Helper.filepath_exists('test/invalid_file'))
     self.assertTrue(Helper.filepath_exists('test'))
     self.assertTrue(Helper.filepath_exists('./test'))
     self.assertTrue(Helper.filepath_exists('./test/'))
Beispiel #2
0
 def test_filepath_exists(self):
     self.assertTrue(Helper.filepath_exists('/etc/passwd'))
     self.assertTrue(Helper.filepath_exists('/etc/bullshit'))
     self.assertFalse(Helper.filepath_exists('/complete_bullshit/bs'))
     self.assertTrue(Helper.filepath_exists('/blubb'))
     self.assertTrue(Helper.filepath_exists('test/__init__.py'))
     self.assertTrue(Helper.filepath_exists('test/invalid_file'))
     self.assertTrue(Helper.filepath_exists('test'))
     self.assertTrue(Helper.filepath_exists('./test'))
     self.assertTrue(Helper.filepath_exists('./test/'))
    def init_config_database(self, config_database_path):
        """
        Prepares a sqlite3 database for use as a configuration database. Creates a database with the specified
        filename and creates empty 'Config' and 'TypeDefs' database tables that are going to hold all configuration
        settings.

        :param config_database_path: Path to database file.
        :return:    Returns a cursor to the sqlite3 database connection that can be used for further database
                    operations.
        """
        if not os.path.isfile(config_database_path):
            if not Helper.filepath_exists(config_database_path):
                raise AvivoreConfigException(
                    'Invalid path to configuration database file specified!')
            Helper.output('[W] Configuration database file not found!')
            Helper.output('[W] Creating a new configuration database.')
            Helper.output(
                '[W] Now please store your configuration in database file \'%s\', then try again!'
                % config_database_path)
        dbcon = lite.connect(config_database_path)
        dbcur = dbcon.cursor()
        dbcur.execute(
            'CREATE TABLE IF NOT EXISTS Config (dbpath text, consumer_key text, consumer_secret text, \
            credentials_file text, stream_tracking_keyword text, csv_search_term, interval int)'
        )
        dbcur.execute(
            'CREATE TABLE IF NOT EXISTS TypeDefs (Id int, Regex text, Comment text)'
        )
        return dbcur
Beispiel #4
0
    def init_config_database(self, config_database_path):
        """
        Prepares a sqlite3 database for use as a configuration database. Creates a database with the specified
        filename and creates empty 'Config' and 'TypeDefs' database tables that are going to hold all configuration
        settings.

        :param config_database_path: Path to database file.
        :return:    Returns a cursor to the sqlite3 database connection that can be used for further database
                    operations.
        """
        if not os.path.isfile(config_database_path):
            if not Helper.filepath_exists(config_database_path):
                raise AvivoreConfigException('Invalid path to configuration database file specified!')
            Helper.output('[W] Configuration database file not found!')
            Helper.output('[W] Creating a new configuration database.')
            Helper.output('[W] Now please store your configuration in database file \'%s\', then try again!'
                          % config_database_path)
        dbcon = lite.connect(config_database_path)
        dbcur = dbcon.cursor()
        dbcur.execute(
            'CREATE TABLE IF NOT EXISTS Config (dbpath text, consumer_key text, consumer_secret text, \
            credentials_file text, stream_tracking_keyword text, csv_search_term, interval int)')
        dbcur.execute('CREATE TABLE IF NOT EXISTS TypeDefs (Id int, Regex text, Comment text)')
        return dbcur