コード例 #1
0
ファイル: xUTILS_DB.py プロジェクト: BrunelJacques/NoeXpy
def GetOneConfig(self, nomConfig='lastConfig', mute=False):
    # appel d'une configuration nommée, retourne le dict des params
    cfg = xucfg.ParamFile()
    grpCONFIGS = cfg.GetDict(groupe='CONFIGS')
    cfg = xucfg.ParamUser()
    grpAPPLI = cfg.GetDict(groupe='APPLI')
    nomAppli = ''
    if 'NOM_APPLICATION' in grpAPPLI.keys():
        nomAppli = grpAPPLI['NOM_APPLICATION']

    if nomConfig == 'lastConfig':
        # recherche du nom de configuration par défaut, cad la dernière des choix
        if 'choixConfigs' in grpCONFIGS:
            if nomAppli in grpCONFIGS['choixConfigs'].keys():
                if 'lastConfig' in grpCONFIGS['choixConfigs'][nomAppli].keys():
                    nomConfig = grpCONFIGS['choixConfigs'][nomAppli][
                        'lastConfig']

    typeConfig = 'db_reseau'
    if 'TYPE_CONFIG' in grpAPPLI:
        typeConfig = grpAPPLI['TYPE_CONFIG']
    if 'lstConfigs' in grpCONFIGS:
        lstNomsConfigs = [
            x[typeConfig]['ID'] for x in grpCONFIGS['lstConfigs']
        ]
        if not (nomConfig in lstNomsConfigs):
            mess = "xDB: Le nom de config '%s' n'est pas dans la liste des accès base de donnée" % (
                nomConfig)
            self.erreur = mess
            if not mute:
                wx.MessageBox(mess)
            return mess
        ix = lstNomsConfigs.index(nomConfig)
        # on récupére les paramétres de la config par le pointeur ix dans les clés
        return grpCONFIGS['lstConfigs'][ix][typeConfig]
コード例 #2
0
def GetDictUtilisateur(afficheMessage=True):
    try:
        topWindow = wx.GetApp().GetTopWindow()
        dictUtilisateur = topWindow.dictUser
    except:
        dictUtilisateur = None
    if not dictUtilisateur:
        #try :
        import xpy.outils.xshelve as xucfg
        cfg = xucfg.ParamUser()
        #userdomain, username ,config, mpUserDB, seudo, utilisateur, nom,prenom, IDutilisateur, droits,profil
        dictUtilisateur = cfg.GetDict(groupe='IDENT', close=False)
        user = cfg.GetDict(groupe='USER')
        dictUtilisateur.update(user)
        #except:
        pass
    if dictUtilisateur:
        # Si la frame 'General' est chargée, on y récupère le dict de config
        return dictUtilisateur
    else:
        if afficheMessage == True:
            wx.MessageBox(
                "Vous n'êtes pas identifiés\n\nrepassez par l'entrée",
                style=wx.ICON_AUTH_NEEDED)
    return None
コード例 #3
0
def VerificationDroitsUtilisateurActuel(categorie="",
                                        action="",
                                        IDactivite="",
                                        afficheMessage=True):
    try:
        topWindow = wx.GetApp().GetTopWindow()
        nomWindow = topWindow.GetName()
        dictUtilisateur = topWindow.dictUser
    except:
        dictUtilisateur = None
    if not dictUtilisateur:
        try:
            import xpy.outils.xshelve as xucfg
            cfg = xucfg.ParamUser()
            dictUtilisateur = cfg.GetDict(groupe='USER')
        except:
            pass
    if dictUtilisateur:
        # Si la frame 'General' est chargée, on y récupère le dict de config
        resultat = VerificationDroits(dictUtilisateur, categorie, action,
                                      IDactivite)
        if resultat == False and afficheMessage == True:
            wx.MessageBox(
                "'%s'\n\nVotre profil utilisateur  ne permet pas d'accéder à la fonctionnalité demandée!\n'%s' - '%s'"
                % (dictUtilisateur['nom'], categorie, action),
                style=wx.ICON_AUTH_NEEDED)
        return resultat
    return True
