当前位置: 首页>>代码示例>>Python>>正文


Python System.local_encode方法代码示例

本文整理汇总了Python中ovd.Platform.System.System.local_encode方法的典型用法代码示例。如果您正苦于以下问题:Python System.local_encode方法的具体用法?Python System.local_encode怎么用?Python System.local_encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ovd.Platform.System.System的用法示例。


在下文中一共展示了System.local_encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: copyDirOverride

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
def copyDirOverride(src, dst, exception=None):
	src = System.local_encode(src)
	dst = System.local_encode(dst)
	if not os.path.isdir(src):
		return
	
	if exception is None:
		exception = []
	
	try:
		attr = win32file.GetFileAttributes(src)
		if attr & FILE_ATTRIBUTE_SYSTEM and attr & FILE_ATTRIBUTE_REPARSE_POINT:
			return 
		win32file.SetFileAttributes(dst, attr)
	except:
		#print "Unable to setAttribute of",dst
		pass
	
	if not os.path.isdir(dst):
		os.makedirs(dst)

	dirs = None
	try:
		dirs = os.listdir(src)
	except Exception, err:
		return
开发者ID:Oyatsumi,项目名称:ulteo4Kode4kids,代码行数:28,代码来源:Util.py

示例2: check_remaining_mount_points

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def check_remaining_mount_points(self):
		try:
			user = pwd.getpwnam(System.local_encode(self.name))
		except KeyError:
			return False
		
		mount_points = MountPoint.get_list(user.pw_dir)
		if mount_points is None:
			return False
		
		success = True
		for d in mount_points:
			path = System.local_encode(d)
			Logger.warn("Remaining mount point '%s'"%(path))
			cmd = 'umount "%s"'%(path)
			
			p = System.execute(cmd)
			if p.returncode == 0:
				continue
			
			Logger.warn("Unable to unmount remaining mount point %s: force the unmount"%(path))
			Logger.debug('umount command "%s" return: %s'%(cmd,  p.stdout.read()))
			cmd = 'umount -l "%s"'%(path)
			p = System.execute(cmd)
			if p.returncode != 0:
				Logger.error("Unable to force the unmount remaining mount point %s"%(path))
				Logger.debug('umount command "%s" return: %s'%(cmd,  p.stdout.read()))
			
			success = False
		
		if success == False:
			Logger.error("Unable to unmount remaining mount point, home dir %s won't be purged"%(user.pw_dir))
		
		return success
开发者ID:bloveing,项目名称:openulteo,代码行数:36,代码来源:User.py

示例3: install_client

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def install_client(self):
		name = System.local_encode(self.user.name)
		
		d = os.path.join(self.SPOOL_USER, self.user.name)
		self.init_user_session_dir(d)
		self.install_desktop_shortcuts()
		
		os.chown(self.instanceDirectory, pwd.getpwnam(name)[2], -1)
		os.chown(self.user_session_dir, pwd.getpwnam(name)[2], -1)
		
		xdg_dir = os.path.join(d, "xdg")
		xdg_app_d = os.path.join(xdg_dir, "applications")
		if not os.path.isdir(xdg_app_d):
			os.makedirs(xdg_app_d)
		
		for p in ["icons", "pixmaps", "mime", "themes"]:
			src_dir = os.path.join("/usr/share/", p)
			dst_dir =  os.path.join(xdg_dir, p)
			
			os.symlink(src_dir, dst_dir)
		
		
		os.system('update-desktop-database "%s"'%(System.local_encode(xdg_app_d)))
	
		if self.parameters.has_key("desktop_icons") and self.parameters["desktop_icons"] == "1":
			path = os.path.join(xdg_app_d, ".show_on_desktop")
			f = file(path, "w")
			f.close()
		
		
		env_file_lines = []
		# Set the language
		if self.parameters.has_key("locale"):
			env_file_lines.append("LANG=%s.UTF-8\n"%(self.parameters["locale"]))
			env_file_lines.append("LC_ALL=%s.UTF-8\n"%(self.parameters["locale"]))
			env_file_lines.append("LANGUAGE=%s.UTF-8\n"%(self.parameters["locale"]))
		
		if self.parameters.has_key("timezone"):
			tz_file = "/usr/share/zoneinfo/" + self.parameters["timezone"]
			if not os.path.exists(tz_file):
				Logger.warn("Unsupported timezone '%s'"%(self.parameters["timezone"]))
				Logger.debug("Unsupported timezone '%s'. File '%s' does not exists"%(self.parameters["timezone"], tz_file))
			else:
				env_file_lines.append("TZ=%s\n"%(tz_file))
		
		f = file(os.path.join(d, "env"), "w")
		f.writelines(env_file_lines)
		f.close()
		
		if self.profile is not None:
			self.profile.mount()
			
			shares_dir = os.path.join(d, "shares")
			if not os.path.isdir(shares_dir):
				os.makedirs(shares_dir)
			
			self.profile.register_shares(shares_dir)
		
		return True
