예제 #1
0
def ufile_get(db, page_id):
    cond = "WHERE Id == '{}'".format(page_id)
    ufile = halt.load_column(db, 'Pages', ('Ufile', ), cond)
    ufile = halt.load_column(db, 'Pages', ('Ufile', ), cond)[0][0]
    if ufile:
        return ufile
    return False
예제 #2
0
 def test_profile_set_active(self):
     dbapi.profile_create(self.db, self.profile)
     dbapi.profile_set_active(self.db, self.profile)
     cond = "where Name == '{}'".format(self.profile)
     data = halt.load_column(self.db, 'Profiles', ('Active', ), cond)[0][0]
     assert data == True
     cond = "where Name == '{}'".format('default')
     data = halt.load_column(self.db, 'Profiles', ('Active', ), cond)[0][0]
     assert data == False
예제 #3
0
def hotkey_pressed(app, profile, program, hotkey, system_pages):
    '''
    profile -> active profile
    hotkey -> the pressed hotkey

    evaluates a hotkey, can either
    * load an existing page
    * create a page, (optionally load it)
    '''
    # TODO DELETE
    global DEVELOPING
    if hasattr(app, 'DEVELOPING'):
        DEVELOPING = app.DEVELOPING

    if DEVELOPING and program in ('python3', 'python'):
        program = 'uncrumpled'

    # Find the book that is bound to the hotkey
    hotkey = json.dumps(hotkey)
    cond = "WHERE Hotkey == '{}' AND \
                  Profile == '{}'".format(hotkey, profile)
    book = halt.load_column(app.db, 'Hotkeys', ('Book', ), cond)[0][0]

    cond = "WHERE Book == '{}' AND \
                  Profile == '{}'".format(book, profile)
    bookopts = json.loads(
        halt.load_column(app.db, 'Books', ('MashConfig', ), cond)[0][0])

    if bookopts['no_process'] == 'read':
        page_id = bookopts.get('read_page')
    else:
        page_id = page_find(app.db, profile, book, program, bookopts)

    # Potentially create and load a new page
    if not page_id:
        response = no_process(app, profile, book, program, hotkey, bookopts)
        if response:
            yield from close_open_pages(system_pages, ignore=page_id)
            create_resp = next(response)
            yield create_resp
            page_id = yield from response
            yield resp.resp('page_load', page_id=page_id)
            yield resp.resp('window_show')
        else:
            yield False
    # Open or close a page
    else:
        if system_pages.get(page_id, {}).get('is_open'):
            yield resp.resp('page_close', page_id=page_id)
            yield resp.resp('window_hide')
        # NOTE, this is a simple work around to make uncrumpled
        # be able to have notepages on it, This implementaiton limits
        # alot of options (we are not using them atm so it is ok)
        else:
            yield from close_open_pages(system_pages, ignore=page_id)
            yield resp.resp('page_load', page_id=page_id)
            yield resp.resp('window_show')
예제 #4
0
def hotkey_get_all(db, profile):
    '''returns a list of all hotkeys for a given profile'''
    hotkeys = []
    cond = "where Profile == '" + profile + "'"
    for hk in halt.load_column(db, 'Hotkeys', ('Hotkey', ), cond):
        hotkeys.append(halt.objectify(hk[0]))
    return hotkeys
예제 #5
0
def page_get_all(db):
    '''
    return eith as address
    or profile book, program, program, specific, loose
    '''
    columns = ('Profile', 'Book', 'Program', 'Specific', 'Loose')
    results = halt.load_column(db, 'Pages', columns)
    for row in results:
        yield row
예제 #6
0
def loose_get_all(db, profile):
    '''returns a list of all loose pages for a given profile'''
    filenames = []
    cond = "where Profile == '" + profile + "'"
    for fname in halt.load_column(db, 'Pages', ('Loose', ), cond):
        fname = fname[0]
        if fname not in util.UNIQUE_NULL:
            filenames.append(fname)
    return filenames
예제 #7
0
def hotkey_get(db, profile, book) -> list:
    ''' get single hotkey based on profile and book'''
    cond = "WHERE Profile=='{}' AND Book=='{}'".format(profile, book)
    hk = halt.load_column(db, 'Hotkeys', ('Hotkey', ), cond)
    try:
        hk = halt.objectify((hk[0][0]))
    except Exception:
        return []
    return hk
예제 #8
0
    def test_profile_create(self):
        rv = dbapi.profile_create(self.db, self.profile)
        assert rv
        cond = "where Name == '{}'".format(self.profile)
        data = halt.load_column(self.db, 'Profiles', ('*', ), cond)[0]
        assert data[0] == self.profile
        assert data[1] != True  # the active column

        rv = dbapi.profile_create(self.db, self.profile)
        assert not rv
