Example #1
0
 def register(self):
     """Register class relationships
     
     """
     # Application, AppInterface and AppProperty
     Registry.register(Application, AppInterface, AppProperty)
     # AppInterface and the concrete classes
     Registry.register(Reflector, AzureIotHttps, AppInterface)
Example #2
0
	def setup(cls, database):
		Log.info("Initializing database")
		# create the database connection pool 
		# sqlite requires that foreign key support be turned on with every connection
		# to ensure that we have this turned on we use only one connection 
		Registry.DBPOOL = adbapi.ConnectionPool('sqlite3', database=database, check_same_thread=False, cp_max=1)
		# register our classes with the registry
		Registry.register(Record, Measurement)
Example #3
0
    def setUp(self):
        configfile = os.path.join(
            os.path.dirname(inspect.getsourcefile(TestBase)), "test.conf")

        config.read_config(configfile)

        Registry.DBPOOL = adbapi.ConnectionPool(config.dbtype,
                                                **config.dbparams)
        Registry.register(models.Cracker, models.Report, models.Legacy)

        yield database.clean_database()
        main.configure_logging()
Example #4
0
    def setUp(self, config_basename="test.conf"):
        configfile = os.path.join(
            os.path.dirname(inspect.getsourcefile(TestBase)),
            config_basename
        )

        config.read_config(configfile)

        Registry.DBPOOL = adbapi.ConnectionPool(config.dbtype, **config.dbparams)
        Registry.register(models.Cracker, models.Report, models.Legacy)

        yield database.clean_database(quiet=True)
        main.configure_logging()
Example #5
0
    def setupRegistry(self, passd):
        user, db = self.db_data
        self.logger.info("Starting MySQL DB Pool... @{0}:{1}".format(*self.db_data))
        try:
            Registry.register(Penguin, Igloo, Avatar, Currency, Ninja, Asset, Ban, CareItem, Friend, Request, Ignore,
                              Inventory, Mail, Membership, MusicTrack, Puffle, Stamp, StampCover, Coin)
            Registry.register(Igloo, IglooFurniture, IglooLike)

            Registry.DBPOOL = ReconnectingMySQLConnectionPool('MySQLdb', user=user, passwd=passd, db=db, cp_reconnect=True)
            self.conn = True
    
        except Exception, e:
            self.logger.error("Unable to start MySQL Pool on given details. (E:{0})".format(e))
            self.conn = False
Example #6
0
    try:
        config.read_config(args.config)
    except ConfigParser.NoSectionError, e:
        print(
            "Error in reading the configuration file from \"{}\": {}.".format(
                args.config, e))
        print(
            "Please review the configuration file. Look at the supplied denyhosts-server.conf.example for more information."
        )
        sys.exit()

    configure_logging()

    Registry.DBPOOL = adbapi.ConnectionPool(config.dbtype, **config.dbparams)
    Registry.register(models.Cracker, models.Report, models.Legacy)

    single_shot = False

    if not args.force and (args.recreate_database or args.evolve_database
                           or args.purge_legacy_addresses
                           or args.purge_reported_addresses
                           or args.recreate_database
                           or args.purge_ip is not None):
        print(
            "WARNING: do not run this method when denyhosts-server is running."
        )
        reply = raw_input("Are you sure you want to continue (Y/N): ")
        if not reply.upper().startswith('Y'):
            sys.exit()
Example #7
0
# -*- coding: utf-8 -*-

from twistar.dbobject import DBObject
from twistar.registry import Registry


class User(DBObject):
    HASMANY = [
        'media_encryption_keys',
    ]


class MediaEncryptionKey(DBObject):
    BELONGSTO = [
        'user',
    ]


Registry.register(User, MediaEncryptionKey)
Example #8
0
    configfile = args.config

    try:
        config.read_config(args.config)
    except ConfigParser.NoSectionError, e:
        print("Error in reading the configuration file from \"{}\": {}.".format(args.config, e))
        print("Please review the configuration file. Look at the supplied denyhosts-server.conf.example for more information.")
        sys.exit()

    configure_logging()

    peering.load_keys()

    Registry.DBPOOL = adbapi.ConnectionPool(config.dbtype, **config.dbparams)
    Registry.register(models.Cracker, models.Report, models.Legacy)

    single_shot = False

    if not args.force and (args.recreate_database
        or args.evolve_database
        or args.purge_legacy_addresses
        or args.purge_reported_addresses
        or args.recreate_database
        or args.bootstrap_from_peer
        or args.purge_ip is not None):
        print("WARNING: do not run this method when denyhosts-server is running.")
        reply = raw_input("Are you sure you want to continue (Y/N): ")
        if not reply.upper().startswith('Y'):
            sys.exit()
