def __update(self):
        Database.macrosdb().commit(
            """UPDATE macros
                SET
                    name=?,
                    code=?,
                    class_name=?,
                    is_button_macros=?,
                    on_board=?,
                    picture=?,
                    guid=?,
                    page=?,
                    description=?,
                    zindex=?,
                    timer_guid=?,
                    plugin_guid=?,
                    namespace=?,
                    page=?,
                    custom_event_guid=?,
                    type=?
                    WHERE id=?""",
            (self.name, self.code, self.class_name, self.is_button_macros,
             self.on_board, self.macros_picture, self.guid, self.page,
             self.description, self.zindex, self.timer_guid, self.plugin_guid,
             self.namespace, self.page, self.custom_event_guid, self.type,
             self.id))

        return self
Example #2
0
	def delete( self ):
		from class_db import Database

		if self.id in CONFIG_IDs:
			return
		query = """DELETE FROM subject_config WHERE id = ?"""
		values = ( self.id, )
		Database.maindb().commit( query, values )
    def __update(self):
        Database.macrosdb().commit(
            """UPDATE custom_event
				SET
					name=?,
					guid=?,
					plugin_guid=?
					WHERE id=?""", (self.name, self.guid, self.plugin_guid, self.id))
        self.update_custom_event()
        return self
	def _update_2( self ):
		if self._version != 1:
			return

		# create `version` column
		query = """
			ALTER TABLE remote_settings
			ADD COLUMN version
		"""
		Database.maindb().commit( query )

		self._version = 2
	def _version( self, value ):
		if not self._ispersistent():
			return

		query = """
			UPDATE remote_settings
			SET version = ?
			WHERE id = ?
		"""

		args = ( value, self.id, )
		Database.maindb().commit( query, args )
Example #6
0
    def save(self):
        if not self.guid:
            self.guid = str(uuid.uuid4())

        json_data = json.dumps(self.documents)
        query = """ mysql query """
        Database.maindb().commit(
            query,
            (self.guid, json_data, self.del_date.strftime(
                self.date_format), self.dshare_guid, self.type))

        return self.guid
Example #7
0
    def __update(self):
        Database.macrosdb().commit(
            """UPDATE timer
				SET
					name=?,
					period=?,
					guid=?,
					plugin_guid=?
					WHERE id=?""",
            (self.name, self.period, self.guid, self.plugin_guid, self.id))
        self.update_timer()
        return self
    def delete(self):
        from class_macro import Macros

        macros_list = Macros.get_macros_by_custom_event_guid(self.guid)
        for macros in macros_list:
            macros.class_name = "NULL"
            macros.custom_event = "NULL"
            macros.is_button_macros = "1"
            macros.on_board = "0"
            macros.save()

        self.unregister()
        Database.macrosdb().commit("""DELETE FROM custom_event WHERE id=?""",
                                   (self.id, ))
Example #9
0
	def _exist( self ):
		from class_db import Database

		if self.id: return self.id
		if self.name in CONFIG_IDs:	return CONFIG_IDs[ name ]

		query = """
			SELECT id
			FROM subject_config
			WHERE
				user_dn = ?
				AND group_dn = ?
				AND user_guid = ?
				AND group_guid = ?
				AND users_in_group = ?
				AND groups_in_user = ?
			"""

		values = (
			self[ 'user_dn' ],
			self[ 'group_dn' ],
			self[ 'user_guid' ],
			self[ 'group_guid' ],
			self.get_attribute( 'users_in_group', 'NULL' ),
			self.get_attribute( 'groups_in_user', 'NULL' ),
		)

		id = Database.maindb().fetch_one( query, values )
		id = id[0] if id else None

		return id
Example #10
0
    def get_by_guid(cls, guid):
        query = """ mysql query """
        row = Database.maindb().fetch_one(query, (str(guid), ))

        if row:
            return Sharing(row)
        return None
    def get_all_button(self):
        db_rows = Database.macrosdb().fetch_all(
            _SQL_SELECT_HEADER +
            "WHERE is_button_macros='1' AND on_board='0'", )

        return [self().__fill_from_row(row)
                for row in db_rows] if db_rows else []
