[prev in list] [next in list] [prev in thread] [next in thread] 

List:       klik-devel
Subject:    [klik-devel] [klikclient commit] r1281 - in
From:       codesite-noreply () google ! com
Date:       2008-02-29 23:09:31
Message-ID: 00163646ce78044754217f06734666a1 () google ! com
[Download RAW message or body]

Author: razielmine
Date: Fri Feb 29 15:08:49 2008
New Revision: 1281

Modified:
   trunk/client/trunk/klikclient/bin/klik
   trunk/client/trunk/klikclient/lib/klik/base.py
   trunk/client/trunk/klikclient/lib/klik/cmg.py
   trunk/client/trunk/klikclient/lib/klik/utils/freedesktop.py

Log:
- Fixed klik *.xml
- Optimice file extraction from klik2 packages having the posibility to 
get the output in a pipe instead of saving to a temporal file
- Deleted obsolete __is_klik2_cmg and __is_klik2_cmg functions


Modified: trunk/client/trunk/klikclient/bin/klik
==============================================================================
--- trunk/client/trunk/klikclient/bin/klik	(original)
+++ trunk/client/trunk/klikclient/bin/klik	Fri Feb 29 15:08:49 2008
@@ -148,8 +148,8 @@
 		else:
 			first_arg = sys.argv[1]
 			args = sys.argv[2:]
-				
-			if os.path.exists( first_arg ):
+				                       # TODO: quick hack to avoid .xml b0rkenage, 
fix this properly
+			if os.path.exists( first_arg ) and first_arg.lower().endswith(".cmg"):
 				cmg = KlikCmg( klik, first_arg )
 				result, text = cmg.execute(None, args)

@@ -172,9 +172,8 @@
 					print "Error: Could not extract icon"

 			elif first_arg == "shell":
-				print "boom"
 				cmg = KlikCmg( klik, args[0] )
-				cmg.execute_shell(None)
+				cmg.execute_shell()

 			elif first_arg == "pack":
 				cmg = KlikCmg( klik, args[0] )

Modified: trunk/client/trunk/klikclient/lib/klik/base.py
==============================================================================
--- trunk/client/trunk/klikclient/lib/klik/base.py	(original)
+++ trunk/client/trunk/klikclient/lib/klik/base.py	Fri Feb 29 15:08:49 2008
@@ -204,7 +204,10 @@

 	def load_recipe(self, recipe_path):
 		recipe = KlikRecipe()
-		recipe.load_from_file( recipe_path )
+		if type(recipe_path) is file:
+			recipe.load_from_string( recipe_path.read() )
+		else:
+			recipe.load_from_file( recipe_path )
 		return recipe

 	def create_cmg(self, recipe_object ):
@@ -225,7 +228,7 @@
 		mtype, entype = mimetypes.guess_type(filename)
  		if mtype in 
[ "text/xml", "application/xml", "application/x-extension-cmg-recipe" ]:
 			return True
-		return filename.endswith(".recipe") or filename.endswith(".xml")
+		return filename.endswith(".recipe") or filename.endswith(".xml")




Modified: trunk/client/trunk/klikclient/lib/klik/cmg.py
==============================================================================
--- trunk/client/trunk/klikclient/lib/klik/cmg.py	(original)
+++ trunk/client/trunk/klikclient/lib/klik/cmg.py	Fri Feb 29 15:08:49 2008
@@ -139,37 +139,55 @@
 		return ex.execute_shell(self, self.__get_command([None], False))
 		
 	def get_recipe(self):
-		if self.__recipe == None:
-			temp_path = tempfile.mktemp()
-			self.extract_file("/recipe.xml", temp_path)
+		if not self.__recipe:
+			temp_path, is_pipe = self.extract_file("/recipe.xml")
 			try:
 				self.__recipe = self.klik.load_recipe( temp_path )
-				os.remove(temp_path)
-				return self.__recipe
+				if not is_pipe:
+					os.remove(temp_path)
 			except:
-				# no recipe
 				pass
-			
-			return None
-		else:
-			return self.__recipe
+		return self.__recipe
 	
