示例#1
0
def COMRENAME(ClientInfo:ClientInformation, var1, var2):
    if not funs.CheckCommandDataBase(ClientInfo, 'RENAME'):
        return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied)
    if not funs.CheckCorrectNameVariable(var1) or not funs.CheckCorrectNameVariable(var2):
        return (Inf.Error, 'NAME', ClientInfo.language.NotCorrectNameOfVariable)
    DataBase = ClientInfo.DataBase
    if var1 in DataBase.data:
        DataBase.data[var2] = DataBase.data[var1]
        del DataBase.data[var1]
    else:
        return (Inf.Error, 'VARNOTFOUND', ClientInfo.language.VariableNotFound.format(var1))
    sendinfo.SendToListeners(ClientInfo.DataBase, 'ListenerRename', [var1, var2])
    return (Inf.OK, ClientInfo.language.NA, ClientInfo.language.OK)
示例#2
0
def COMAPPEND(ClientInfo:ClientInformation, variable, value, position=None):
    if not funs.CheckCommandDataBase(ClientInfo, 'APPEND'):
        return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied)
    if not funs.CheckCorrectNameVariable(variable):
        return (Inf.Error, 'NAME', ClientInfo.language.NotCorrectNameOfVariable)
    DataBase = ClientInfo.DataBase
    if variable in DataBase.data:
        if position == None:
            position = len(DataBase.data[variable])
        else:
            try:
                position = int(position)
            except:
                return (Inf.Error, 'NOTNUMPOS', ClientInfo.language.NotNumericWherePosition)
        if position < 0 or position > len(DataBase.data[variable]):
            return (Inf.Error, 'INDEXOUTOFRANGE', ClientInfo.language.IndexOutOfRange)
        DataBase.data[variable].insert(position, value)
    else:
        if position == None:
            position = 0
        else:
            try:
                position = int(position)
            except:
                return (Inf.Error, 'NOTNUMPOS', ClientInfo.language.NotNumericWherePosition)
        if position != 0:
            return (Inf.Error, 'INDEXOUTOFRANGE', ClientInfo.language.IndexOutOfRange)               
        DataBase.data[variable] = [value, ]

    sendinfo.SendToListeners(DataBase, 'ListenerAppend', [value, variable, position])

    Data = str(len(DataBase.data[variable]))
    return (Inf.Info, Data, '{}\r\n'.format(Data))
示例#3
0
def COMSET(ClientInfo:ClientInformation, variable, value, *args):
    if not funs.CheckCommandDataBase(ClientInfo, 'SET'):
        return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied)
    if not funs.CheckCorrectNameVariable(variable):
        return (Inf.Error, ClientInfo.language.NA, ClientInfo.language.NotCorrectNameOfVariable)
    data = [value,] + list(args)
    ClientInfo.DataBase.data[variable] = data
    sendinfo.SendToListeners(ClientInfo.DataBase, 'ListenerSet', [variable, ', '.join(data)])
    return (Inf.OK, ClientInfo.language.NA, ClientInfo.language.OK)
示例#4
0
def CreateUser(RegUser:classes.User):
    if not funs.CheckCorrectNameVariable(RegUser.login):
        return 'NotCorrectLoginUser'
    if RegUser.login.lower() in (u.lower() for u in USERS):
        return 'UserIsExists'
    if 'GLOBAL' not in RegUser.DataBases:
        RegUser.DataBases['GLOBAL'] = classes.AccessDataBase(True, False, True, False, False, True, False)
    USERS[RegUser.login] = RegUser
    SaveUsers()
    return 'RegistrationCompleted'
示例#5
0
def COMDBCLEAR(ClientInfo:ClientInformation, Database):
    Database = Database.upper()
    if not funs.CheckCorrectNameVariable(Database):
        return (Inf.Error, 'NAME', ClientInfo.language.NotCorrectNameOfDatabase)
    if Database not in database.DATABASES:
        return (Inf.Error, 'NOTEXISTS', ClientInfo.language.BDNotExists.format(Database))

    if not funs.CheckCommandDataBase(ClientInfo, 'DBCLEAR', Database):
        return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied)

    DataBase = database.DATABASES[Database]
    DataBase.data = dict()
    return (Inf.OK, ClientInfo.language.NA, ClientInfo.language.BDCleared.format(Database))
