Exemplo n.º 1
0
def create(pSettingid, pDescription, pType='list', pFilename=None, pFiletype='dict'):
    #check for pickle problems
    if pFiletype == 'dict':
        try:
            pickle_data = list(map(str, list(range(1, 10))))
            pickle_file = open(selfdatatest, 'wb')
            pickle.dump(pickle_data, pickle_file)
            pickle_file.flush()
            pickle_file.close()
            pickle_file = open(selfdatatest, 'rb')
            pickle_file.seek(0)
            pickle_test = pickle.load(pickle_file)
            pickle_file.close()
            os.remove(selfdatatest)
            if pickle_test != pickle_data:
                pFiletype = 'keyvalues'
        except:
            pFiletype = 'keyvalues'
    else:
        pFiletype = 'keyvalues'
    if not pFilename:
        if pFiletype == 'keyvalues':
            pFilename = '%s/%s.txt' % (selfdatapath, pSettingid)
        elif pFiletype == 'dict':
            pFilename = '%s/%s.pkl' % (selfdatapath, pSettingid)
    #create new setting
    if pType == 'list':
        gSettings[pSettingid] = list.Setting_list(pSettingid, pDescription, pFilename, pFiletype)
    elif pType == 'toggle':
        gSettings[pSettingid] = toggle.Setting_toggle(pSettingid, pDescription, pFilename, pFiletype)
    else:
        return None
    return gSettings[pSettingid]
Exemplo n.º 2
0
 def information(self, listlevel):
     if listlevel >= 1:
         es.dbgmsg(0, ' ')
     es.dbgmsg(0, self.name)
     if listlevel >= 1:
         es.dbgmsg(0, '  Description:  '+str(self.keyvalues['config']['descr']))
         es.dbgmsg(0, '  Re-Send:      '+str(self.keyvalues['config']['resend']))
         es.dbgmsg(0, '  Soundfile:    '+str(self.keyvalues['config']['sound']))
     if listlevel >= 2:
         es.dbgmsg(0, '  Players:      '+str(len(list(self.keyvalues['users'].keys()))))
         es.dbgmsg(0, '  Options:      '+str(len(list(self.keyvalues['options'].keys()))))
         for option in list(self.keyvalues['options'].keys()):
             es.dbgmsg(0,'    ['+str(self.keyvalues['options'][option]['keyname'])+']:  '+self.keyvalues['options'][option]['display'])
Exemplo n.º 3
0
 def isValidOption(self, option, passthrough=False):      #checks for valid options
     if option in self.keyvalues['options']:
         return option
     for thisoption in list(self.keyvalues['options'].keys()):
         if self.keyvalues['options'][thisoption]['keyname'] == option:
             return thisoption
     return option if passthrough else False
Exemplo n.º 4
0
 def cleanTypes(self):
     resend = self.keyvalues['config']['resend']
     if isinstance(resend, str):
         try:
             self.keyvalues['config']['resend'] = int(resend)
         except:
             self.keyvalues['config']['resend'] = 1
     for option in list(self.keyvalues['options'].keys()):
         if 'state' in self.keyvalues['options'][option]:
             state = self.keyvalues['options'][option]['state']
             if isinstance(state, str):
                 try:
                     self.keyvalues['options'][option]['state'] = int(state)
                 except:
                     self.keyvalues['options'][option]['state'] = 0
         if 'globstate' in self.keyvalues['options'][option]:
             state = self.keyvalues['options'][option]['globstate']
             if isinstance(state, str):
                 try:
                     self.keyvalues['options'][option]['globstate'] = int(
                         state)
                 except:
                     self.keyvalues['options'][option]['globstate'] = 0
     for steamid in list(self.keyvalues['users'].keys()):
         if 'time' in self.keyvalues['users'][steamid]:
             state = self.keyvalues['users'][steamid]['time']
             if isinstance(state, str):
                 try:
                     self.keyvalues['users'][steamid]['time'] = int(state)
                 except:
                     self.keyvalues['users'][steamid]['time'] = int(
                         time.time())
         if 'data' in self.keyvalues['users'][steamid]:
             for option in list(
                     self.keyvalues['users'][steamid]['data'].keys()):
                 if 'state' in self.keyvalues['users'][steamid]['data'][
                         option]:
                     state = self.keyvalues['users'][steamid]['data'][
                         option]['state']
                     if isinstance(state, str):
                         try:
                             self.keyvalues['users'][steamid]['data'][
                                 option]['state'] = int(state)
                         except:
                             self.keyvalues['users'][steamid]['data'][
                                 option]['state'] = 0
