[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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


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