コード例 #4
0
ファイル: xAppli.py プロジェクト: BrunelJacques/NoeXpy
    def MakeStatusText(self):
        cfgU = xucfg.ParamUser()
        self.config = cfgU.SetDict(self.dictAppli, groupe='APPLI')

        # appel de la configuration base de données dans paramFile
        cfgF = xucfg.ParamFile()
        grpCONFIGS = cfgF.GetDict(dictDemande=None, groupe='CONFIGS')
        nomAppli = self.dictAppli['NOM_APPLICATION']
        nomConfig = ''
        if 'choixConfigs' in grpCONFIGS:
            if nomAppli and nomAppli in grpCONFIGS['choixConfigs'].keys():
                if 'lastConfig' in grpCONFIGS['choixConfigs'][nomAppli].keys():
                    nomConfig = grpCONFIGS['choixConfigs'][nomAppli][
                        'lastConfig']
        messBD = "données: '%s'" % (nomConfig)
        self.nomVersion = "%s %s" % (self.dictAppli['NOM_APPLICATION'],
                                     xaccueil.GetVersion(self))
        self.messageStatus = "%s |  %s" % (self.nomVersion, messBD)

        if hasattr(self, 'dictUser') and self.dictUser:
            self.messageStatus += ",  Utilisateur: %s" % (
                self.dictUser['utilisateur'])
        else:
            self.messageStatus += ",  Utilisateur non identifié"
        if hasattr(self, 'infoStatus'):
            self.messageStatus += " | %s" % (self.infoStatus)

        self.SetStatusText(self.messageStatus)
コード例 #5
0
    def Recherche(self):
        txtSearch = self.GetValue()
        # Recherche de l'utilisateur et envoi dans ParamUser de shelve
        for dictUtilisateur in self.listeUtilisateurs:
            if txtSearch == dictUtilisateur["mdp"]:
                # Enregistrement de l'utilisateur et de ses propriétés
                cfg = xu_shelve.ParamUser()
                self.choix = cfg.GetDict(groupe='USER', close=False)
                dictUtilisateur['utilisateur'] = dictUtilisateur[
                    'prenom'] + " " + dictUtilisateur['nom']
                self.choix['utilisateur'] = dictUtilisateur['utilisateur']
                self.choix['nom'] = dictUtilisateur['nom']
                self.choix['prenom'] = dictUtilisateur['prenom']
                self.choix['IDutilisateur'] = dictUtilisateur['IDutilisateur']
                self.choix['droits'] = dictUtilisateur['droits']
                self.choix['profil'] = dictUtilisateur['profil']
                self.choix['username'] = os.environ['USERNAME']
                self.choix['userdomain'] = os.environ['USERDOMAIN']
                cfg.SetDict(self.choix, groupe='USER')

                if hasattr(self.parent, 'On_trouve'):
                    self.parent.On_trouve(dictUtilisateur)
                    self.SetValue("")
                    break
        self.Refresh()
コード例 #6
0
ファイル: xUTILS_DB.py プロジェクト: BrunelJacques/NoeXpy
def GetConfigs():
    # appel des params de connexion stockés dans UserProfile et data
    cfg = xucfg.ParamUser()
    grpUSER = cfg.GetDict(groupe='USER', close=False)
    grpAPPLI = cfg.GetDict(groupe='APPLI')
    # appel des params de connexion stockés dans Data
    cfg = xucfg.ParamFile()
    grpCONFIGS = cfg.GetDict(groupe='CONFIGS')
    return grpAPPLI, grpUSER, grpCONFIGS
コード例 #7
0
 def SauveParamUser(self):
     # sauve ID dans le registre de la session
     cfg = xshelve.ParamUser()
     dic = {}
     for ctrlConfig in self.lstChoixConfigs:
         dic.update(ctrlConfig.GetValues())
     #dic.update(self.ctrlConnect.GetValues())
     cfg.SetDict(dic, groupe='USER', close=False)
     dic = self.ctrlID.GetValues()
     cfg.SetDict(dic['ident'], groupe='IDENT')
コード例 #8
0
 def EstAdmin(self):
     dicUser = {'utilisateur':'User inconnu!','profil':'inconnu'}
     if self.estAdmin == None:
         # récup info de l'utilisateur de la session
         cfg = xshelve.ParamUser()
         dicUser = cfg.GetDict(dictDemande=None, groupe='USER')
         self.estAdmin =  dicUser['profil'] == 'administrateur'
     if not self.estAdmin:
         mess = "Echec de la vérification des droits administateur"
         mess += "\n\n%s de profil %s n'est pas administrateur!"%(dicUser['utilisateur'],dicUser['profil'])
         wx.MessageBox(mess,"Verif droits d'accès")
     return self.estAdmin
コード例 #9
0
def GetIDutilisateur(afficheMessage=True):
    try:
        topWindow = wx.GetApp().GetTopWindow()
        dictUtilisateur = topWindow.dictUser
    except:
        dictUtilisateur = None
    if not dictUtilisateur:
        try:
            import xpy.outils.xshelve as xucfg
            cfg = xucfg.ParamUser()
            dictUtilisateur = cfg.GetDict(groupe='USER')
        except:
            pass
    if 'IDutilisateur' in dictUtilisateur.keys():
        # Si la frame 'General' est chargée, on y récupère le dict de config
        return dictUtilisateur['IDutilisateur']
    else:
        if afficheMessage == True:
            wx.MessageBox(
                "Vous n'êtes pas identifiés\n\nrepassez par l'entrée",
                style=wx.ICON_AUTH_NEEDED)
    return None
