[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  # -*- coding: utf-8 -*-
   2  import sys, os, posix
   3  
   4  class se3Templates:
   5  
   6      def __init__ (self, path2Templates,path2BatFiles, user):
   7          """
   8              Initializations
   9          """
  10          self.__user = user
  11          self.__tplPath = path2Templates
  12  
  13  
  14      def getTemplates (self):
  15          """
  16              Get template dir list
  17          """
  18          try:
  19              dirList = []
  20              for dir in os.listdir (self.__tplPath):
  21                   if os.path.isdir (os.path.join(self.__tplPath, dir)):
  22                       dirList.append (dir.lower ())
  23              return dirList
  24          except OSError:
  25              print "Error getting template list"
  26  
  27      def createDesktop (self, templates):
  28          """
  29              Create destktop from templates
  30          """
  31          try:
  32              for template in templates:
  33                  list = self.__getDirListing ("%s/%s/Bureau" % \
  34                                               (self.__tplPath, template), False)
  35                  for item in list:
  36                      self.__createLinks (item, template)
  37          except OSError:
  38              print "Error while creating desktop"
  39  
  40  
  41      def cleanDesktop (self):
  42          """
  43              Remove all links on desktop
  44          """
  45          try:
  46              list = self.__getDirListing ("/home/%s/profil/Bureau" % \
  47                                           (self.__user), True)
  48              for item in list:
  49                  self.__removeLinks (item)
  50  
  51          except OSError:
  52              print "Error while cleaning desktop"
  53  
  54  
  55      def createStartMenu (self, templates):
  56          """
  57              Create start menu from templates
  58          """
  59          try:
  60              for template in templates:
  61                  list = self.__getDirListing ("%s/%s/Demarrer" % \
  62                                               (self.__tplPath, template), False)
  63                  for item in list:
  64                      self.__createLinks (item, template)
  65          except OSError:
  66              print "Error while creating start menu"
  67  
  68  
  69      def cleanStartMenu (self):   
  70            """   
  71                Remove all links in start menu   
  72            """   
  73            try:   
  74                list = self.__getDirListing ("/home/%s/profil/Demarrer" % \
  75                                             (self.__user), True)   
  76                for item in list:   
  77                    self.__removeLinks (item)   
  78        
  79            except OSError:   
  80                print "Error while cleaning desktop"
  81  
  82  
  83      def __createLinks (self, path, template):
  84          """
  85              Create file in user environnement from template
  86              path: absolute path to template file
  87          """
  88          item = path.replace ("/home/templates/%s/" % template, "")
  89          if os.path.isdir(path):
  90               if not os.access ("/home/%s/profil/%s" % (self.__user, item), os.F_OK):
  91                   os.mkdir ("/home/%s/profil/%s" % (self.__user, item))
  92          else:
  93              if not os.access ("/home/%s/profil/%s" % (self.__user, item), os.F_OK):
  94                  posix.symlink ("%s" % path, "/home/%s/profil/%s" \
  95                                      % (self.__user, item))
  96  
  97      def __removeLinks (self, path):
  98          """
  99              Remove all dst links
 100          """
 101          try:
 102              if os.path.islink (path):
 103                  os.unlink (path)
 104              else:
 105                  os.rmdir (path)
 106  
 107          except OSError:
 108              # path is a dir, path is not empty
 109              return
 110             
 111  
 112      def __getDirListing (self, dirPath, revert):
 113          """
 114              Return a list with dir content
 115              Dirs first, then files
 116              if revert == True, Files first, then dirs, then subdirs
 117              else, Dirs first, then subdirs, then files
 118          """
 119          dirList = []
 120          fileList = []
 121          for root, dirs, files in os.walk (dirPath, False):
 122              for name in files:
 123                  fileList.append (os.path.join (root, name))
 124              for name in dirs:
 125                  dirList.append (os.path.join (root, name))
 126          
 127          if revert == True:
 128              return fileList + dirList
 129          else:
 130              dirList.reverse ()
 131              return dirList + fileList


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