开发者ID:Oyatsumi,项目名称:ulteo4Kode4kids,代码行数:61,代码来源:Session.py

示例4: copySessionStop

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def copySessionStop(self):
		# etre sur que le type est logoff !
		
		
		d = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0)
		profile_tmp_dir = os.path.join(d, "ulteo", "profile", self.session.user.name)
		profile_tmp_dir = System.local_encode(profile_tmp_dir)
		profile_filter = System.local_encode(Config.profile_filters_filename)

		d = os.path.join(self.mountPoint, "conf.Windows.%s"%System.getWindowsVersionName())
		trial = 5
		while not os.path.exists(d):
			try:
				os.makedirs(d)
			except OSError:
				trial -= 1
				if trial == 0:
					Logger.exception("Failed to create directory %s"%d)
					return False
				
				time.sleep(random.randint(1,10)/100.0)	
				Logger.debug2("conf.Windows mkdir failed (concurrent access because of more than one ApS)")
				continue
		
		# Copy user registry
		src = os.path.join(self.session.windowsProfileDir, "NTUSER.DAT")
		dst = os.path.join(d, "NTUSER.DAT")
		
		if os.path.exists(src):
			try:
				win32file.CopyFile(src, dst, False)
			except:
				Logger.error("Unable to copy registry to profile")
		else:
			Logger.warn("Weird: no NTUSER.DAT in user home dir ...")
		
		
		# Copy configuration File
		if self.profile['profile_mode'] == 'standard':
			cmd = self.getRsyncMethod(Profile.toCygPath(profile_tmp_dir), Profile.toCygPath(d), Profile.toCygPath(profile_filter))
			Logger.debug("rsync cmd '%s'"%(cmd))
		
			p = System.execute(cmd)
			if p.returncode is not 0:
				Logger.error("Unable to copy conf to profile")
				Logger.debug("Unable to copy conf to profile, cmd '%s' return %d: %s"%(cmd, p.returncode, p.stdout.read()))
		
		if os.path.exists(profile_tmp_dir):
			System.DeleteDirectory(profile_tmp_dir)
开发者ID:bloveing,项目名称:openulteo,代码行数:51,代码来源:Profile.py

示例5: destroy

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def destroy(self):
		lock = FileLock("/tmp/user.lock")
		
		arg_remove = ""
		if self.check_remaining_mount_points():
			arg_remove = "--remove"
		
		cmd = "userdel --force %s %s"%(arg_remove, System.local_encode(self.name))
		
		retry = 5
		while retry !=0:
			lock.acquire()
			p = System.execute(cmd)
			lock.release()
			if p.returncode == 0:
				return True
			if p.returncode == 12:
				Logger.debug("mail dir error: '%s' return %d => %s"%(str(cmd), p.returncode, p.stdout.read()))
				return True
			
			Logger.debug("User delete of %s: retry %i"%(self.name, 6-retry))
			if p.returncode == 1 or p.returncode == 10: # an other process is creating a user
				Logger.debug("An other process is creating a user")
				retry -=1
				time.sleep(0.2)
				continue
			if p.returncode != 0:
				Logger.error("userdel return %d (%s)"%(p.returncode, p.stdout.read()))
				return False
		
		return True
开发者ID:bloveing,项目名称:openulteo,代码行数:33,代码来源:User.py

示例6: exists

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def exists(self):
		try:
			pwd.getpwnam(System.local_encode(self.name))
		except KeyError:
			return False
		
		return True
开发者ID:bloveing,项目名称:openulteo,代码行数:9,代码来源:User.py