Example #12
0
	def get_by_id( self, id ):
		from class_db import Database

		for config_name, config_id in CONFIG_IDs.items():
			if str( config_id ) == str( id ):
				return LDAPConfig( config = config_name )

		query = """
			SELECT
				email,
				phone,
				password,
				group_dn,
				user_dn,
				user_guid,
				group_guid,
				base_dn,
				groups_in_user,
				users_in_group,
				user_class,
				group_class,
				group_name,
				first_name,
				last_name,
				config_name,
				id
			FROM subject_config WHERE id = ?
			"""
		values = (id,)

		db_row = Database.maindb().fetch_one( query, values )
		return LDAPConfig().__fill_from_row( db_row ) if db_row else None
    def get_macros_by_custom_event_guid(self, custom_event_guid):
        db_rows = Database.macrosdb().fetch_all(
            _SQL_SELECT_HEADER + "WHERE custom_event_guid=?",
            (custom_event_guid, ))

        return [self().__fill_from_row(row)
                for row in db_rows] if db_rows else []
Example #14
0
    def __update(self):
        Database.macrosdb().commit(
            """UPDATE plugin
			SET
				name=?,
				description=?,
				author=?,
				picture=?,
				guid=?,
				zindex=?,
				version=?,
				protected=?
			WHERE id=?""",
            (self.name, self.description, self.author, self.picture, self.guid,
             self.zindex, self.version, self.protected, self.id))

        return self
Example #15
0
	def _update( self, id ):
		from class_db import Database

		if self.id in CONFIG_IDs.values():
			return
		self.id = id
		query = """
			UPDATE subject_config SET email = ?,
				phone = ?,
				password = ?,
				group_dn = ?,
				user_dn = ?,
				user_guid = ?,
				group_guid = ?,
				group_name = ?,
				base_dn = ?,
				groups_in_user = ?,
				users_in_group = ?,
				user_class = ?,
				group_class = ?,
				first_name = ?,
				last_name = ?,
				config_name = ?
			WHERE id = ?"""

		values = (
			self[ 'email' ],
			self[ 'phone' ],
			self[ 'password' ],
			self[ 'group_dn' ],
			self[ 'user_dn' ],
			self[ 'user_guid' ],
			self[ 'group_guid' ],
			self[ 'group_name' ],
			self[ 'base_dn' ],
			self[ 'groups_in_user' ],
			self[ 'users_in_group' ],
			self[ 'user_class' ][-1],
			self[ 'group_class' ][-1],
			self[ 'first_name' ],
			self[ 'last_name' ],
			self.name,
			self.id,
		)

		Database.maindb().commit( query, values )
Example #16
0
    def __insert(self):
        self.guid = str(uuid4()) if self.guid is None else self.guid
        self.id = Database.macrosdb().commit(
            """INSERT INTO timer (name, period, guid, plugin_guid) VALUES (?,?,?,?)""",
            (self.name, self.period, self.guid, self.plugin_guid))

        self.register()
        return self
Example #17
0
    def delete(self, keep_storage=False):
        macros_list = self.get_macros()
        for macro in macros_list:
            macro.delete()
        timer_list = self.get_timer()
        for timer in timer_list:
            timer.delete()
        custom_event_list = self.get_custom_event()
        for cevent in custom_event_list:
            cevent.delete()

        Database.macrosdb().commit("""DELETE FROM plugin WHERE id=?""",
                                   (self.id, ))
        if not keep_storage:
            Database.macrosdb().commit(
                """DELETE FROM kv_macro_storage WHERE namespace=?""",
                (self.guid, ))
	def _update( self ):
		if self.id is None:
			return self

		query = """
			UPDATE remote_settings
			SET
				server = ?,
				login = ?,
				password = ?

			WHERE id = ?
		"""

		args = ( self.server, self.login. self.password, self.id, )
		Database.maindb().commit( query, args )

		return self
    def __insert(self):
        self.guid = str(uuid4()) if self.guid is None else self.guid
        #raise Exception(self.guid, self.name)
        self.id = Database.macrosdb().commit(
            """INSERT INTO custom_event (name, guid, plugin_guid) VALUES (?,?,?)""",
            (self.name, self.guid, self.plugin_guid))

        self.register()
        return self
    def update_all_macro_with_library(cls, library):

        db_rows = Database.macrosdb().fetch_all(
            _SQL_SELECT_HEADER +
            """WHERE plugin_guid=? and code LIKE "%'#include("||?||")%" """,
            (library.plugin_guid, library.name))

        return map(register_macro,
                   [cls().__fill_from_row(row)
                    for row in db_rows] if db_rows else [])
    def get_custom_event_by_plugin_guid(self, plugin_guid):
        db_rows = Database.macrosdb().fetch_all(
            """
			SELECT
				custom_event.id,
				custom_event.name,
				custom_event.guid,
				custom_event.plugin_guid
			FROM `custom_event`
			WHERE custom_event.plugin_guid=?""", (plugin_guid, ))
        return [self().__fill_from_row(row) for row in db_rows]
	def _insert( self ):
		query = """
			INSERT INTO remote_settings (server, login, password)
			VALUES (?, ?, ?)
		"""

		args = ( self.server, self.login, self.password, )

		self.id = Database.maindb().commit( query, args )

		return self
