コード例 #1
0
ファイル: config.py プロジェクト: msteinhoff/foption-bot
def config_init(args):
    config_root = os.environ['FPTBOT_CONFIG']
    
    bot = Bot(root=config_root, level=logging.INFO)
    bot.init(runlevel.LOCAL_FILESYSTEM)
    
    logger = logging.getLogger('tools.config')
    
    def _init(identifier, object):
        logger.info('initializing configuration: %s', identifier)
        
        object.init(object.default_values())
        object.save()
    
    if args.identifier is None:
        for (identifier, object) in bot.get_configs().items():
            _init(identifier, object)
    
    else:
        identifier = args.identifier
        
        try:
            object = bot.get_config(identifier)
            
            _init(identifier, object)
        
        except KeyError:
            logger.critical('invalid identifier: %s', identifier)
            
    bot.init(runlevel.HALT)
コード例 #2
0
ファイル: config.py プロジェクト: msteinhoff/foption-bot
def config_write(args):
    config_root = os.environ['FPTBOT_CONFIG']
    
    bot = Bot(root=config_root, level=logging.INFO)
    bot.init(runlevel.LOCAL_FILESYSTEM)
    
    logger = logging.getLogger('tools.config') 
    
    identifier = args.identifier
    key = args.key
    type = args.type
    value = args.value
    
    try:
        object = bot.get_config(identifier)
        
    except KeyError:
        logger.critical('invalid identifier: %s', identifier)
        
    if key not in object.valid_keys():
        logger.critical('invalid key: %s', key)
        return
        
    
    value = ' '.join(value)
    
    if type == 'int':
        new_value = int(value)
        
    elif type == 'bool':
        new_value = bool(value)
        
    elif type == 'list':
        new_value = value.split(',')
    
    else:
        new_value = value
    
    
    object.set(key, new_value)
    object.save()
    
    logger.info('%s.%s set to %s', identifier, key, new_value)
    
    bot.init(runlevel.HALT)
コード例 #3
0
ファイル: config.py プロジェクト: msteinhoff/foption-bot
def config_read(args):
    config_root = os.environ['FPTBOT_CONFIG']
    
    bot = Bot(root=config_root, level=logging.INFO)
    bot.init(runlevel.LOCAL_FILESYSTEM)
    
    logger = logging.getLogger('tools.config')
    
    identifier = args.identifier
    
    def _read(identifier, key, value, padding=0):
        print "{}.{} {}= '{}' ({})".format(identifier, key, ' ' * padding, value, type(value))
    
    try:
        object = bot.get_config(identifier)
    except KeyError:
        logger.critical('invalid identifier: %s', identifier)
        return
        
    if(args.key is None):
        spacelist = [len(item) for item in object.get_all().keys()]
        
        if spacelist:
            space = max(spacelist)
        else:
            space = 0
        
        for (key, value) in object.get_all().items():
            _read(identifier, key, value, (space - len(key)))
        
    else:
        try:
            key = args.key
            value = object.get(key)
        except KeyError:
            logger.critical('invalid key: %s', key)
            return
            
        _read(identifier, key, value)
    
    bot.init(runlevel.HALT)
コード例 #4
0
ファイル: initdb.py プロジェクト: msteinhoff/foption-bot
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@since Aug 15, 2011
@author Mario Steinhoff
"""

__version__ = '$Rev$'

import logging
import os

from core import runlevel
from core.bot import Bot
from core.persistence import SqlAlchemyPersistence

# Load all table definitions
import objects

if __name__ == '__main__':
    config_root = os.environ['FPTBOT_CONFIG']

    bot = Bot(root=config_root, level=logging.INFO)
    bot.init(runlevel.LOCAL_SERVICE)

    persistence = bot.get_subsystem('local-persistence')

    base = SqlAlchemyPersistence.Base
    base.metadata.create_all(persistence.engine)
コード例 #5
0
ファイル: events.py プロジェクト: msteinhoff/foption-bot
"""

__version__ = '$Rev$'

import datetime

from core import runlevel
from core.bot import Bot
from objects.calendar import Calendar, Event
from components.calendar import LocalUserAuthority
from tools import dataloader

if __name__ == '__main__':
    bot = Bot()
    bot.register_subsystem('sqlite-persistence', 'core.persistence.SqlitePersistence', sqlite_file=dataloader.Parameters.source)
    bot.init(runlevel.NETWORK_SERVICE)
    
    sqlite = bot.get_subsystem('sqlite-persistence')
    cursor = sqlite.get_cursor()
    calendar = bot.get_subsystem('calendar-component')
    
    logger = bot.get_logger('tools.import.contacts')
    
    calendar_references = {}
    
    for category in dataloader.get_categories(cursor, dataloader.Parameters.event_categories):
        newCalendar = Calendar()
        newCalendar.title = category['Name']
        newCalendar.color = category['Color'][1:]
        newCalendar.location = dataloader.Parameters.default_location
        newCalendar.authority = LocalUserAuthority.NAME
コード例 #6
0
ファイル: calendar.py プロジェクト: msteinhoff/foption-bot
@author Mario Steinhoff
"""

__version__ = '$$'

import datetime
import json

from core import runlevel
from core.bot import Bot
from objects.calendar import Calendar, Event
from components.calendar import GoogleBackend

try:
    bot = Bot()
    bot.init(runlevel.NETWORK_SERVICE)

    cc = bot.get_subsystem('calendar-component')
    """
    event = Event(start=datetime.date(2011, 9, 26), end=datetime.date(2011, 9, 27), title="sync-test")
    event = cc.insert_object(event)
    
    scnds = cc.datastore.secondary_backends
    gbe = [scnd for scnd in scnds if isinstance(scnd, GoogleBackend)][0]
    
    query = cc.datastore.get_query('event_by_id')
    local_id = [identity for identity in event.identities if identity.backend.typename == 'GoogleBackend'][0]
    
    query.id = json.loads(local_id.identity)['edit']
    
    gev = gbe.find_objects(query)
コード例 #7
0
ファイル: cleandb.py プロジェクト: msteinhoff/foption-bot
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@since Aug 15, 2011
@author Mario Steinhoff
"""

__version__ = '$Rev$'

import logging
import os

from core import runlevel
from core.bot import Bot
from core.persistence import SqlAlchemyPersistence

# Load all table definitions
import objects

if __name__ == '__main__':
    config_root = os.environ['FPTBOT_CONFIG']
    
    bot = Bot(root=config_root, level=logging.INFO)
    bot.init(runlevel.LOCAL_SERVICE)
    
    persistence = bot.get_subsystem('local-persistence')
    
    base = SqlAlchemyPersistence.Base
    base.metadata.drop_all(persistence.engine)
コード例 #8
0
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@since Jan 6, 2011
@author Mario Steinhoff
"""

__version__ = '$Rev$'

import os

from core import runlevel
from core.bot import Bot

if __name__ == '__main__':
    config_root = os.environ['FPTBOT_CONFIG']

    bot = Bot(root=config_root)
    bot.init(runlevel.NETWORK_INTERACTION)
コード例 #9
0
ファイル: bot.py プロジェクト: msteinhoff/foption-bot
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@since Jan 6, 2011
@author Mario Steinhoff
"""

__version__ = '$Rev$'

import os

from core import runlevel
from core.bot import Bot

if __name__ == '__main__':
    config_root = os.environ['FPTBOT_CONFIG']
    
    bot = Bot(root=config_root)
    bot.init(runlevel.NETWORK_INTERACTION)