def cleanupShortcut(self, path): if self.mode != Session.MODE_DESKTOP: return shortcut_ext = ApplicationsDetection.shortcut_ext if not os.path.exists(path): return try: contents = os.listdir(path) except Exception: Logger.exception("Unable to list content of the directory %s" % path) return for content in contents: target = None l = os.path.join(path, content) if not os.path.isfile(l): continue if not os.path.splitext(l)[1] == shortcut_ext: continue try: target = ApplicationsDetection.getExec(l) except Exception: Logger.exception("Unable to get the desktop target of %s" % l) target = None if target is None: continue for app in self.Ulteo_apps: if app.lower() in target.lower(): Logger.debug("removing shortcut %s" % (target)) try: os.remove(l) except Exception: Logger.exception( "Unable to delete the desktop target %s" % l)
def cleanupShortcut(self, path): if self.mode != Session.MODE_DESKTOP: return shortcut_ext = ApplicationsDetection.shortcut_ext if not os.path.exists(path): return try: contents = os.listdir(path) except Exception: Logger.exception("Unable to list content of the directory %s"%path) return for content in contents: target = None l = os.path.join(path, content) if not os.path.isfile(l): continue if not os.path.splitext(l)[1] == shortcut_ext: continue try: target = ApplicationsDetection.getExec(l) except Exception: Logger.exception("Unable to get the desktop target of %s"%l) target = None if target is None: continue for app in self.Ulteo_apps: if app.lower() in target.lower(): Logger.debug("removing shortcut %s"%(target)) try: os.remove(l) except Exception: Logger.exception("Unable to delete the desktop target %s"%l)
class Session: Ulteo_apps = ["startovdapp", "UlteoOVDIntegratedLauncher"] SESSION_STATUS_UNKNOWN = "unknown" SESSION_STATUS_ERROR = "error" SESSION_STATUS_INIT = "init" SESSION_STATUS_INITED = "ready" SESSION_STATUS_ACTIVE = "logged" SESSION_STATUS_INACTIVE = "disconnected" SESSION_STATUS_WAIT_DESTROY = "wait_destroy" SESSION_STATUS_DESTROYED = "destroyed" SESSION_END_STATUS_NORMAL = "logout" SESSION_END_STATUS_SHUTDOWN = "shutdown" SESSION_END_STATUS_ERROR = "internal" MODE_DESKTOP = "desktop" MODE_APPLICATIONS = "applications" def __init__(self, id_, mode_, user_, parameters_, applications_): self.id = id_ self.user = user_ self.mode = mode_ self.parameters = parameters_ self.profile = None self.applications = applications_ self.instanceDirectory = None self.used_applications = {} self.shellNode = None self.end_status = None self.user_session_dir = None self.locked = False self.domain = None self.log = SessionLogger() self.switch_status(Session.SESSION_STATUS_INIT) def init(self): raise NotImplementedError() def init_user_session_dir(self, user_session_dir): self.user_session_dir = user_session_dir if os.path.isdir(self.user_session_dir): System.DeleteDirectory(self.user_session_dir) try: os.makedirs(self.user_session_dir) except WindowsError, e: if e[0] == 183: # The directory already exist Logger.debug("The directory %s already exist" % (self.user_session_dir)) self.instanceDirectory = os.path.join(self.user_session_dir, "instances") self.matchingDirectory = os.path.join(self.user_session_dir, "matching") self.shortcutDirectory = os.path.join(self.user_session_dir, "shortcuts") os.mkdir(self.instanceDirectory) os.mkdir(self.matchingDirectory) os.mkdir(self.shortcutDirectory) for application in self.applications: cmd = ApplicationsDetection.getExec(application["filename"]) if cmd is None: Logger.error( "Session::install_client unable to extract command from app_id %s (%s)" % (application["id"], application["filename"])) continue f = file(os.path.join(self.matchingDirectory, application["id"]), "w") f.write(cmd) f.close() if self.shellNode is not None: # Push the OvdShell configuration self.shellNode.setAttribute("sm", Config.session_manager) scriptsNodes = self.shellNode.getElementsByTagName("script") script2start_dir = os.path.join(self.user_session_dir, 'scripts') scripts_aps = os.path.join(Config.spool_dir, "scripts") os.mkdir(script2start_dir) for node in scriptsNodes: scriptID = node.getAttribute("id") scriptName = node.getAttribute("name") scriptType = node.getAttribute("type") scriptExt = Scripts.type2ext(scriptType) node.setAttribute("name", scriptName + "." + scriptExt) apsname = os.path.join(scripts_aps, scriptID + "." + scriptExt) sessionname = os.path.join(script2start_dir, scriptName + "." + scriptExt) if os.path.isfile(apsname): shutil.copy(apsname, sessionname) f = open(os.path.join(self.user_session_dir, "shell.conf"), "w") f.write(self.shellNode.toprettyxml()) f.close()