Example #9
0
    HASONE = ['avatar']
    HABTM = ['favorite_colors']

class Picture(DBObject):
    BELONGSTO = ['user']

class Avatar(DBObject):
    pass

class FavoriteColor(DBObject):
    HABTM = ['users']    

class FakeObject(DBObject):
    pass

class Coltest(DBObject):
    pass

class Boy(DBObject):
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]

class Girl(DBObject):
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]    

class Nickname(DBObject):
    BELONGSTO = [{'name': 'nicknameable', 'polymorphic': True}]


Registry.register(Picture, User, Avatar, FakeObject, FavoriteColor)
Registry.register(Boy, Girl, Nickname)
Example #10
0
    conn = psycopg2.connect(user=user, password=password, database=database)
    cur = conn.cursor()
    register_composite('label', cur, globally=True, factory=LabelComposite)
    register_composite('security_attribute', cur, globally=True, factory=SecuritAttributeComposite)

    cur.execute("SELECT oid FROM pg_type WHERE typname = 'timestamptz';")
    timestamptz_oid = cur.fetchone()[0]

    DT = psycopg2.extensions.new_type((timestamptz_oid,), "timestamptz", castDatetime)
    psycopg2.extensions.register_type(DT)

    conn.close()

    Registry.DBPOOL = adbapi.ConnectionPool('psycopg2', user=user, password=password, database=database)




# ORM Objects

class ServiceConnection(DBObject):
    HASMANY = ['SubConnections']


class SubConnection(DBObject):
    BELONGSTO = ['ServiceConnection']


Registry.register(ServiceConnection, SubConnection)

Example #11
0
    pass


class Table(DBObject):
    HABTM = ['pens']
    HASMANY = ['rubbers']


class Rubber(DBObject):
    pass


class Role(DBObject):
    BELONGSTO = ['serviceclass']


class Serviceclass(DBObject):
    HASMANY = ['roles']
    BELONGSTO = ['superclass']


class Superclass(DBObject):
    HASONE = ['serviceclass']


Registry.register(Picture, User, Comment, Avatar, FakeObject, FavoriteColor)
Registry.register(Boy, Girl, Nickname)
Registry.register(Blogpost, Category)
Registry.register(Pen, Table, Rubber)
Registry.register(Role, Serviceclass, Superclass)
Example #12
0
    def __eq__(self, other):
        """
        Determine if this object is the same as another (only taking
        the type of the other class and it's C{id} into account).

        @param other: The other object to compare this one to.

        @return: A boolean.
        """
        eqclass = self.__class__.__name__ == other.__class__.__name__
        eqid = hasattr(other, 'id') and self.id == other.id
        return eqclass and eqid


    def __neq__(self, other):
        """
        Determine if this object is not the same as another (only taking
        the type of the other class and it's C{id} into account).

        @param other: The other object to compare this one to.

        @return: A boolean.
        """        
        return not self == other


    __repr__ = __str__


Registry.register(DBObject)
Example #13
0
def register_classes(*args):
    Registry.register(*args)
Example #14
0
    def __getattr__(self, attr_name):
        if hasattr(self._nodes, attr_name):
            return getattr(self._nodes, attr_name)
        elif hasattr(self._tasks, attr_name):
            return getattr(self._tasks, attr_name)
        else:
            raise AttributeError(attr_name)

    def update(self,name,description,status):
        self.status=status
        self.description=description
        log.msg("Environment ",name," updated succesfully",system="Environement manager",logLevel=logging.INFO)
        return self
        

Registry.register(Environment, Node)
Registry.register(Environment, Task)
Registry.register(Task, PrintAction)
Registry.register(Task, Action)
#Registry.register(Task, Condition)
Registry.register(Node, Driver)


class EnvironmentManager(object):
    """
    Class acting as a central access point for all the functionality of environments
    """
    envPath=None
    environments={}
    idCounter=1
    def __init__(self,envPath):
            self.intent_formula_version
        }

        if self.date_created:
            values_dict["date_created"] = self.date_created.isoformat()

        for intent_keyword in self.intent_keywords:
            for field_type in KEYWORD_RECORDING_TYPES:
                keyword_field_name = "{}_{}".format(intent_keyword, field_type)
                values_dict[keyword_field_name] = getattr(
                    self, keyword_field_name)

        return values_dict


Registry.register(PresenceBrowsingData, PresenceBrowsingIntentSnapshot)