示例7: destroy

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def destroy(self):
                lock = FileLock("/tmp/user.lock")

		arg_remove = ""
		if self.check_remaining_mount_points():
			arg_remove = "--remove"
		
		cmd = "userdel --force %s %s"%(arg_remove, System.local_encode(self.name))
		
		retry = 5
		while retry !=0:
			lock.acquire()
			s,o = commands.getstatusoutput(cmd)
			lock.release()
		        if s == 0:
		                return True
                        if s == 3072:
                                Logger.debug("mail dir error: '%s' return %d => %s"%(str(cmd), s, o))
                                return True

		        Logger.debug("User delete of %s: retry %i"%(self.name, 6-retry))
		        if s == 256 or s == 2560: # an other process is creating a user
		                Logger.debug("An other process is creating a user")
		                retry -=1
		                time.sleep(0.2)
		                continue
		        if s != 0:
		                Logger.error("userdel return %d (%s)"%(s, o))
		                return False

		return True
开发者ID:Oyatsumi,项目名称:ulteo4Kode4kids,代码行数:33,代码来源:User.py

示例8: create

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def create(self):
		lock = FileLock("/tmp/user.lock")
		
		# TODO get the default home in /etc/default/useradd
		default_home_dir = os.path.join(u"/home", self.name)
		home_dir = default_home_dir
		i = 0
		while os.path.exists(home_dir) and i < 100:
			home_dir = default_home_dir+"_%d"%(i)
			i+= 1

		if i > 0:
			Logger.warn("Unable to create home directory %s, the home is now %s"%(default_home_dir, home_dir))

		if os.path.exists(home_dir):
			Logger.error("Unable to find a valid home directory")
			return False
		
		cmd = u"useradd -m -d '%s' -k '%s'"%(home_dir, Config.linux_skel_directory)
		if self.infos.has_key("displayName"):
			cmd+= u""" --comment "%s,,," """%(self.infos["displayName"].replace('"', ""))
		
		groups = ["video", "audio", "pulse", "pulse-access", Config.linux_fuse_group]
		if self.infos.has_key("groups"):
			groups+= self.infos["groups"]
		cmd+= u" --groups %s"%(",".join(groups))
		
		cmd+= u" "+self.name
		
		retry = 5
		while retry !=0:
			if retry < 0:
				  Logger.error("ERROR: unable to add a new user")
			lock.acquire()
			p = System.execute(System.local_encode(cmd))
			lock.release()
			if p.returncode == 0:
				break
			
			Logger.debug("Add user :retry %i"%(6-retry))
			if p.returncode == 9: # user already exist
				Logger.error("User %s already exist"%(self.name))
				break;
			if p.returncode == 1: # an other process is creating a user
				Logger.error("An other process is creating a user")
				retry -=1
				time.sleep(0.2)
				continue
			if p.returncode != 0:
				Logger.error("UserAdd return %d (%s)"%(p.returncode, p.stdout.read()))
				return False
		
		
		if self.infos.has_key("password"):
			if not self.set_password():
				return False
		
		return self.post_create()
开发者ID:bloveing,项目名称:openulteo,代码行数:60,代码来源:User.py

示例9: tuneGroups

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def tuneGroups(self, username, groups):
		if groups is None or len(groups) == 0:
			return False
		
		groupString = ','.join(groups)
		cmd = u"usermod -G %s %s"%(groupString, username)
		p = System.execute(System.local_encode(cmd))
		if p.returncode != 0:
			Logger.error("UserAdd return %d (%s)"%(p.returncode, p.stdout.read()))
			return False
		
		return True
开发者ID:bloveing,项目名称:openulteo,代码行数:14,代码来源:DomainMicrosoft.py

示例10: post_create

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def post_create(self):
		name = System.local_encode(self.name)
		
		if self.infos.has_key("shell"):
			xrdp.UserSetShell(name, self.infos["shell"])
			xrdp.UserAllowUserShellOverride(name, True)
		
		
		try:		
			self.home = pwd.getpwnam(name)[5]
		except KeyError:
			return False
		return True
开发者ID:bloveing,项目名称:openulteo,代码行数:15,代码来源:User.py