コード例 #10
0
    def __init__(self, parent, **kwds):
        typeConfig = kwds.pop('typeConfig', None)
        nomConfig = kwds.pop('nomConfig', None)
        lblBox = kwds.pop('lblBox', "Paramètres de la base de donnée")
        modeBase = kwds.pop('modeBase', 'pointeur')
        kwds['size'] = (350, 430)
        super().__init__(parent, **kwds)
        self.modeBase = modeBase
        self.DB = None

        # récup info de l'utilisateur de la session
        cfg = xshelve.ParamUser()
        dicUser = cfg.GetDict(dictDemande=None, groupe='USER')
        mess = "Accès aux ParamUser"
        try:
            # vérif des droits
            if modeBase == 'creation':
                mess = "Echec de la vérification des droits de création"
                if dicUser['profil'] != 'administrateur':
                    mess += "\n\n%s de profil %s n'est pas administrateur!" % (
                        dicUser['utilisateur'], dicUser['profil'])
                    raise (mess)
            mess = None
        except:
            wx.MessageBox(mess, "xGestionConfig.DLG_saisieUneConfig")
        if mess:
            self.Destroy()

        # choix de la configuration prise dans paramFile
        cfgF = xshelve.ParamFile()
        grpConfigs = cfgF.GetDict(dictDemande=None, groupe='CONFIGS')

        # les choix de config sont stockés par application car Data peut être commun à plusieurs
        if parent and hasattr(parent, 'dictAppli'):
            dictAppli = self.parent.dictAppli
        else:
            cfg = xshelve.ParamUser()
            dictAppli = cfg.GetDict(dictDemande=None, groupe='APPLI')
        nomAppli = dictAppli['NOM_APPLICATION']

        # récup des données à afficher après construction

        choixConfigs = grpConfigs['choixConfigs'][nomAppli]
        if 'lastConfig' in choixConfigs:
            lastConfig = choixConfigs['lastConfig']
        else:
            lastConfig = None
        ddConfig = GetDdConfig(grpConfigs, lastConfig)

        # récup de la matrice ayant servi à la gestion des données
        if not typeConfig:
            lstcode = GetLstCodesMatrice(MATRICE_CONFIGS)
            typeConfig = lstcode[0]
        key = (typeConfig, lblBox)
        matrice = {
            key: MATRICE_CONFIGS[GetCleMatrice(typeConfig, MATRICE_CONFIGS)]
        }
        self.typeConfig = typeConfig

        # ajustement de la matrice selon les modeBase
        ixID = GetIxLigneMatrice('nameDB', matrice[key])
        if self.modeBase == 'pointeur':
            matrice[key][ixID] = {
                'name': 'nameDB',
                'genre': 'combo',
                'label': 'Nom de la Base',
                'help':
                "Le nom de la base est le fichier en local, ou son nom sur le serveur",
                'ctrlAction': 'OnNameDB',
            }

        elif self.modeBase == 'creation':
            matrice[key][ixID] = {
                'name': 'nameDB',
                'genre': 'texte',
                'label': 'Nom de la Base',
                'help':
                "Choisir un base de donnée non présente sur le serveur ou fichier non existant",
                'ctrlAction': 'OnNameDB',
            }

        # place la valeur du champ ID
        exist = False
        if nomConfig:
            ixID = GetIxLigneMatrice('ID', matrice[key])
            matrice[key][ixID]['value'] = nomConfig

        # construction de l'écran de saisie
        self.pnl = xusp.TopBoxPanel(self, matrice=matrice, lblTopBox=None)

        if self.typeConfig in ddConfig.keys() and nomConfig == ddConfig[
                self.typeConfig]['ID']:
            self.pnl.SetValues(ddConfig)

        # grise le champ ID
        ctrlID = self.pnl.GetPnlCtrl('ID')
        ctrlID.Enable(False)
        if self.modeBase in ('creation', 'pointeur'):
            titre = "Création d'une nouvelle base de données"
            texte = "Définissez les pointeurs d'accès et le nom de la base à y créer\n"
            texte += "le mot de passe présenté sera celui  des 'Accès aux bases de données'"
        else:
            titre = "Définition de la base de données"
            texte = "Définissez les pointeurs d'accès et le nom de la base souhaitée\n"
            texte += "l'éventuel mot de passe présenté sera celui des 'Accès aux bases de données'"

        # personnalisation des éléments de l'écran
        self.bandeau = xbandeau.Bandeau(
            self,
            titre=titre,
            texte=texte,
            nomImage='xpy/images/32x32/Configuration.png')
        self.btn = self.Boutons(self)

        # layout
        self.Sizer(self.pnl)
