[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-logonpy/usr/share/se3/logonpy_Win9x/ -> se3DB.py (source)

   1  # -*- coding: utf-8 -*-
   2  import sys, MySQLdb, os
   3  sys.path.append('/etc/se3/python/')
   4  from  mysqlinfo import *
   5  
   6  class se3DB:
   7  
   8      def __init__ (self,user, arch):
   9          """
  10              Connect to se3db base 
  11          """
  12          try:
  13              self.__db = MySQLdb.connect(dbhost, dbuser, dbpass, dbname)
  14              self.__user = user
  15              self.__arch = arch
  16          except MySQLdb.Error, e:
  17              print "Error %d: %s" % (e.args[0], e.args[1])
  18              sys.exit (1)
  19  
  20      def __del__ (self):
  21          """
  22              Close connexion
  23          """
  24          self.__db.close ()
  25  
  26      def getValue (self, name):
  27          """
  28              Get a value from params table
  29          """
  30          try:
  31              cursor = self.__db.cursor ()
  32              cursor.execute ("SELECT value FROM params where name = %s" , name)
  33              row = cursor.fetchone ()
  34              cursor.close ()
  35              return row[0]
  36  
  37          except TypeError:
  38              return 0
  39  
  40  
  41      def setValue (self, name, value):
  42          """
  43              Set a value in params table
  44          """
  45          query = "UPDATE params SET  value = '" + value + \
  46                  "' where name = '" + name + "'"
  47          cursor = self.__db.cursor ()
  48          cursor.execute ("UPDATE params SET value = %s WHERE name = %s" ,\
  49                          (value, name))
  50          cursor.close ()
  51  
  52      def getRestrictions(self, templates):
  53          """
  54              Return restriction list for a template
  55          """
  56          results = {}
  57          rest = []
  58          wallModule = False
  59          tileWallSet = False
  60  
  61          if os.access ("/var/se3/Docs/media/fonds_ecran/%s.jpg" % self.__user, os.F_OK) \
  62              and self.__arch != "Win95":
  63              wallModule = True
  64  
  65          cursor = self.__db.cursor()
  66          for template in templates:
  67              cursor.execute ("SELECT CleID, valeur from restrictions where groupe=%s", template)
  68              for result in cursor.fetchall ():
  69                  results[result[0]] = result[1]
  70  
  71          for key in results.keys():
  72              cursor.execute ("SELECT Chemin, Genre, OS FROM corresp where CleID='%s'\
  73                                      and (OS like \"*Win9x*\" or OS=\"TOUS\")", key)
  74              row2 = cursor.fetchone ()
  75  
  76              if row2 != None:
  77                  rest.append ((row2[0], row2[1], row2[2], results[key]))
  78  
  79          cursor.close ()
  80  
  81          return rest


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1