예제 #9
0
    def test_profile_set_and_get_active(s):
        profile = 'test'
        s.run(req.profile_create, s.app, profile)
        response = s.run(req.profile_set_active, s.app, profile)
        assert 'profile changed' in response['output_kwargs']['msg'].lower()
        assert response['output_kwargs']['code'] == 1
        data = get_all_data(s.app.db, 'Profiles')

        response = s.run(req.profile_get_active, s.app)
        abc = response
        response['output_method'] == 'noop'
        cond = "where Name == '{}'".format('default')
        default_active = halt.load_column(s.app.db, 'Profiles', ('Active', ),
                                          cond)
        assert not default_active[0][0]
        cond = "where Name == '{}'".format(profile)
        test_active = halt.load_column(s.app.db, 'Profiles', ('Active', ),
                                       cond)
        assert test_active[0][0]
예제 #10
0
def page_rowid_get(db, profile, book, program, specific, loose):
    page = util.page_validate(profile, book, program, specific, loose)
    cond = "WHERE Profile == '{}' AND \
                  Book == '{}' AND \
                  Program == '{}' AND \
                  Specific == '{}' AND \
                  Loose == '{}'".format(*page)
    rowid = halt.load_column(db, 'Pages', ('Id', ), cond=cond)
    if not rowid:
        return False
    else:
        return rowid[0][0]
예제 #11
0
def page_info(db, page_id, rv=list): # TODO delete?
    '''given a page_id, get all page info in as a tuple or dictionary'''
    assert rv in (list, dict)
    cond = "WHERE Id == '{}'".format(page_id)
    result = halt.load_column(db, 'Pages', ('*',), cond)
    import pdb;pdb.set_trace()
    if rv == tuple:
        return result
    else:
        obj = {'Id': page_id, 'Profile': result[1], 'Book': result[2],
               'Program': result[3], 'Specific': result[4],
               'Loose':result[5], 'UFile': result[6], 'MashConfig': result[7]}
        return obj
예제 #12
0
def page_itr(db, profile, book, program):
    '''
    the active profie, program, and the book to which the
    hotkey belongs are required.

    :return: rowid, specific
    '''
    cond = "WHERE Profile == '{}' AND \
                  Book == '{}' AND \
                  Program == '{}'".format(profile, book, program)

    results = halt.load_column(db, 'Pages', (
        'Id',
        'Specific',
    ), cond)
    for x in results:
        yield x
예제 #13
0
def book_create(db, profile, book, hotkey, **kwargs):
    '''
    For creating a new workbook, NOT updating one

    use this with the exceptions
    NoHotkeyError
    UniqueNameError
    UniqueHotkeyError

    On no hotkey the book will still be created

    No changes to db on the other errors

    on success returns the  keycode and masks
    '''
    cond = "where Name = 'System Default'"
    options = halt.load_column(db, 'DefaultOptions', ('MashConfig', ), cond)
    options = halt.objectify(options[0][0])
    for k, v in kwargs.items():
        if k not in options:
            raise KeyError(k +
                           'not recognized, add a default first to dbapi.py')
        else:
            options[k] = v

    options['Book'] = book
    options['Profile'] = profile

    try:
        # i am doing 2 seperate queries that depend on each other
        # the cur is only commited at the end so i dont have to undo anythin on
        # a fail
        if hotkey:
            con = halt.insert(db, 'Books', options, mash=True, commit=False)
            _add_hotkey(db, hotkey, profile, book, con)
            con.commit()  # TODO delete
        else:
            raise NoHotkeyError
    except halt.HaltException:
        raise UniqueNameError('Name for that widget already exists!')
    finally:
        with suppress(UnboundLocalError):
            con.close()
예제 #14
0
def book_get_all(db):
    results = halt.load_column(db, 'Books', ('Book', ))
    return [x[0] for x in results]
예제 #15
0
def profile_get_active(db):
    '''Returns the currently active profile'''
    cond = "where Active == 1"
    results = halt.load_column(db, 'Profiles', ('Name', ), cond)
    profile = results[0][0]
    return profile
예제 #16
0
파일: test_halt.py 프로젝트: Waaotst/halt
 def test_load_column(self):
     data = {'Name': 'bob', 'Password': '******', 'random': 15}
     insert(self.db, 'Test', data, mash=True)
     assert 'bob' == load_column(self.db, 'Test', ('Name',))[0][0]
     assert ('bob', 'pass') == load_column(self.db,
                                          'Test', ('Name', 'Password'))[0]
예제 #17
0
def profile_get_all(db):
    ''' Returns a list of profiles on the system '''
    results = halt.load_column(db, 'Profiles', ('Name', ))
    return [x[0] for x in results]