示例#6
0
def COMCREATE(ClientInfo:ClientInformation, Database):
    if len(ClientInfo.CurrentUser.OwnerDataBases) >= ClientInfo.CurrentUser.MaxCountCreateDataBases and ClientInfo.CurrentUser.MaxCountCreateDataBases != -1 and ClientInfo.CurrentUser.UserRole != variables.ADMINISTRATORROLE:
        return (Inf.Error, 'MAXDB', ClientInfo.language.MaximumOfDataBases.format(ClientInfo.CurrentUser.MaxCountCreateDataBases))
    Database = Database.upper()
    if not funs.CheckCorrectNameVariable(Database):
        return (Inf.Error, 'NAME', ClientInfo.language.NotCorrectNameOfDatabase)
    message = database.CreateDB(Database)
    if message == 'CreateBD':
        sendinfo.SendToAllListeners('ListenerAllCreate', [Database, ])
        ClientInfo.CurrentUser.DataBases[Database] = classes.AccessDataBase(True, True, True, True, True, True, True)
        ClientInfo.CurrentUser.OwnerDataBases.append(Database)
        return (Inf.OK, Database, ClientInfo.language[message].format(Database))
    elif message == 'BDExists':
        return (Inf.Error, 'EXISTS', ClientInfo.language[message].format(Database))
示例#7
0
def COMUSE(ClientInfo:ClientInformation, Database):
    Database = Database.upper()
    if ClientInfo.Listen:
        return (Inf.Error, 'CANTUSEWHENLISTENING', ClientInfo.language.CantUseWhenListening)
    if not funs.CheckCorrectNameVariable(Database):
        return (Inf.Error, 'NAME', ClientInfo.language.NotCorrectNameOfDatabase)
    if Database in database.DATABASES:

        if not funs.CheckCommandDataBase(ClientInfo, 'USE', Database):
            return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied)

        ClientInfo.DataBase = database.DATABASES[Database]

        return (Inf.OK, ClientInfo.language.NA, ClientInfo.language.OK)
    else:
        return (Inf.Error, 'NOTEXISTS', ClientInfo.language.BDNotExists.format(Database))
示例#8
0
def COMDBDEL(ClientInfo:ClientInformation, Database):
    Database = Database.upper()
    if Database == 'GLOBAL':
        return (Inf.Error, 'MAIN', ClientInfo.language.BDCantDeleteMainBase)
    if not funs.CheckCorrectNameVariable(Database):
        return (Inf.Error, 'NAME', ClientInfo.language.NotCorrectNameOfDatabase)
    if Database not in database.DATABASES:
        return (Inf.Error, 'NOTEXISTS', ClientInfo.language.BDNotExists.format(Database))

    if not funs.CheckCommandDataBase(ClientInfo, 'DBDEL', Database):
        return (Inf.PermissionDenied, ClientInfo.language.NA, ClientInfo.language.PermissionDenied)

    DataBase = database.DATABASES[Database]
    if ClientInfo.DataBase == DataBase:
        return (Inf.Error, 'CURRENT', ClientInfo.language.BDCantDeleteCurrent)
    if len(database.GetClientsInDB(DataBase)) > 0:
        return (Inf.Error, 'USERS', ClientInfo.language.BDCantDeleteWhereUsers)
    message = database.DeleteDB(Database)
    if message == 'BDDeleted':
        sendinfo.SendToAllListeners('ListenerAllDelete', [Database, ])
        return (Inf.OK, ClientInfo.language.NA, ClientInfo.language[message].format(Database))
    elif message == 'BDNotExists':
        return (Inf.Error, 'NOTEXISTS', ClientInfo.language[message].format(Database))