Example #23
0
    def get_timer_by_plugin_guid(self, plugin_guid):
        db_rows = Database.macrosdb().fetch_all(
            """
			SELECT
				timer.id,
				timer.name,
				timer.period,
				timer.guid,
				timer.plugin_guid
			FROM `timer`
			WHERE timer.plugin_guid=?""", (plugin_guid, ))
        return [self().__fill_from_row(row) for row in db_rows]
Example #24
0
	def get_name_list( self ):
		from class_db import Database

		rows = Database.maindb().fetch_all("""SELECT id, config_name FROM subject_config""")

		result = [ [ id, name ] for name, id in CONFIG_IDs.iteritems() ]
		result.reverse()

		for row in rows:
			result.append( [row[0], row[1]] )

		return result
    def get_custom_event_by_guid(self, guid):
        db_row = Database.macrosdb().fetch_one(
            """
			SELECT
				custom_event.id,
				custom_event.name,
				custom_event.guid,
				custom_event.plugin_guid
			FROM `custom_event`
			WHERE custom_event.guid=?""", (guid, ))

        return self().__fill_from_row(db_row) if db_row else None
	def get_all( self ):
		query = """
			SELECT
				id as id,
				server as server,
				login as login,
				password as password

			FROM `remote_settings`
		"""

		rows = Database.maindb().fetch_all( query )
		return [ self()._fill_from_row( row ) for row in rows ]
Example #27
0
    def get_timer_by_guid(self, guid):
        db_row = Database.macrosdb().fetch_one(
            """
			SELECT
				timer.id,
				timer.name,
				timer.period,
				timer.guid,
				timer.plugin_guid
			FROM `timer`
			WHERE timer.guid=?""", (guid, ))

        return self().__fill_from_row(db_row) if db_row else None
	def _version( self ):
		if not self._ispersistent():
			return None

		query = """
			SELECT version as version
			FROM remote_settings
			WHERE id = ?
		"""

		args = ( self.id, )

		row = Database.maindb().fetch_one( query, args )
		return int( row[ 'version' ] ) if row else 1
	def _ispersistent( self ):
		# check by id
		query = """
			SELECT id from remote_settings
			WHERE id = ?
		"""

		args = ( self.id, )
		row = Database.maindb().fetch_one( query, args )
		if row: return True


		# check by content
		query = """
			SELECT id from remote_settings
			WHERE server = ? AND login = ? and password = ?
		"""

		args = ( self.server, self.login, self.password )
		row = Database.maindb().fetch_one( query, args )
		if row: return True

		return False
    def __insert(self):
        self.guid = str(uuid4()) if self.guid is None else self.guid
        self.id = Database.macrosdb().commit(
            "INSERT INTO macros (name, code, class_name, is_button_macros,"
            "on_board, picture, guid, page, description, zindex, timer_guid,"
            "plugin_guid, namespace, page, custom_event_guid,type) VALUES"
            "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
            "",
            (self.name, self.code, self.class_name, self.is_button_macros,
             self.on_board, self.macros_picture, self.guid, self.page,
             self.description, self.zindex, self.timer_guid, self.plugin_guid,
             self.plugin_guid, self.page, self.custom_event_guid, self.type))

        return self