@inlineCallbacks
def non_blocking_create_presence_browsing_session_data_row():
    presence_browsing_session_data_row = PresenceBrowsingData()

    for browsing_keyword in PRESENCE_INTENT_KEYWORDS:
        setattr(presence_browsing_session_data_row,
                "{}_{}".format(browsing_keyword, "clicks"), 0)
        setattr(presence_browsing_session_data_row,
                "{}_{}".format(browsing_keyword, "hover_time"), 0.0)

    current_date_time = datetime.utcnow()
    presence_browsing_session_data_row.date_created = current_date_time
    presence_browsing_session_data_row.date_last_updated = current_date_time
Example #16
0
def run_main():
    global configfile
    global maintenance_job, legacy_sync_job
    global main_xmlrpc_handler

    parser = argparse.ArgumentParser(description="DenyHosts sync server")
    parser.add_argument("-c", "--config", default="/etc/dh_syncserver.conf", help="Configuration file")
    parser.add_argument("--recreate-database", action="store_true", help="Wipe and recreate the database")
    parser.add_argument(
        "--evolve-database", action="store_true", help="Evolve the database to the latest schema version"
    )
    parser.add_argument(
        "--purge-legacy-addresses",
        action="store_true",
        help="Purge all hosts downloaded from the legacy server. DO NOT USE WHEN DH_SYNCSERVER IS RUNNING!",
    )
    parser.add_argument(
        "--purge-reported-addresses",
        action="store_true",
        help="Purge all hosts that have been reported by clients. DO NOT USE WHEN DH_SYNCSERVER IS RUNNING!",
    )
    parser.add_argument(
        "--purge-ip",
        action="store",
        help="Purge ip address from both legacy and reported host lists. DO NOT USE WHEN DH_SYNCSERVER IS RUNNING!",
    )
    parser.add_argument(
        "-f", "--force", action="store_true", help="Do not ask for confirmation, execute action immediately"
    )
    args = parser.parse_args()

    configfile = args.config

    config.read_config(args.config)

    configure_logging()

    Registry.DBPOOL = adbapi.ConnectionPool(config.dbtype, **config.dbparams)
    Registry.register(models.Cracker, models.Report, models.Legacy)

    single_shot = False

    if not args.force and (
        args.recreate_database
        or args.evolve_database
        or args.purge_legacy_addresses
        or args.purge_reported_addresses
        or args.recreate_database
        or args.purge_ip is not None
    ):
        print("WARNING: do not run this method when dh_syncserver is running.")
        reply = raw_input("Are you sure you want to continue (Y/N): ")
        if not reply.upper().startswith("Y"):
            sys.exit()

    if args.recreate_database:
        single_shot = True
        database.clean_database().addCallbacks(stop_reactor, stop_reactor)

    if args.evolve_database:
        single_shot = True
        database.evolve_database().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_legacy_addresses:
        single_shot = True
        controllers.purge_legacy_addresses().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_reported_addresses:
        single_shot = True
        controllers.purge_reported_addresses().addCallbacks(stop_reactor, stop_reactor)

    if args.purge_ip is not None:
        single_shot = True
        controllers.purge_ip(args.purge_ip).addCallbacks(stop_reactor, stop_reactor)

    if not single_shot:
        signal.signal(signal.SIGHUP, sighup_handler)
        reactor.addSystemEventTrigger("after", "startup", database.check_database_version)

        main_xmlrpc_handler = views.Server()
        if config.enable_debug_methods:
            d = debug_views.DebugServer(main_xmlrpc_handler)
            main_xmlrpc_handler.putSubHandler("debug", d)
        start_listening(config.listen_port)

        # Set up maintenance and legacy sync jobs
        schedule_jobs()

    # Start reactor
    logging.info("Starting dh_syncserver version {}".format(__init__.version))
    reactor.run()
Example #17
0
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]    

class Nickname(DBObject):
    BELONGSTO = [{'name': 'nicknameable', 'polymorphic': True}]

class Pen(DBObject):
    pass

class Table(DBObject):
    HABTM = ['pens']
    HASMANY = ['rubbers']

class Rubber(DBObject):
    pass

class Role(DBObject):
	BELONGSTO = ['serviceclass']

class Serviceclass(DBObject):
	HASMANY = ['roles']
	BELONGSTO = ['superclass']

class Superclass(DBObject):
	HASONE = ['serviceclass']

Registry.register(Picture, User, Comment, Avatar, FakeObject, FavoriteColor)
Registry.register(Boy, Girl, Nickname)
Registry.register(Blogpost, Category)
Registry.register(Pen, Table, Rubber)
Registry.register(Role, Serviceclass, Superclass)
Example #18
0
    HABTM = ['users']    

class FakeObject(DBObject):
    pass

class Coltest(DBObject):
    pass

class Boy(DBObject):
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]