コード例 #11
0
    def __init__(self, parent, **kwds):
        style = kwds.pop('style', wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
        size = kwds.pop('size', (400, 430))
        self.typeConfig = kwds.pop('typeConfig', None)
        listArbo = os.path.abspath(__file__).split("\\")
        titre = listArbo[-1:][0] + "/" + self.__class__.__name__
        wx.Dialog.__init__(self,
                           parent,
                           -1,
                           title=titre,
                           style=style,
                           size=size)
        self.parent = parent

        # Récup du code de la description des champs pour une configuration
        lstcode = GetLstCodesMatrice(MATRICE_CONFIGS)
        if not self.typeConfig:
            self.typeConfig = lstcode[0]
        if self.parent and 'TYPE_CONFIG' in self.parent.dictAppli:
            self.typeConfig = self.parent.dictAppli['TYPE_CONFIG']
            if not (self.typeConfig in lstcode):
                wx.MessageBox("L'option '%s' n'est pas dans MATRICECONFIGS " %
                              (self.typeConfig))

        ddDonnees = {}
        valeurs = {}
        ident = None
        # Bouton sortie de pied d'écran
        self.btnTest = xboutons.BTN_tester(self)
        self.btn = xboutons.BTN_fermer(self)

        #  IDENT :  appel de l'identification IDENT partie grisée -----------------------------------------------------
        try:
            utilisateur = self.parent.dictUser['utilisateur']
        except:
            utilisateur = None

        for (code, label), lignes in MATRICE_IDENT.items():
            for ligne in lignes:
                if ligne['name'].lower() in ('username', 'user'):
                    valeurs[ligne['name']] = os.environ['USERNAME']
                    ident = code
                if ligne['name'].lower() in ('userdomain', 'domaine',
                                             'workgroup'):
                    try:
                        valeurs[ligne['name']] = os.environ['USERDOMAIN']
                    except:
                        import platform
                        valeurs[ligne['name']] = platform.node()
                if ligne['name'].lower() in ('utilisateur', ):
                    valeurs[ligne['name']] = utilisateur
                    ident = code

        self.ctrlID = xusp.CTRL_property(self,
                                         matrice=MATRICE_IDENT,
                                         enable=False)
        if ident:
            ddDonnees[ident] = valeurs
            self.ctrlID.SetValues(ddDonnees=ddDonnees)

        # recherche dans profilUser ----------------------------------------------------------------------------------
        cfg = xshelve.ParamUser()
        # lecture des valeurs préalablement utilisées
        choixUser = cfg.GetDict(dictDemande=None, groupe='USER', close=True)
        dictAppli = cfg.GetDict(dictDemande=None, groupe='APPLI')
        if dictAppli == {}:
            dictAppli = self.parent.dictAppli
        self.nomAppli = dictAppli['NOM_APPLICATION']

        # CONFIGS : appel du modèle des configurations ----------------------------------------------------------------
        codeBox, labelBox, lignes = xformat.AppelLignesMatrice(
            None, MATRICE_CHOIX_CONFIG)
        # Composition des choix de configurations selon l'implantation
        self.lstChoixConfigs = []
        if self.parent and 'CHOIX_CONFIGS' in self.parent.dictAppli:
            lstchoix = self.parent.dictAppli['CHOIX_CONFIGS']
            for codeBox, labelBox in lstchoix:
                self.lstChoixConfigs.append(
                    ChoixConfig(self, labelBox, codeBox, lignes, {}))
        else:
            # le nom de la configuration c'est le premier champ décrit dans la matrice
            self.lstChoixConfigs.append(
                ChoixConfig(self, labelBox, codeBox, lignes, {}))

        # choix de la configuration prise dans paramFile
        cfgF = xshelve.ParamFile()
        grpConfigs = cfgF.GetDict(dictDemande=None, groupe='CONFIGS')
        # filtrage des des configs selon type retenu
        self.lstIDconfigsOK, self.lstConfigsOK, self.lstConfigsKO = GetLstConfigs(
            grpConfigs, self.typeConfig)
        ddchoixConfigs = grpConfigs.pop('choixConfigs', {})
        # les choix de config sont stockés par application car Data peut être commun à plusieurs
        if not (self.nomAppli in ddchoixConfigs):
            ddchoixConfigs[self.nomAppli] = {}
        choixConfigs = ddchoixConfigs[self.nomAppli]
        # alimente la liste des choix possibles
        for ctrlConfig in self.lstChoixConfigs:
            ctrlConfig.SetOneSet(ctrlConfig.Name, self.lstIDconfigsOK)
            if ctrlConfig.Name in choixConfigs:
                ctrlConfig.SetOneValue(ctrlConfig.Name,
                                       choixConfigs[ctrlConfig.Name])
        # last config sera affichée en 'Fermer' si pas modifiée
        if 'lastConfig' in choixConfigs:
            self.lastConfig = choixConfigs['lastConfig']
        else:
            self.lastConfig = ''

        # SEPARATEUR : simple texte
        self.titre = wx.StaticText(self, -1, "Eléments de connexion")

        self.Sizer()