示例11: exec_command

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def exec_command(cls, cmd, wait=True):
			subprocess_args = {}
			subprocess_args["stdin"] = subprocess.PIPE
			subprocess_args["stdout"] = subprocess.PIPE
			subprocess_args["stderr"] = subprocess.STDOUT
			subprocess_args["shell"] = True
			subprocess_args["preexec_fn"] = os.setpgrp
			
			p = subprocess.Popen(System.local_encode(cmd), **subprocess_args)
			if wait:
					p.wait()
			
			return p
开发者ID:bloveing,项目名称:openulteo,代码行数:15,代码来源:User.py

示例12: clean_tmp_dir

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
    def clean_tmp_dir(self):
        # Purge TMP directory
        uid = pwd.getpwnam(System.local_encode(self.user.name))[2]
        for f in os.listdir("/tmp"):
            filename = os.path.join("/tmp", f)
            s = os.lstat(filename)
            if s.st_uid != uid:
                continue

            try:
                if os.path.isdir(filename):
                    shutil.rmtree(filename)
                else:
                    os.remove(filename)
            except:
                Logger.exception("Unable to remove %s" % (filename))
开发者ID:bloveing,项目名称:openulteo,代码行数:18,代码来源:Session.py

示例13: check_remaining_mount_points

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def check_remaining_mount_points(self):
		try:
			user = pwd.getpwnam(self.name)
		except KeyError:
			return False
		
		mount_points = MountPoint.get_list(user.pw_dir)
		if mount_points is None:
			return False
		
		success = True
		for d in mount_points:
			Logger.warn("Remaining mount point '%s'"%(d))
			cmd = 'umount "%s"'%(System.local_encode(d))
			
			s,o = commands.getstatusoutput(cmd)
			if s != 0:
				Logger.error("Unable to unmount remaining mount point, home dir %s won't be purged"%(user.pw_dir))
				Logger.debug('umount command "%s" return: %s'%(cmd,  o))
				success = False
		
		return success
开发者ID:Oyatsumi,项目名称:ulteo4Kode4kids,代码行数:24,代码来源:User.py

示例14: createShortcut

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def createShortcut(self, application_):
		lines = []
		lines.append("[Desktop Entry]")
		lines.append("Type=Application")
		lines.append("Terminal=false")
		lines.append("Version=1.0")
		lines.append("Icon=%s"%(os.path.join(self.spool, application_["id"]+".png")))
		lines.append("Name=%s"%(application_["name"]))
		lines.append("Comment=%s"%(application_["description"]))
		lines.append("Exec=%s"%(application_["command"]))
		if application_.has_key("directory"):
			lines.append("Path=%s"%(application_["directory"]))
		
		lines.append("MimeType=%s"%(";".join(application_["mimetypes"])))
		#parser = ConfigParser.ConfigParser()
		#parser.add_section("Desktop Entry")
		#parser.set("Desktop Entry", "Type", "Application")
		#parser.set("Desktop Entry", "Version", "1.0")
		#parser.set("Desktop Entry", "Terminal", "false")
		#parser.set("Desktop Entry", "Icon", os.path.join(self.spool, application_["id"]+".png"))
		#parser.set("Desktop Entry", "Name", application_["name"])
		#parser.set("Desktop Entry", "Comment", application_["description"])
		#parser.set("Desktop Entry", "Exec", application_["command"])
		#parser.set("Desktop Entry", "MimeType", ";".join(application_["mimetypes"]))
		
		path = os.path.join(self.spool, application_["id"]+".desktop")
		try:
			f= file(path, "w")
		except:
			Logger.error("Unable to open file '%s'"%(path))
			return False
		
		f.writelines([System.local_encode(s)+"\n" for s in lines])
		#parser.write(f)
		f.close()
		
		return True
开发者ID:bloveing,项目名称:openulteo,代码行数:39,代码来源:ApplicationsStatic.py

示例15: getSessionID

# 需要导入模块: from ovd.Platform.System import System [as 别名]
# 或者: from ovd.Platform.System.System import local_encode [as 别名]
	def getSessionID(username_):
		return xrdp.SessionGetId(System.local_encode(username_))
开发者ID:Oyatsumi,项目名称:ulteo4Kode4kids,代码行数:4,代码来源:TS.py


注:本文中的ovd.Platform.System.System.local_encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。