-	def extract_file(self, file_path_from, file_path_to):
-		if self.__is_klik1_cmg():
-			
+	def extract_file(self, file_path_from, file_path_to=None):
+		# Returns:
+		#   if file_path_to == None: (path to file extracted or pipe object, 
(bool) returning a pipe object)
+		#   if file_path_to != None: file_path_to was succesfully extracted
+		
+		if self.cmg_version == 1:
+			# Klik1 packages: mount cramfs and copy file
 			if file_path_from[0] == "/": file_path_from = file_path_from[1:]
-			temp_path = tempfile.mkdtemp( '.extract.' + os.environ["USER"], 
self.klik.settings.temp_directory_path )
+			mnt_path = tempfile.mkdtemp( '.extract.' + self.get_unique_id(), 
self.klik.settings.temp_directory_path )
+			file_path_from = os.path.join(mnt_path, file_path_from)
+			pipe = False
 			try:
 				try:
-					subprocess.Popen(["/opt/klik/bin/fusecram", "-n", "-p", 
self.path, temp_path, "-s"]).wait()
-					shutil.copy( os.path.join(temp_path, file_path_from), 
file_path_to )
+					# Mount cramfs
+					subprocess.Popen(["/opt/klik/bin/fusecram", "-n", "-p", 
self.path, mnt_path, "-s"]).wait()
+					if not file_path_to:
+						file_path_to = tempfile.mktemp( self.get_unique_id(),
+									self.klik.settings.temp_directory_path )
+					shutil.copy( file_path_from, file_path_to )
+					if not file_path_to:
+						file = os.path.exists( file_path_to )
 				except IOError:
-					return False
+					file = None
 			finally:
-				subprocess.Popen(["fusermount", "-u", temp_path]).wait()
+				subprocess.Popen(["fusermount", "-u", mnt_path]).wait()
+				
+		else:
+			# Klik2 packages: if file_path_to != None, extract file; otherwise 
write file to a pipe
+			if file_path_to:
+				subprocess.Popen(["cmginfo", "-f", self.path, "-e", 
file_path_from, "-o", file_path_to]).wait()
+			else:
+				p = subprocess.Popen(["cmginfo", "-f", self.path, "-e", 
file_path_from], stdout=subprocess.PIPE)
+				file = p.stdout
+				pipe = True
+				
+		if file_path_to:
+			return os.path.exists( file_path_to )
 		else:
-			subprocess.Popen(["cmginfo", "-f", self.path, "-e", 
file_path_from, "-o", file_path_to]).wait()
-		return os.path.exists( file_path_to )
+			return (file, pipe)
 		
 		
 	def is_valid_cmg(self):
@@ -194,7 +212,10 @@
 							f.seek(22)
 							magic = str(f.read(28)).strip()
 							# Ima is NOT a typo!  only picking 28 chars up
