capuchin r63 - in trunk: examples src/libcapuchin src/libcapuchin/Compression src/libcapuchin/Installation src/libcapuchin/Installation/Compression src/libcapuchin/Installation/Simple



Author: sebp
Date: Mon Mar 10 17:34:52 2008
New Revision: 63
URL: http://svn.gnome.org/viewvc/capuchin?rev=63&view=rev

Log:
* Created new interface Installation.IInstaller
* Moved installation of files to Installation.Simple.SimpleInstaller



Added:
   trunk/src/libcapuchin/Installation/
   trunk/src/libcapuchin/Installation/Compression/
      - copied from r61, /trunk/src/libcapuchin/Compression/
   trunk/src/libcapuchin/Installation/IInstaller.cs
   trunk/src/libcapuchin/Installation/Simple/
   trunk/src/libcapuchin/Installation/Simple/SimpleInstaller.cs
Removed:
   trunk/src/libcapuchin/Compression/
Modified:
   trunk/examples/testapp.cs
   trunk/src/libcapuchin/AppObject.cs
   trunk/src/libcapuchin/Installation/Compression/Decompresser.cs
   trunk/src/libcapuchin/Installation/Compression/IExtracter.cs
   trunk/src/libcapuchin/Installation/Compression/TarBz2Extracter.cs
   trunk/src/libcapuchin/Installation/Compression/TarExtracter.cs
   trunk/src/libcapuchin/Installation/Compression/TarGzExtracter.cs
   trunk/src/libcapuchin/Installation/Compression/ZipExtracter.cs
   trunk/src/libcapuchin/Makefile.am
   trunk/src/libcapuchin/libcapuchin.mdp

Modified: trunk/examples/testapp.cs
==============================================================================
--- trunk/examples/testapp.cs	(original)
+++ trunk/examples/testapp.cs	Mon Mar 10 17:34:52 2008
@@ -53,32 +53,46 @@
 		Console.WriteLine ("ALL:");
 		foreach (string s in stuff)
 		{
-			Console.WriteLine ("ID: " + s);
-            Console.WriteLine ("Name: " + this.appobject.GetName(s));
-            Console.WriteLine ("Description: " + this.appobject.GetDescription(s) );
-            string[] author = this.appobject.GetAuthor(s);
-            Console.WriteLine ("Author: {0} <{1}>", author[0], author[1]);
+			this.printPluginInfos (s);
 		}
 	}
 	
+	private void printPluginInfos (string s) {
+		Console.WriteLine ("ID: " + s);
+        Console.WriteLine ("Name: " + this.appobject.GetPluginName(s));
+        Console.WriteLine ("Description: " + this.appobject.GetPluginDescription(s) );
+        string[] author = this.appobject.GetPluginAuthor(s);
+        Console.WriteLine ("Author: {0} <{1}>", author[0], author[1]);
+		string[] tags = this.appobject.GetPluginTags(s);
+		Console.WriteLine ("TAGS for {0}:", s);
+		foreach (string t in tags)
+		{
+			Console.WriteLine (t);
+		}
+		Console.WriteLine();
+	}
+	
 	public void testGetAvailableUpdates()
 	{
 		string[][] plugins = new string[2][];
-		plugins[0] = new string[] {"leoorg.py", "0.2.0"};
-		plugins[1] = new string[] {"ssh.py", "0.0.9"};
+		plugins[0] = new string[] {"ssh.py", "0.0.9"};
+		plugins[1] = new string[] {"ekiga.py", "0.1.0"};
 		
 		string[] updates = this.appobject.GetAvailableUpdates (plugins);
 		Console.WriteLine ("UPDATES:");
 		foreach (string s in updates)
 		{
 			Console.WriteLine (s);
-            Console.WriteLine ("Changes: " + this.appobject.GetChanges(s, "1.1.0.0"));
+            Console.WriteLine ("Changes: " + this.appobject.GetPluginChanges(s, "1.1.0.0"));
 		}
 	}
 	
-	public void testGetTags()
-	{
-		string[] tags = this.appobject.GetTags("leoorg.py");
+    public void testGetApplicationName () {
+        Console.WriteLine ("APPLICATION-NAME: {0}", this.appobject.GetApplicationName ());
+    }
+	
+	public void testGetTags () {
+		string[] tags = this.appobject.GetTags ();
 		Console.WriteLine ("TAGS:");
 		foreach (string t in tags)
 		{
@@ -86,19 +100,17 @@
 		}
 	}
 	
-	public void testGetAuthor()
-	{
-		string[] author = this.appobject.GetAuthor("leoorg.py");
-		Console.WriteLine ("AUTHOR: {0}, {1}", author[0], author[1]);
+	public void testGetPluginsWithTag () {
+		Console.WriteLine("PLUGINS WITH TAG:");
+		string[] ids = this.appobject.GetPluginsWithTag ("phone");
+		foreach (string id in ids) {
+			this.printPluginInfos (id);
+		}
 	}
-    
-    public void testGetApplicationName () {
-        Console.WriteLine ("APPLICATION-NAME: {0}", this.appobject.GetApplicationName ());
-    }
 	
 	public void testInstall()
 	{
-		this.appobject.Install("leoorg.py");
+		this.appobject.Install("ekiga.py");
 	}
 	
 	public void testClose()
@@ -111,10 +123,10 @@
         test.testGetApplicationName();
         test.testGetAvailablePlugins();
 		test.testGetAvailableUpdates();
-		test.testGetTags();
-		test.testGetAuthor();
+		test.testGetTags ();
+		test.testGetPluginsWithTag ();
 		test.testInstall();
-		Thread.Sleep(5000); // Wait 5s for update to complete, because we have no mainloop
+		Thread.Sleep(10000); // Wait 5s for update to complete, because we have no mainloop
 		test.testClose();
 	}
 	

Modified: trunk/src/libcapuchin/AppObject.cs
==============================================================================
--- trunk/src/libcapuchin/AppObject.cs	(original)
+++ trunk/src/libcapuchin/AppObject.cs	Mon Mar 10 17:34:52 2008
@@ -6,7 +6,8 @@
 using System.Xml.Serialization;
 using System.Threading;
 using Capuchin.Verification;
-using Capuchin.Compression;
+using Capuchin.Installation;
+using Capuchin.Installation.Simple;
 using Capuchin.Logging;
 using Capuchin.Xml;
 
@@ -237,7 +238,8 @@
         /// </summary>
         public string GetPluginChanges (string plugin_id, string version)
         {
-            if (this.RepoItems[plugin_id].Changelog.ContainsKey (version))
+			changelog changes = this.RepoItems[plugin_id].Changelog;
+            if (changes != null && changes.ContainsKey (version))
             {
                 return this.RepoItems[plugin_id].Changelog[version];
             } else {
@@ -296,6 +298,8 @@
         /// <param name="checksumField">Checksum information</param>
         internal void CheckFile (string local_file, string signature, checksum checksumField)
         {
+			Log.Info ("Checking file");
+			
             if (checksumField != null)
             {
                 FileStream fs = new FileStream( local_file, FileMode.Open );
@@ -325,20 +329,18 @@
             }
         }
          
-        /// <summary>Extract file</summary>
-        /// <param name="local_file_obj">A <see cref="Capuchin.Download" /> instance</param>   
-        protected void ExtractFile (object local_file_obj)
+        /// <summary>Actually install the file</summary>
+        /// <param name="local_file_obj">
+		/// A <see cref="System.String" /> where the file is located
+		/// </param>   
+        protected void InstallFileReal (object local_file_obj)
         {   
+			Log.Info ("Installing file");
+			
             string local_file = (string)local_file_obj;
 
-            Log.Info("Decompressing {0} to {1}", local_file, this.InstallPath);            
-            
-            Decompresser decomp = new Decompresser(local_file, this.InstallPath);
-            decomp.Run();
-         
-            if (decomp.DeleteFile)
-                Log.Info("Deleting archive {0}", local_file);
-                File.Delete(local_file);
+			IInstaller installer = new SimpleInstaller (this.InstallPath);
+			installer.InstallFile (local_file);
         }
 		
 		protected void fillTagToPlugins ()
@@ -421,7 +423,7 @@
                 wresp.Close();
                 return (File.GetLastWriteTime(this.LocalRepo) >= remoteModTime);
             } catch (WebException e) {
-                throw new RepositoryConnectionException("Connection to repository "+this.RepositoryURL+" failed", e);
+				throw new RepositoryConnectionException("Connection to repository "+this.RepositoryURL+" failed: "+e.Message, e);
             }
         }
             
@@ -442,6 +444,7 @@
         
         private void OnDownloadFinished (int dlid)
         {
+			Log.Info ("DA SAMER");
             if (dlid == this.repo_dlid) {
                 this.LoadRepository();
                 return;
@@ -459,10 +462,10 @@
             // Check file
             this.CheckFile(local_file, this.RepoItems[plugin_id].Signature, this.RepoItems[plugin_id].Checksum);
             
-            // Extract archive
-            Thread extractThread = new Thread( new ParameterizedThreadStart( this.ExtractFile ) );
-            extractThread.Start( local_file );            
-            while (extractThread.IsAlive)
+            // Install file
+            Thread installThread = new Thread( new ParameterizedThreadStart( this.InstallFileReal ) );
+			installThread.Start( local_file );
+            while (installThread.IsAlive)
             {
                 this.OnStatus( ActionType.ExtractingPlugin, plugin_id, -1.0, -1);
                 Thread.Sleep(SLEEP_TIME);

Modified: trunk/src/libcapuchin/Installation/Compression/Decompresser.cs
==============================================================================
--- /trunk/src/libcapuchin/Compression/Decompresser.cs	(original)
+++ trunk/src/libcapuchin/Installation/Compression/Decompresser.cs	Mon Mar 10 17:34:52 2008
@@ -5,8 +5,9 @@
 using ICSharpCode.SharpZipLib.Tar;
 using ICSharpCode.SharpZipLib.Zip;
 using System.IO;
+using Capuchin.Logging;
 
-namespace Capuchin.Compression
+namespace Capuchin.Installation.Compression
 {
     internal class Decompresser
     {
@@ -27,23 +28,25 @@
         }
         
         public void Run() {
-            string mime_type = Gnome.Vfs.MimeType.GetMimeTypeForUri(path);
-            
-          IExtracter extracter = null;
-          if (mime_type == "application/x-bzip-compressed-tar"){
-              extracter = new TarBz2Extracter();
-              this.deleteField = true;
-          } else if (mime_type == "application/x-compressed-tar") {
-              extracter = new TarGzExtracter();
-              this.deleteField = true;
-          } else if (mime_type == "application/zip") {
-              extracter = new ZipExtracter();
-              this.deleteField = true;
-          }
-          // Do nothing for "text/x-python"
-          if (extracter != null)
-              extracter.Extract(this.path, this.dest_dir);
-        }
+			Log.Info("Decompressing {0} to {1}", this.path, this.dest_dir);
+			
+			string mime_type = Gnome.Vfs.MimeType.GetMimeTypeForUri(path);
+
+			IExtracter extracter = null;
+			if (mime_type == "application/x-bzip-compressed-tar"){
+				extracter = new TarBz2Extracter();
+				this.deleteField = true;
+			} else if (mime_type == "application/x-compressed-tar") {
+				extracter = new TarGzExtracter();
+				this.deleteField = true;
+			} else if (mime_type == "application/zip") {
+				extracter = new ZipExtracter();
+				this.deleteField = true;
+			}
+			// Do nothing for "text/x-python"
+			if (extracter != null)
+				extracter.Extract(this.path, this.dest_dir);
+			}
     }
     
 }

Modified: trunk/src/libcapuchin/Installation/Compression/IExtracter.cs
==============================================================================
--- /trunk/src/libcapuchin/Compression/IExtracter.cs	(original)
+++ trunk/src/libcapuchin/Installation/Compression/IExtracter.cs	Mon Mar 10 17:34:52 2008
@@ -1,7 +1,7 @@
 
 using System;
 
-namespace Capuchin.Compression
+namespace Capuchin.Installation.Compression
 {
     internal interface IExtracter
     {

Modified: trunk/src/libcapuchin/Installation/Compression/TarBz2Extracter.cs
==============================================================================
--- /trunk/src/libcapuchin/Compression/TarBz2Extracter.cs	(original)
+++ trunk/src/libcapuchin/Installation/Compression/TarBz2Extracter.cs	Mon Mar 10 17:34:52 2008
@@ -3,7 +3,7 @@
 using System.IO;
 using ICSharpCode.SharpZipLib.BZip2;
 
-namespace Capuchin.Compression
+namespace Capuchin.Installation.Compression
 {
     
     

Modified: trunk/src/libcapuchin/Installation/Compression/TarExtracter.cs
==============================================================================
--- /trunk/src/libcapuchin/Compression/TarExtracter.cs	(original)
+++ trunk/src/libcapuchin/Installation/Compression/TarExtracter.cs	Mon Mar 10 17:34:52 2008
@@ -3,7 +3,7 @@
 using System.IO;
 using ICSharpCode.SharpZipLib.Tar;
 
-namespace Capuchin.Compression
+namespace Capuchin.Installation.Compression
 {
     
     

Modified: trunk/src/libcapuchin/Installation/Compression/TarGzExtracter.cs
==============================================================================
--- /trunk/src/libcapuchin/Compression/TarGzExtracter.cs	(original)
+++ trunk/src/libcapuchin/Installation/Compression/TarGzExtracter.cs	Mon Mar 10 17:34:52 2008
@@ -3,7 +3,7 @@
 using System.IO;
 using ICSharpCode.SharpZipLib.GZip;
 
-namespace Capuchin.Compression
+namespace Capuchin.Installation.Compression
 {
     
     

Modified: trunk/src/libcapuchin/Installation/Compression/ZipExtracter.cs
==============================================================================
--- /trunk/src/libcapuchin/Compression/ZipExtracter.cs	(original)
+++ trunk/src/libcapuchin/Installation/Compression/ZipExtracter.cs	Mon Mar 10 17:34:52 2008
@@ -3,7 +3,7 @@
 using System.IO;
 using ICSharpCode.SharpZipLib.Zip;
 
-namespace Capuchin.Compression
+namespace Capuchin.Installation.Compression
 {
     
     internal class ZipExtracter : IExtracter

Added: trunk/src/libcapuchin/Installation/IInstaller.cs
==============================================================================
--- (empty file)
+++ trunk/src/libcapuchin/Installation/IInstaller.cs	Mon Mar 10 17:34:52 2008
@@ -0,0 +1,11 @@
+using System;
+
+namespace Capuchin.Installation
+{
+	
+	public interface IInstaller
+	{
+		bool CanInstallFile (string location);
+		void InstallFile (string location);
+	}
+}

Added: trunk/src/libcapuchin/Installation/Simple/SimpleInstaller.cs
==============================================================================
--- (empty file)
+++ trunk/src/libcapuchin/Installation/Simple/SimpleInstaller.cs	Mon Mar 10 17:34:52 2008
@@ -0,0 +1,52 @@
+using System;
+using System.IO;
+using Capuchin.Logging;
+using Capuchin.Installation;
+using Capuchin.Installation.Compression;
+
+namespace Capuchin.Installation.Simple
+{
+	/// <summary>
+	/// Just copies the file to the desired location
+	/// or extracts the archive (if applicable)
+	/// </summary>
+	public class SimpleInstaller : IInstaller
+	{
+		protected readonly string InstallPath; 
+		
+		/// <summary>
+		/// Creates a new class
+		/// </summary>
+		/// <param name="install_dir">Directory where the files will be installed</param>
+		public SimpleInstaller(string install_dir)
+		{
+			this.InstallPath = install_dir;
+		}
+		
+		/// <summary>
+		/// Whether the <see cref="Capuchin.Installation.IInstaller"/>
+		/// can install the provided file
+		/// </summary>
+		/// <param name="location">Where the file to install is located</param>
+		/// <returns>
+		/// Always true. As this <see cref="Capuchin.Installation.IInstaller"/>
+		/// just copies the file or extracts the archive (if applicable).
+		/// </returns>		
+		public bool CanInstallFile (string location)
+		{
+			return true;
+		}
+		
+		public void InstallFile (string location)
+		{
+			Log.Info ("Installing file {0} to {1}", location, this.InstallPath);
+			
+			Decompresser decomp = new Decompresser(location, this.InstallPath);
+            decomp.Run();
+         
+            if (decomp.DeleteFile)
+                Log.Info("Deleting archive {0}", location);
+			File.Delete(location);
+		}
+	}
+}

Modified: trunk/src/libcapuchin/Makefile.am
==============================================================================
--- trunk/src/libcapuchin/Makefile.am	(original)
+++ trunk/src/libcapuchin/Makefile.am	Mon Mar 10 17:34:52 2008
@@ -4,12 +4,14 @@
 libcapuchin_sources_in = AssemblyInfo.cs.in Globals.cs.in
 libcapuchin_generated_sources = $(libcapuchin_sources_in:.in=)
 libcapuchin_sources = \
-	Compression/Decompresser.cs \
-	Compression/IExtracter.cs \
-	Compression/TarBz2Extracter.cs \
-	Compression/TarGzExtracter.cs \
-	Compression/ZipExtracter.cs \
-	Compression/TarExtracter.cs \
+	Installation/Compression/Decompresser.cs \
+	Installation/Compression/IExtracter.cs \
+	Installation/Compression/TarBz2Extracter.cs \
+	Installation/Compression/TarGzExtracter.cs \
+	Installation/Compression/ZipExtracter.cs \
+	Installation/Compression/TarExtracter.cs \
+	Installation/Simple/SimpleInstaller.cs \
+	Installation/IInstaller.cs \
 	Downloaders/AbstractDownloader.cs \
 	Downloaders/HttpDownloader.cs \
 	Logging/DelayedTextWriter.cs \

Modified: trunk/src/libcapuchin/libcapuchin.mdp
==============================================================================
--- trunk/src/libcapuchin/libcapuchin.mdp	(original)
+++ trunk/src/libcapuchin/libcapuchin.mdp	Mon Mar 10 17:34:52 2008
@@ -16,12 +16,6 @@
   <Contents>
     <File name="AppObject.cs" subtype="Code" buildaction="Compile" />
     <File name="AppObjectManager.cs" subtype="Code" buildaction="Compile" />
-    <File name="Compression/Decompresser.cs" subtype="Code" buildaction="Compile" />
-    <File name="Compression/IExtracter.cs" subtype="Code" buildaction="Compile" />
-    <File name="Compression/TarBz2Extracter.cs" subtype="Code" buildaction="Compile" />
-    <File name="Compression/TarGzExtracter.cs" subtype="Code" buildaction="Compile" />
-    <File name="Compression/TarExtracter.cs" subtype="Code" buildaction="Compile" />
-    <File name="Compression/ZipExtracter.cs" subtype="Code" buildaction="Compile" />
     <File name="Verification/ChecksumVerifier.cs" subtype="Code" buildaction="Compile" />
     <File name="Verification/GnuPGVerifier.cs" subtype="Code" buildaction="Compile" />
     <File name="Verification/IVerifier.cs" subtype="Code" buildaction="Compile" />
@@ -45,6 +39,16 @@
     <File name="Xml/checksum.cs" subtype="Code" buildaction="Compile" />
     <File name="Xml/author.cs" subtype="Code" buildaction="Compile" />
     <File name="IDownloadManager.cs" subtype="Code" buildaction="Compile" />
+    <File name="Installation" subtype="Directory" buildaction="Compile" />
+    <File name="Installation/Compression/Decompresser.cs" subtype="Code" buildaction="Compile" />
+    <File name="Installation/Compression/IExtracter.cs" subtype="Code" buildaction="Compile" />
+    <File name="Installation/Compression/TarBz2Extracter.cs" subtype="Code" buildaction="Compile" />
+    <File name="Installation/Compression/TarExtracter.cs" subtype="Code" buildaction="Compile" />
+    <File name="Installation/Compression/TarGzExtracter.cs" subtype="Code" buildaction="Compile" />
+    <File name="Installation/Compression/ZipExtracter.cs" subtype="Code" buildaction="Compile" />
+    <File name="Installation/IInstaller.cs" subtype="Code" buildaction="Compile" />
+    <File name="Installation/Simple" subtype="Directory" buildaction="Compile" />
+    <File name="Installation/Simple/SimpleInstaller.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="gnome-vfs-sharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]