class Girl(DBObject):
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]    

class Nickname(DBObject):
    BELONGSTO = [{'name': 'nicknameable', 'polymorphic': True}]

class Pen(DBObject):
    pass

class Table(DBObject):
    HABTM = ['pens']
    HASMANY = ['rubbers']

class Rubber(DBObject):
    pass

Registry.register(Picture, User, Comment, Avatar, FakeObject, FavoriteColor)
Registry.register(Boy, Girl, Nickname)
Registry.register(Pen, Table, Rubber)
Example #19
0
    HABTM = [dict(name='blogposts', join_table='posts_categories')]


class FakeObject(DBObject):
    pass


class Coltest(DBObject):
    pass


class Transaction(DBObject):
    pass


class Boy(DBObject):
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]


class Girl(DBObject):
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]


class Nickname(DBObject):
    BELONGSTO = [{'name': 'nicknameable', 'polymorphic': True}]


Registry.register(Picture, User, Comment, Avatar, FakeObject, FavoriteColor)
Registry.register(Boy, Girl, Nickname)
Registry.register(Blogpost, Category)
Example #20
0
    def afterInit(self):
        """
        depickle our config
        """
        if hasattr(self, 'config'):
            self.config = cPickle.loads(self.config)


    def beforeSave(self):
        self.config = cPickle.dumps(self.config)


    def setConfig(self, config, subtype):
        self.config = {}
        for field in subtype.fields.keys():
            if field in subtype.requiredFields and config.get(field, "") == "":
                self.errors.add(field, "cannot be blank")
            self.config[field] = config.get(field, "")


class Publisher(DBObject):
    BELONGSTO = ['user', 'node']


class Message(DBObject):
    BELONGSTO = ['node']

Message.validatesPresenceOf('body')

Registry.register(User, Node, Address, Subscription, Publisher, Message)
Example #21
0
                       globally=True,
                       factory=SecuritAttributeComposite)

    cur.execute("SELECT oid FROM pg_type WHERE typname = 'timestamptz';")
    timestamptz_oid = cur.fetchone()[0]

    DT = psycopg2.extensions.new_type((timestamptz_oid, ), "timestamptz",
                                      castDatetime)
    psycopg2.extensions.register_type(DT)

    conn.close()

    Registry.DBPOOL = adbapi.ConnectionPool('psycopg2',
                                            user=user,
                                            password=password,
                                            database=database)


# ORM Objects


class ServiceConnection(DBObject):
    HASMANY = ['SubConnections']


class SubConnection(DBObject):
    BELONGSTO = ['ServiceConnection']


Registry.register(ServiceConnection, SubConnection)
Example #22
0
        return object.__getattribute__(self, name)

    def __eq__(self, other):
        """
        Determine if this object is the same as another (only taking
        the type of the other class and it's C{id} into account).

        @param other: The other object to compare this one to.

        @return: A boolean.
        """
        eqclass = self.__class__.__name__ == other.__class__.__name__
        eqid = hasattr(other, 'id') and self.id == other.id
        return eqclass and eqid

    def __neq__(self, other):
        """
        Determine if this object is not the same as another (only taking
        the type of the other class and it's C{id} into account).

        @param other: The other object to compare this one to.

        @return: A boolean.
        """
        return not self == other

    __repr__ = __str__


Registry.register(DBObject)
Example #23
0
    HABTM = [dict(name='blogposts', join_table='posts_categories')]


class FakeObject(DBObject):
    pass


class Coltest(DBObject):
    pass


class Transaction(DBObject):
    pass


class Boy(DBObject):
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]


class Girl(DBObject):
    HASMANY = [{'name': 'nicknames', 'as': 'nicknameable'}]


class Nickname(DBObject):
    BELONGSTO = [{'name': 'nicknameable', 'polymorphic': True}]


Registry.register(Picture, User, Avatar, FakeObject, FavoriteColor)
Registry.register(Boy, Girl, Nickname)
Registry.register(Blogpost, Category)
Example #24
0
            return getattr(self._tasks, attr_name)
        else:
            raise AttributeError(attr_name)

    def update(self, name, description, status):
        self.status = status
        self.description = description
        log.msg("Environment ",
                name,
                " updated succesfully",
                system="Environement manager",
                logLevel=logging.INFO)
        return self


Registry.register(Environment, Node)
Registry.register(Environment, Task)
Registry.register(Task, PrintAction)
Registry.register(Task, Action)
#Registry.register(Task, Condition)
Registry.register(Node, Driver)


class EnvironmentManager(object):
    """
    Class acting as a central access point for all the functionality of environments
    """
    envPath = None
    environments = {}
    idCounter = 1