Exemplo n.º 5
0
 def deloption(self, key):          #delete an option
     option = self.isValidOption(key, True)
     if option in self.keyvalues['options']:
         del self.keyvalues['options'][option]
         for steamid in list(self.keyvalues['users'].keys()):
             del self.keyvalues['users'][steamid]['data'][option]
         self.save()
     else:
         raise IndexError('Settinglib: Cannot delete option %s, it does not exists'%key)
Exemplo n.º 6
0
 def initUser(self, userid):
     if es.exists('userid',userid):
         steamid = playerlib.uniqueid(userid, True)
         self.keyvalues['users'][steamid] = self.createKey(steamid)
         self.keyvalues['users'][steamid]['time'] = int(time.time())
         self.keyvalues['users'][steamid]['data'] = self.createKey('data')
         for option in list(self.keyvalues['options'].keys()):
             self.keyvalues['users'][steamid]['data'][option] = self.createKey(option)
             self.keyvalues['users'][steamid]['data'][option]['state'] = self.keyvalues['options'][option]['state']
Exemplo n.º 7
0
 def isValidOption(self,
                   option,
                   passthrough=False):  #checks for valid options
     if option in self.keyvalues['options']:
         return option
     for thisoption in list(self.keyvalues['options'].keys()):
         if self.keyvalues['options'][thisoption]['keyname'] == option:
             return thisoption
     return option if passthrough else False
Exemplo n.º 8
0
 def clear(self, timestamp=None):
     clearlist = []
     if timestamp:
         timediff = int(time.time()) - int(timestamp)
         for steamid in list(self.keyvalues['users'].keys()):
             if self.keyvalues['users'][steamid]['time'] < timediff:
                 clearlist.append(steamid)
         for steamid in clearlist:
             del self.keyvalues['users'][steamid]
     else:
         self.keyvalues['users'] = self.createKey('users')
     clearlist = []
     for steamid in list(self.keyvalues['variables'].keys()):
         for variable in list(self.keyvalues['variables'][steamid].keys()):
             clearlist.append((steamid, variable))
     for steamid, variable in clearlist:
         del self.keyvalues['variables'][steamid][variable]
     for option in list(self.keyvalues['options'].keys()):
         self.keyvalues['options'][option]['globstate'] = self.keyvalues['options'][option]['state']
Exemplo n.º 9
0
 def deloption(self, key):  #delete an option
     option = self.isValidOption(key, True)
     if option in self.keyvalues['options']:
         del self.keyvalues['options'][option]
         for steamid in list(self.keyvalues['users'].keys()):
             del self.keyvalues['users'][steamid]['data'][option]
         self.save()
     else:
         raise IndexError(
             f'Settinglib: Cannot delete option {key}, it does not exists')
Exemplo n.º 10
0
 def clear(self, timestamp=None):
     clearlist = []
     if timestamp:
         timediff = int(time.time()) - int(timestamp)
         for steamid in list(self.keyvalues['users'].keys()):
             if self.keyvalues['users'][steamid]['time'] < timediff:
                 clearlist.append(steamid)
         for steamid in clearlist:
             del self.keyvalues['users'][steamid]
     else:
         self.keyvalues['users'] = self.createKey('users')
     clearlist = []
     for steamid in list(self.keyvalues['variables'].keys()):
         for variable in list(self.keyvalues['variables'][steamid].keys()):
             clearlist.append((steamid, variable))
     for steamid, variable in clearlist:
         del self.keyvalues['variables'][steamid][variable]
     for option in list(self.keyvalues['options'].keys()):
         self.keyvalues['options'][option]['globstate'] = self.keyvalues[
             'options'][option]['state']
Exemplo n.º 11
0
 def initUser(self, userid):
     if es.exists('userid', userid):
         steamid = playerlib.uniqueid(userid, True)
         self.keyvalues['users'][steamid] = self.createKey(steamid)
         self.keyvalues['users'][steamid]['time'] = int(time.time())
         self.keyvalues['users'][steamid]['data'] = self.createKey('data')
         for option in list(self.keyvalues['options'].keys()):
             self.keyvalues['users'][steamid]['data'][
                 option] = self.createKey(option)
             self.keyvalues['users'][steamid]['data'][option][
                 'state'] = self.keyvalues['options'][option]['state']
Exemplo n.º 12
0
 def cleanTypes(self):
     resend = self.keyvalues['config']['resend']
     if isinstance(resend, str):
         try:
             self.keyvalues['config']['resend'] = int(resend)
         except:
             self.keyvalues['config']['resend'] = 1
     for option in list(self.keyvalues['options'].keys()):
         if 'state' in self.keyvalues['options'][option]:
             state = self.keyvalues['options'][option]['state']
             if isinstance(state, str):
                 try:
                     self.keyvalues['options'][option]['state'] = int(state)
                 except:
                     self.keyvalues['options'][option]['state'] = 0
         if 'globstate' in self.keyvalues['options'][option]:
             state = self.keyvalues['options'][option]['globstate']
             if isinstance(state, str):
                 try:
                     self.keyvalues['options'][option]['globstate'] = int(state)
                 except:
                     self.keyvalues['options'][option]['globstate'] = 0
     for steamid in list(self.keyvalues['users'].keys()):
         if 'time' in self.keyvalues['users'][steamid]:
             state = self.keyvalues['users'][steamid]['time']
             if isinstance(state, str):
                 try:
                     self.keyvalues['users'][steamid]['time'] = int(state)
                 except:
                     self.keyvalues['users'][steamid]['time'] = int(time.time())
         if 'data' in self.keyvalues['users'][steamid]:
             for option in list(self.keyvalues['users'][steamid]['data'].keys()):
                 if 'state' in self.keyvalues['users'][steamid]['data'][option]:
                     state = self.keyvalues['users'][steamid]['data'][option]['state']
                     if isinstance(state, str):
                         try:
                             self.keyvalues['users'][steamid]['data'][option]['state'] = int(state)
                         except:
                             self.keyvalues['users'][steamid]['data'][option]['state'] = 0
Exemplo n.º 13
0
def create(pSettingid,
           pDescription,
           pType='list',
           pFilename=None,
           pFiletype='dict'):
    #check for pickle problems
    if pFiletype == 'dict':
        try:
            pickle_data = list(map(str, list(range(1, 10))))
            pickle_file = open(selfdatatest, 'wb')
            pickle.dump(pickle_data, pickle_file)
            pickle_file.flush()
            pickle_file.close()
            pickle_file = open(selfdatatest, 'rb')
            pickle_file.seek(0)
            pickle_test = pickle.load(pickle_file)
            pickle_file.close()
            os.remove(selfdatatest)
            if pickle_test != pickle_data:
                pFiletype = 'keyvalues'
        except:
            pFiletype = 'keyvalues'
    else:
        pFiletype = 'keyvalues'
    if not pFilename:
        if pFiletype == 'keyvalues':
            pFilename = '%s/%s.txt' % (selfdatapath, pSettingid)
        elif pFiletype == 'dict':
            pFilename = '%s/%s.pkl' % (selfdatapath, pSettingid)
    #create new setting
    if pType == 'list':
        gSettings[pSettingid] = list.Setting_list(pSettingid, pDescription,
                                                  pFilename, pFiletype)
    elif pType == 'toggle':
        gSettings[pSettingid] = toggle.Setting_toggle(pSettingid, pDescription,
                                                      pFilename, pFiletype)
    else:
        return None
    return gSettings[pSettingid]
Exemplo n.º 14
0
 def information(self, listlevel):
     if listlevel >= 1:
         es.dbgmsg(0, ' ')
     es.dbgmsg(0, self.name)
     if listlevel >= 1:
         es.dbgmsg(
             0, '  Description:  ' + str(self.keyvalues['config']['descr']))
         es.dbgmsg(
             0,
             '  Re-Send:      ' + str(self.keyvalues['config']['resend']))
         es.dbgmsg(
             0, '  Soundfile:    ' + str(self.keyvalues['config']['sound']))
     if listlevel >= 2:
         es.dbgmsg(
             0, '  Players:      ' +
             str(len(list(self.keyvalues['users'].keys()))))
         es.dbgmsg(
             0, '  Options:      ' +
             str(len(list(self.keyvalues['options'].keys()))))
         for option in list(self.keyvalues['options'].keys()):
             es.dbgmsg(
                 0, '    [' +
                 str(self.keyvalues['options'][option]['keyname']) +
                 ']:  ' + self.keyvalues['options'][option]['display'])
Exemplo n.º 15
0
 def clearoption(self):
     optionlist = []
     for option in list(self.keyvalues['options'].keys()):
         optionlist.append(option)
     for option in optionlist:
         self.deloption(option)
Exemplo n.º 16
0
 def clearoption(self):
     optionlist = []
     for option in list(self.keyvalues['options'].keys()):
         optionlist.append(option)
     for option in optionlist:
         self.deloption(option)