def up_b_bookname(user_entered_name, oldname, db=None): ''' Update name of a book Make sure to overwirte the old bookname, Make sure to pass in only the user entered part of the name ''' widgettype = oldname.split('-')[0].strip() newname = ' - '.join((widgettype, user_entered_name)) dbtools.updateIt(newname, 'Name', 'Books', "where Name =='" + oldname + "'", mashconfig=False, db=db) condition = "where Bookname =='" + oldname + "'" for data in dbtools.loadItColumn('Name, Program, Profile', 'Pages', condition).fetchall(): page, program, profile = data rest = page[len(oldname):] dbtools.updateIt(newname + rest, 'Name', 'Pages', condition + " and Program == '{0}' and Profile == '{1}'".format( program, profile), mashconfig=False) dbtools.updateIt(newname, 'Bookname', 'Pages', condition, mashconfig=False) dbtools.updateIt(newname, 'Bookname', 'Hotkeys', condition, mashconfig=False) return newname
def get_page_col(col, address, db=None): name = name_from_address(address) condition = "where Name == '" + name + "'" cur = dbtools.loadItColumn(col, 'Pages', condition, db=db) result = cur.fetchone()[0] cur.close() return result
def get_hotkeys(profile, db=None): '''returns a list of all hotkeys for a given profile''' hotkeys = [] condition = "where Profile is '" + profile + "'" cur = dbtools.loadItColumn('Hotkey', 'Hotkeys', condition, db=db) for hotkey in cur.fetchall(): hotkeys.append(dbtools.turnIntoObj(hotkey)) return hotkeys
def all_books(widgettype=True, db=None): ''' return all workbook names ''' cur = dbtools.loadItColumn('Name', 'Books', db=db) if widgettype: return [x[0] for x in cur.fetchall()] else: return [split_bookname(x[0]) for x in cur.fetchall()]
def get_active_profile(db=None): '''Returns the currently active profile''' cond = "where Active == 1" cur = dbtools.loadItColumn(column='Name', table='Profiles', condition=cond, db=db) profile = cur.fetchone()[0] return profile
def make_bookname(name, widgettype=None, profile=None, db=None): if not widgettype: assert profile cond = "where Book == '{0}' and Profile =='{1}'".format(name, profile) cur = dbtools.loadItColumn('WidgetType', 'Books', cond, db=db) widgettype = cur.fetchone()[0] cur.close() bookname = widgettype + ' - ' + name return bookname
def up_b_hotkey(value, bookname, db=None): ''' Update The hotkey for a Book returns the old keycode so you can unregister the key if you wish ''' condition = "where Bookname =='" + bookname + "'" old_hk = dbtools.turnIntoObj( dbtools.loadItColumn('Hotkey', 'Hotkeys', condition).fetchone()[0]) try: dbtools.updateIt({'Hotkey': value}, True, 'Hotkeys', condition, db=db) except: raise UniqueHotkeyError('Hotkey not unique') return old_hk
def create_link(app, uncpath, filepath, db=None): ''' point a uncpath to a specifc file this is done by reading the symlink and modifying it TODO if the uncpath doesn't exist it will be created ''' # profile, book, program, specific = parse_address( # filepath, db=db) get_my_link = name_from_address(filepath) update_my_link = name_from_address(uncpath) cur = dbtools.loadItColumn( 'Symlink', table='Pages', condition="where Name == '{}'".format(get_my_link)) # new_link_path = readlink(os.path.join(app.symlinkdir, # cur.fetchone()[0])) name = cur.fetchone()[0] new_link_path = readlink(os.path.join(app.symlinkdir, name)) cur = dbtools.loadItColumn( 'Symlink', table='Pages', condition="where Name == '{}'".format(update_my_link)) old_link_name = cur.fetchone()[0] update_me = os.path.join(app.symlinkdir, old_link_name) print('from ', get_my_link) print('from ', filepath) print('updating {} from {} -> {}'.format(old_link_name, name, new_link_path)) print('the symlink from the other file ', readlink(os.path.join(app.symlinkdir, old_link_name))) os.remove(update_me) symlink(new_link_path, update_me)
def create_page(book, program, profile, specific=None, db=None): options = { 'PathToLoad': None, 'Profile': profile, 'Bookname': book, 'Program': program, 'Symlink': None, 'SpecificName': specific, 'db': db, } display_name = book.split()[0] condition = "where Name == '" + display_name + "'" cur = dbtools.loadItColumn('ClassName', 'WidgetTypes', condition, db=db) category = cur.fetchone()[0] import newPage new_page = eval('newPage.' + category + '(options)') new_page.save_instance()
def all_profiles(db=None): ''' Returns a list of profiles on the system ''' cur = dbtools.loadItColumn('Name', 'Profiles', db=db) return [x[0] for x in cur.fetchall()]