-							if magic.startswith("Compressed Application Image") or 
magic.startswith("KLIK2 ISO") or magic.startswith("# Compressed 
Application Ima") or magic.startswith("# KLIK2 ISO"):
+							if (magic.startswith("Compressed Application Image") or
+							    magic.startswith("KLIK2 ISO") or
+							    magic.startswith("# Compressed Application Ima") or
+							    magic.startswith("# KLIK2 ISO")):
 								f.close()
 								self.__cmg_version = 2
 								return self.__cmg_version
@@ -218,24 +239,6 @@
 					f.close()
 			self.__cmg_version = 0
 		return self.__cmg_version
-
-	def __is_klik2_cmg(self):
-		# Klik2 Compatability....
-		f = open(self.path, "r")
-		f.seek(22)     # Go to the 22nd byte in the file
-		magic = str(f.read(28)).strip()
-		print "::", magic
-		test = magic.startswith( "# Compressed Application Ima" ) or 
magic.startswith( "# KLIK2 ISO" ) or magic.startswith ( "Compressed 
Application Image" ) or magic.startswith( "KLIK2 ISO" )
-		f.close()
-		return test
-	
-	def __is_klik1_cmg(self):
-		# Klik1 Compatability....
-		f = open(self.path, "r")
-		f.seek(16)     # Go to the 16th byte in the file
-		test = ( str(f.read(16)).strip() == "Compressed ROMFS" )
-		f.close()
-		return test
 		
 	# Return all the files in a given CMG that match pre and post text
 	def find_files(self, pre_text=None, post_text=None, omit_extension=False):
@@ -265,12 +268,7 @@
 		# Returns a list of icons for a .desktop entry

 		icon = do.get( "Icon" )
-
-		if not icon:
-			# No icon specifyed, fallback to CMG icon
-			return ["/.DirIcon"]
-
-		else:
+		if icon and icon != "/.DirIcon":
 			# Check if the icon belongs to the default theme
 			theme_icon = None
 			if icon[0] != "/" and self.klik.xdg.get_is_gtk_installed():
@@ -289,9 +287,8 @@
  				icon_files = self.find_files( "/usr/share/icons/", icon, 
omit_extension=True )
 				if icon_files:
 					return icon_files
-				else:
-					# Icon doesn't exist, fallback to CMG icon
-					return ["/.DirIcon"]
+		# Icon doesn't exist, fallback to CMG icon
+		return ["/.DirIcon"]


 	# Get desktop objects set to execute cmg
@@ -301,11 +298,11 @@
 		desktop_objects = []
 		for file in self.find_files("/usr/share/applications/", ".desktop"):
 			# Extract and parse the .desktop file
-			temp_path = tempfile.mktemp()
-
-			if self.extract_file( file, temp_path ): # TODO: extract to 
standard output instead of a file
+			temp_path, is_pipe = self.extract_file( file )
+			if temp_path:
 				do = DesktopParser( temp_path )
-				os.remove( temp_path )
+				if not is_pipe:
+					os.remove( temp_path )

 				if do.get("Exec") and (do.get("Type") == "Application"):
 					desktop_objects.append( do )
@@ -319,24 +316,25 @@
 			for menu_file in menu_files:

 				# Extract and parse the .desktop file
-				temp_path = tempfile.mktemp()
-
-				if not self.extract_file( menu_file, temp_path ):
-					print "\t!! Couldn't extract", menu_file
-
-				else:
+				temp_path, is_pipe = self.extract_file( menu_file )
+				if temp_path:
 					for mo in MenuParser( temp_path ).menu_objects:
 						do = DesktopParser()
-
+						
 						do.set("Type", "Application")
 						do.set("Exec", mo.command)
-						do.set( "X-CMG", self.path )
+						do.set("X-CMG", self.path)
 						do.set("Name", mo.title.capitalize())
 						#do.set("Terminal", recipe.require_terminal)
 						do.set("Icon", mo.icon)
 						do.set("Categories", mo.freedesktop_category)

 						desktop_objects.append( do )
+					if not is_pipe:
+						os.remove( temp_path )
+						
+				else:
+					print "\t!! Couldn't extract", menu_file

 		# Couldn't find any desktop file, build a basic one
 		if len(desktop_objects) == 0:

Modified: trunk/client/trunk/klikclient/lib/klik/utils/freedesktop.py
==============================================================================
--- trunk/client/trunk/klikclient/lib/klik/utils/freedesktop.py	(original)
+++ trunk/client/trunk/klikclient/lib/klik/utils/freedesktop.py	Fri Feb 
29 15:08:49 2008
@@ -27,13 +27,16 @@
 		ConfigParser.__init__(self)
 		self.filename = filename
 		self.file_type = file_type
+		self._list_separator = ";"
 		if filename:
-			if len(self.read(filename)) == 0:
-				#file doesn't exist
-				self.add_section('Desktop Entry')
+			if type(filename) is file:
+				self.readfp(filename)
+			else:
+				if not self.read(filename):
+					#file doesn't exist
+					self.add_section('Desktop Entry')
 		else:
 			self.add_section('Desktop Entry')
-		self._list_separator = ';'

 	def optionxform(self, option):
 		#makes keys not be lowercase
_______________________________________________
klik-devel mailing list
klik-devel@kde.org
https://mail.kde.org/mailman/listinfo/klik-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic