예제 #1
0
		protected override bool PullPackageProperties ()
		{
			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string [] { "rpm", "-qp", "--queryformat", property_queryformat, FileInfo.FullName };
			pc.RedirectStandardOutput = true;
			pc.UseLangC = true;

			// Let rpm run for 15 seconds for properties, max.
			pc.CpuLimit = 15;
			
			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				return false;
			}

			StreamReader pout = new StreamReader (pc.StandardOutput);

			// Order is dependent on the queryformat string
			PackageName = ReadString (pout);
			PackageVersion = ReadString (pout);
			Summary = ReadString (pout);
			Category = ReadString (pout);
			License = ReadString (pout);
			Packager = ReadString (pout);
			Homepage = ReadString (pout);
			string size = ReadString (pout);
			Size = Convert.ToInt64 (size);

			pout.Close ();
			pc.Close ();

			return true;
		}
예제 #2
0
		public override void Open ()
		{
			SafeProcess p = new SafeProcess ();

			switch (Hit.Source) {
			case "Tomboy":
				// This doesn't work very well if you have multiple
				// terms that match.  Tomboy doesn't seem to have a way
				// to specify more than one thing to highlight.
				p.Arguments = new string [] { "tomboy",
							      "--open-note", Hit.EscapedUri,
							      "--highlight-search", Query.QuotedText };
				break;
			
			case "Labyrinth":
				p.Arguments = new string [] { "labyrinth", "-m", Hit.FileInfo.Name };
				break;

			case "EvolutionDataServer":
				p.Arguments = new string [] { "evolution", Hit.EscapedUri };
				break;
			}

			try {
				p.Start ();
			} catch (Exception e) {
				Console.WriteLine ("Could not open note: " + e);
			}
		}
예제 #3
0
		protected override void RegisterSupportedTypes ()
		{
			// Get the list of mime-types from the totem-video-indexer

			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string [] { "totem-video-indexer", "--mimetype" };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = true;
			pc.UseLangC = true;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				if (Debug)
					Log.Debug (e.Message);

				return;
			}

			StreamReader pout = new StreamReader (pc.StandardOutput);
			string str;

			while ((str = pout.ReadLine ()) != null) {
				FilterFlavor flavor = FilterFlavor.NewFromMimeType (str);
				flavor.Priority = Priority;

				AddSupportedFlavor (flavor);

				if (Debug)
					Log.Debug ("Added {0} as a supported mime type for Totem video filter", str);
			}

			pout.Close ();
			pc.Close ();
		}
예제 #4
0
		public static SafeProcess GetSafeProcess (params string[] args)
		{
			SafeProcess p = new SafeProcess ();
			
			p.Arguments = new string [1 + args.Length];
			p.Arguments [0] = ExecutableName;
			Array.Copy (args, 0, p.Arguments, 1, args.Length);
			
			return p;
		}
예제 #5
0
        public static SafeProcess GetSafeProcess(params string[] args)
        {
            SafeProcess p = new SafeProcess();

            p.Arguments     = new string [1 + args.Length];
            p.Arguments [0] = ExecutableName;
            Array.Copy(args, 0, p.Arguments, 1, args.Length);

            return(p);
        }
예제 #6
0
		public override void Open ()
		{
			SafeProcess p = new SafeProcess ();
			p.Arguments = new string [] { "yelp", Hit.Uri.LocalPath };
			
			try {
				p.Start ();
			} catch {
				Console.WriteLine ("Failed to start '{0}'", p.Arguments [0]);
			}
		}
예제 #7
0
		public override void Open ()
		{
			SafeProcess p = new SafeProcess ();
			p.Arguments = new string [] { "evolution", Hit.EscapedUri };

			try {
				p.Start ();
			} catch (SafeProcessException e) {
				Console.WriteLine (e.Message);
			}
		}
예제 #8
0
		public void FindFromHost()
		{
			
			SafeProcess p = new SafeProcess ();
			//string addr = Search.Tiles.Utils.GetFirstPropertyOfParent(Hit,"fixme:from_address");
			p.Arguments = new string [] { "beagle-search", String.Format ("host:{0}", Hit.Uri.Host) };
			try {
				p.Start () ;
			} catch (Exception e) {
				Console.WriteLine ("Error launching new search: " + e.Message);
			}
		}
예제 #9
0
		public void FindAllFromSender()
		{
			SafeProcess p = new SafeProcess ();
			string addr = Beagle.Search.Tiles.Utils.GetFirstPropertyOfParent(Hit,"fixme:from_address");
			p.Arguments = new string [] { "beagle-search", String.Format ("mailfromaddr:{0}", addr) };

			try {
				p.Start () ;
			} catch (Exception e) {
				Console.WriteLine ("Error launching new search: " + e.Message);
			}
		}
예제 #10
0
		static FilterBibTex ()
		{
			// Check if bibparse is present
			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string [] { "bibparse"};
			pc.RedirectStandardOutput = false;
			pc.RedirectStandardError = false;

			try {
				pc.Start ();
				bibparse_installed = true;
			} catch (SafeProcessException) {
				Log.Warn ("bibparse is not found; bibtex files will not be indexed");
				bibparse_installed = false;
			}

			pc.Close ();
		}
예제 #11
0
		private bool InitBibparse ()
		{
			bib_process = new SafeProcess ();
			bib_process.Arguments = new string[] { "bibparse", FileInfo.FullName};
			bib_process.RedirectStandardError = false;
			bib_process.RedirectStandardOutput = true;
			bib_process.CpuLimit = 180; // 3 minutes
			bib_process.MemLimit = 50*1024*1024; // 50 MB

			try {
				bib_process.Start ();
			} catch (SafeProcessException e) {
				Log.Error (e, "Error running 'bibparse {0}'", FileInfo.FullName);
				return false;
			}

			reader = new StreamReader (bib_process.StandardOutput);
			return true;
		}
예제 #12
0
		public static SafeProcess GetClientProcess (string client, string uri)
		{
			SafeProcess p = null;

   			if (client == "evolution" || (client == null && uri.StartsWith ("contacts:"))) {
				p = new SafeProcess ();
				p.Arguments = new string [2];
				p.Arguments [0] = "evolution";
				p.Arguments [1] = uri;
			} else if (client == "thunderbird") {
				p = new SafeProcess ();
				p.Arguments = new string [4];
				p.Arguments [0] = "beagle-contactviewer";
				p.Arguments [1] = "--manager";
				p.Arguments [2] = "Thunderbird";
				p.Arguments [3] = uri;
			}

			return p;
                }
예제 #13
0
		override protected void DoPull ()
		{
			// create new external process
			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string [] { "ssindex", "-i", FileInfo.FullName };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = false;
			pc.UseLangC = true;

			// Let ssindex run for 10 seconds, max.
			pc.CpuLimit = 10;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				Error ();
				return;
			}

			// process ssindex output
			StreamReader pout = new StreamReader (pc.StandardOutput);
			xmlReader = new XmlTextReader (pout);

			try {
				WalkContentNodes (xmlReader);
			} catch (Exception e) {
				Logger.Log.Debug ("Exception occurred while indexing {0}.", FileInfo.FullName);
				Logger.Log.Debug (e);
			}

			pout.Close ();
			pc.Close ();

			Finished ();
		}
예제 #14
0
		protected override void DoPull ()
		{
			ExternalFilterInfo efi = GetFilterInfo (this.Extension, this.MimeType);

			if (efi == null) {
				Logger.Log.Warn ("Unable to find a match for extension {0}, mime type {1} when one should have matched", this.Extension, this.MimeType);
				Error ();
			}

			// FIXME: Need to deal with quotation marks in the XML file, probably.
			string[] tmp_argv = efi.Arguments.Split (' ');
			string[] argv = new string [tmp_argv.Length + 1];

			argv [0] = efi.Command;

			int j = 1;
			for (int i = 0; i < tmp_argv.Length; i++) {
				if (tmp_argv [i] == String.Empty)
					continue;

				if (tmp_argv [i] == "%s")
					argv [j] = FileInfo.FullName;
				else
					argv [j] = tmp_argv [i];
				j++;
			}

			SafeProcess pc = new SafeProcess ();
			pc.Arguments = argv;
			pc.RedirectStandardOutput = true;
			pc.UseLangC = true;

			// Let the external filter run for 2 minutes, max.
			pc.CpuLimit = 120;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				Error ();
				return;
			}

			StreamReader pout = new StreamReader (pc.StandardOutput);

			string str;
			while ((str = pout.ReadLine ()) != null) {
				AppendText (str);
				AppendStructuralBreak ();
			}

			pout.Close ();
			pc.Close ();
			Finished ();
		}
예제 #15
0
		protected override void DoPullProperties ()
		{
			// create new external process
			pc = new SafeProcess ();
			pc.Arguments = new string [] { "pdfinfo", "-meta", FileInfo.FullName };
			pc.RedirectStandardOutput = true;
			// See FIXME below for why this is false.
			pc.RedirectStandardError = false;

			// Let pdfinfo run for at most 10 CPU seconds, and not
			// use more than 100 megs memory.
			pc.CpuLimit = 90;
			pc.MemLimit = 100*1024*1024;
			pc.UseLangC = true;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				Error ();
				return;
			}

			// add pdfinfo's output to pool
			pout = new StreamReader (pc.StandardOutput);
			string str = null;
			int idx = -1;
			string strMetaTag = null;
			bool bKeyword = false;
			string prop = null;
			string val = null;

			while ((str = pout.ReadLine ()) != null) {
				bKeyword = false;
				strMetaTag = null;
				idx = str.IndexOf (':');
				if (idx > 0) {
					prop = str.Substring (0, idx);
					val = str.Substring (idx + 1);
					switch (prop) {
					case "Title":
						strMetaTag = "dc:title";
						break;
					case "Author":
						strMetaTag = "dc:author";
						break;
					case "Pages":
						strMetaTag = "fixme:page-count";
						bKeyword = true;
						break;
					case "Creator":
						strMetaTag = "dc:creator";
						break;
					case "Keywords":
						strMetaTag = "dc:keyword";
						break;
					case "Producer":
						strMetaTag = "dc:appname";
						break;
					case "Metadata":
						string xmpString = pout.ReadToEnd();
						XmpFile xmp = new XmpFile (new MemoryStream(System.Text.Encoding.ASCII.GetBytes(xmpString)));
						AddXmpProperties(xmp);
						break;
					}
					if (strMetaTag != null) {
						if (bKeyword)
							AddProperty (Beagle.Property.NewUnsearched (strMetaTag, 
												 val.Trim ()));
						else
							AddProperty (Beagle.Property.New (strMetaTag, 
											  val.Trim ()));
					}
						
				}
			}
			pout.Close ();

#if false
			// Log any errors or warnings from stderr
			pout = new StreamReader (pc.StandardError);
			while ((str = pout.ReadLine ()) != null)
				Log.Warn ("pdfinfo [{0}]: {1}", Indexable.Uri, str);

			pout.Close ();
#endif
			pc.Close ();
		}
예제 #16
0
        public static void StorePasswordKDEWallet(string folder, string username, string password)
        {
            if (String.IsNullOrEmpty(folder) || String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                throw new ArgumentException("folder, username or password", "cannot be empty");
            }

            // Get name of the local wallet
            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "localWallet" };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = false;
            pc.UseLangC = true;

            pc.Start();
            string localWallet = null;

            using (StreamReader pout = new StreamReader(pc.StandardOutput))
                localWallet = pout.ReadLine();
            pc.Close();

            if (String.IsNullOrEmpty(localWallet) || localWallet == "-1")
            {
                throw new ArgumentException("kwalletd", "Local KDE Wallet is not found. Please run kwalletmanager to enable KDE Wallet.");
            }

            // Open local wallet
            pc           = new SafeProcess();
            pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "open", localWallet, "K" };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = false;
            pc.UseLangC = true;

            pc.Start();
            string wallet_id = null;

            using (StreamReader pout = new StreamReader(pc.StandardOutput))
                wallet_id = pout.ReadLine();
            pc.Close();

            if (String.IsNullOrEmpty(wallet_id) || wallet_id == "-1")
            {
                throw new ArgumentException("kwalletd", "Unable to open local KDE wallet");
            }

            // Write given password for the given folder and username
            pc           = new SafeProcess();
            pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "writePassword", wallet_id, folder, username, password };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = false;
            pc.UseLangC = true;

            pc.Start();
            string ret = null;

            using (StreamReader pout = new StreamReader(pc.StandardOutput))
                ret = pout.ReadLine();
            pc.Close();

            if (ret != "0")
            {
                throw new ArgumentException("kwalletd", "Unable to save password.");
            }
        }
예제 #17
0
		protected override void DoPullProperties ()
		{
			if (FileInfo == null) {
				Log.Error ("FilterMPlayerVideo: Unable to extract properties for non-file data");
				Error ();
				return;
			}

			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string [] { "mplayer", "-vo", "null", "-ao", "null", "-frames", "0", "-identify", FileInfo.FullName };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = true;
			pc.UseLangC = true;

			// Let mplayer run for 10 seconds, max.
			pc.CpuLimit = 10;

			// There have been reports of mplayer eating tons of
			// memory.  So limit it to 100 megs too.
			pc.MemLimit = 100*1024*1024;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				Error ();
				return;
			}

			StreamReader pout = new StreamReader (pc.StandardOutput);
			string str;
			string name = String.Empty;
			
			while ((str = pout.ReadLine ()) != null) {
				if (!str.StartsWith ("ID_"))
					continue;

				string[] tokens = str.Split ('=');

				if (tokens.Length != 2)
					continue;

				if (str.StartsWith ("ID_CLIP_INFO_NAME"))
					name = tokens [1].ToLower ();
				else if (str.StartsWith ("ID_CLIP_INFO_VALUE")) {
					switch (name) {

					case "":
						break;

					case "name":
						AddProperty (Beagle.Property.New ("dc:title", tokens [1]));
						break;

					case "language":
						AddProperty (Beagle.Property.NewUnsearched ("dc:language", tokens [1]));
						break;

					case "copyright":
						AddProperty (Beagle.Property.NewUnsearched ("dc:copyright", tokens [1]));
						break;

					case "comments":
						AddProperty (Beagle.Property.New ("dc:description", tokens [1]));
						break;

					default:
						AddProperty (Beagle.Property.NewUnsearched ("fixme:info:" + name, tokens [1]));
						break;
					}
				} else {
					switch (tokens [0]) {

					case "ID_VIDEO_WIDTH":
						width = Convert.ToInt32 (tokens [1]);
						break;

					case "ID_VIDEO_HEIGHT":
						height = Convert.ToInt32 (tokens [1]);
						break;

					case "ID_VIDEO_ASPECT":
						aspect = Convert.ToSingle (tokens [1], CultureInfo.InvariantCulture);
						break;

					case "ID_VIDEO_FPS":
						fps = Convert.ToSingle (tokens [1], CultureInfo.InvariantCulture);
						break;

					case "ID_VIDEO_FORMAT":
						AddProperty (Beagle.Property.NewKeyword ("fixme:video:codec", tokens [1]));
						break;

					case "ID_LENGTH":
						length_seconds = (int) Convert.ToSingle (tokens [1], CultureInfo.InvariantCulture);
						break;

					case "ID_AUDIO_NCH":
						audio_channels = Convert.ToInt32 (tokens [1]);
						break;

					case "ID_AUDIO_CODEC":
						AddProperty (Beagle.Property.NewKeyword ("fixme:audio:codec", tokens [1]));
						break;

					case "ID_DEMUXER":
						AddProperty (Beagle.Property.NewUnsearched ("fixme:video:container", tokens [1]));
						break;
					}
				}
			}
			
			pout.Close ();
			pc.Close ();
			
			// If an aspect ratio wasn't set in the file then work out the
			// pixel aspect ratio
			if (aspect <= 0.0f) {
				if (width > 0 && height > 0)
					aspect = (float) width / (float) height;
			}
			
			if (aspect > 0.0f)
				AddProperty (Beagle.Property.NewUnsearched ("fixme:video:aspect", aspect));

			AddProperty (Beagle.Property.NewUnsearched ("fixme:video:aspect", AspectString (aspect)));

			if (width > 0)
				AddProperty (Beagle.Property.NewUnsearched ("fixme:video:width", width));

			if (height > 0)
				AddProperty (Beagle.Property.NewUnsearched ("fixme:video:height", height));	
			
			if (fps > 0.0f)
				AddProperty (Beagle.Property.NewUnsearched ("fixme:video:fps", fps));
			
			if (length_seconds > 0)
				AddProperty (Beagle.Property.NewUnsearched ("dc:extent", length_seconds));
			
			switch (audio_channels) {

			case 0:
				AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:channel_setup", "none"));
				break;
			case 1:
				AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:channel_setup", "mono"));
				break;
			case 2:
				AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:channel_setup", "stereo"));
				break;
			case 5:
				AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:channel_setup", "4.1"));
				break;
			case 6:
				AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:channel_setup", "5.1"));
				break;
			case 7:
				AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:channel_setup", "6.1"));
				break;
			case 8:
				AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:channel_setup", "7.1"));
				break;
			}
			
			AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:channels", audio_channels));

			Finished ();
		}
예제 #18
0
		private bool InitDoPull ()
		{
			// create new external process
			pc = new SafeProcess ();
			pc.Arguments = new string [] { "pdftotext", "-q", "-nopgbrk", "-enc", "UTF-8", FileInfo.FullName, "-" };
			pc.RedirectStandardOutput = true;

			// FIXME: This should really be true, and we should
			// process the output.  But we can deadlock when
			// pdftotext is blocked writing to stderr because of a
			// full buffer and we're blocking while reading from
			// stdout.
			pc.RedirectStandardError = false;

			// Let pdftotext run for at most 90 CPU seconds, and not
			// use more than 100 megs memory.
			pc.CpuLimit = 90;
			pc.MemLimit = 100*1024*1024;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				Error ();
				return false;
			}

			// add pdftotext's output to pool
			pout = new StreamReader (pc.StandardOutput);
			pull_started = true;

			return true;
		}
예제 #19
0
        public static string ReadPasswordKDEWallet(string folder, string username)
        {
            if (String.IsNullOrEmpty(folder) || String.IsNullOrEmpty(username))
            {
                throw new ArgumentException("folder, username", "cannot be empty");
            }

            // Get name of the local wallet
            SafeProcess pc = new SafeProcess();

            pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "localWallet" };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = false;
            pc.UseLangC = true;

            pc.Start();
            string localWallet = null;

            using (StreamReader pout = new StreamReader(pc.StandardOutput))
                localWallet = pout.ReadLine();
            pc.Close();

            if (String.IsNullOrEmpty(localWallet) || localWallet == "-1")
            {
                throw new ArgumentException("kwalletd", "Unable to reach local KDE wallet");
            }

            // Open local wallet
            pc           = new SafeProcess();
            pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "open", localWallet, "K" };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = false;
            pc.UseLangC = true;

            pc.Start();
            string wallet_id = null;

            using (StreamReader pout = new StreamReader(pc.StandardOutput))
                wallet_id = pout.ReadLine();
            pc.Close();

            if (String.IsNullOrEmpty(wallet_id) || wallet_id == "-1")
            {
                throw new ArgumentException("kwalletd", "Unable to open local KDE wallet");
            }

            // Read password from the given folder and for the given username
            pc           = new SafeProcess();
            pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "readPassword", wallet_id, folder, username };
            pc.RedirectStandardOutput = true;
            pc.RedirectStandardError  = false;
            pc.UseLangC = true;

            pc.Start();
            string password = null;

            using (StreamReader pout = new StreamReader(pc.StandardOutput))
                password = pout.ReadLine();
            pc.Close();

            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentException("kwalletd", "Unable to read password.");
            }

            return(password);
        }
예제 #20
0
		private static void RunDefaultHandler (string command, string uri)
		{
			string[] argv;
			argv = new string [] { command, uri };

			Console.WriteLine ("Cmd: {0}", command);
			Console.WriteLine ("Uri: {0}", uri);

			SafeProcess p = new SafeProcess ();
			p.Arguments = argv;

			try {
				p.Start ();
			} catch (Exception e) {
				Console.WriteLine ("Error in OpenFromMime: " + e);
			}
		}
예제 #21
0
		public void FindSameAuthor()
		{
			SafeProcess p = new SafeProcess ();
			string author = Hit.GetFirstProperty("dc:author");
			if( String.IsNullOrEmpty(author))
				 author = Hit.GetFirstProperty("dc:creator");
			p.Arguments = new string [] { "beagle-search", String.Format ("author:{0} OR creator:{0}", author) };
			try {
				p.Start () ;
			} catch (Exception e) {
				Console.WriteLine ("Error launching new search: " + e.Message);
			}
			
		}
예제 #22
0
		public static SafeProcess GetClientProcess (Beagle.Hit hit)
		{
			string client = null;
			SafeProcess p = null;
			
			if (hit.ParentUri != null)
				client = Utils.GetFirstPropertyOfParent (hit, "fixme:client");
			else
				client = hit.GetFirstProperty ("fixme:client");
			
			if (client == "evolution") {
				p = new SafeProcess ();
				p.Arguments = new string [2];
				p.Arguments [0] = "evolution";
				p.Arguments [1] = (hit.ParentUri != null ? hit.EscapedParentUri : hit.EscapedUri);
			}
#if ENABLE_THUNDERBIRD
			else if (client == "thunderbird")  {
			     p = Thunderbird.GetSafeProcess ("-viewbeagle", hit.GetFirstProperty ("fixme:uri"));
			}
#endif

			return p;
		}
예제 #23
0
		private bool RunExtractor ()
		{
			string extractor_path, exe;

			// Hack, along with magic in beagled-index-helper.in
			// and tools/wrapper.in to make this work in the
			// uninstalled case.
			extractor_path = Environment.GetEnvironmentVariable ("BEAGLE_TOOL_PATH");

			if (extractor_path != null)
				exe = Path.Combine (extractor_path, "beagle-doc-extractor");
			else
				exe = "beagle-doc-extractor";

			pc = new SafeProcess ();
			pc.Arguments = new string [] { exe, FileInfo.FullName };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = true;
			pc.UseLangC = true;

			// Let beagle-doc-extractor run for 90 CPU seconds, max.
			pc.CpuLimit = 90;

			// Some documents make wv1 go crazy with memory.  Limit
			// it to 100 megs of address space, too.
			pc.MemLimit = 100*1024*1024;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e);
				Error ();
				return false;
			}

			pout = new StreamReader (pc.StandardOutput);
			pull_started = true;

			return true;
		}
예제 #24
0
		public void RevealInFolder ()
		{
			string path = Hit.FileInfo.DirectoryName;

			// FIXME: When nautilus implements this, then we should
			// also select the file in the folder.

			SafeProcess p = new SafeProcess ();

#if ENABLE_DESKTOP_LAUNCH
			p.Arguments = new string [] { "desktop-launch", path };
#elif ENABLE_XDG_OPEN
			p.Arguments = new string [] { "xdg-open", path };
#else
			p.Arguments = new string [] { "nautilus", "--no-desktop", path };
#endif
			try {
				p.Start ();
			} catch (Exception e) {
				Console.WriteLine ("Cannot open folder: " + e);
			}
		}
예제 #25
0
		protected override void DoPullProperties ()
		{
			if (FileInfo == null) {
				Log.Error ("FilterTotem: Unable to extract properties for non-file data");
				Error ();
				return;
			}

			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string [] { "totem-video-indexer", FileInfo.FullName };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = true;

			// Let totem run for 10 seconds, max.
			pc.CpuLimit = 10;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				Error ();
				return;
			}

			StreamReader pout = new StreamReader (pc.StandardOutput);
			string str;

			while ((str = pout.ReadLine ()) != null) {
				if (!str.StartsWith ("TOTEM_INFO_"))
					continue;

				string[] tokens = str.Split ('=');

				if (tokens.Length != 2)
					continue;

				switch (tokens [0]) {
					case "":
						break;
					case "TOTEM_INFO_TITLE":
						AddProperty (Beagle.Property.New ("dc:title", tokens [1]));
						break;
					case "TOTEM_INFO_ARTIST":
						AddProperty (Beagle.Property.New ("fixme:artist", tokens [1]));
						break;
					case "TOTEM_INFO_YEAR":
						AddProperty (Beagle.Property.New ("fixme:year", tokens [1]));
						break;
					case "TOTEM_INFO_ALBUM":
						AddProperty (Beagle.Property.New ("fixme:album", tokens [1]));
						break;
					case "TOTEM_INFO_DURATION":
						//FIXME dc:extent or fixme:duration???
						AddProperty (Beagle.Property.NewUnsearched ("dc:extent", Convert.ToInt32 (tokens [1])));
						break;
					case "TOTEM_INFO_TRACK_NUMBER":
						AddProperty (Beagle.Property.NewUnsearched ("fixme:tracknumber", Convert.ToInt32 (tokens [1])));
						break;
					case "TOTEM_INFO_HAS_VIDEO":
						break;
					case "TOTEM_INFO_VIDEO_WIDTH":
						AddProperty (Beagle.Property.NewUnsearched ("fixme:video:width", Convert.ToInt32 (tokens [1])));
						break;
					case "TOTEM_INFO_VIDEO_HEIGHT":
						AddProperty (Beagle.Property.NewUnsearched ("fixme:video:height", Convert.ToInt32 (tokens [1])));
						break;
					case "TOTEM_INFO_VIDEO_CODEC":
						AddProperty (Beagle.Property.NewKeyword ("fixme:video:codec", tokens [1]));
						break;
					case "TOTEM_INFO_FPS":
						AddProperty (Beagle.Property.NewUnsearched ("fixme:video:fps", Convert.ToInt32 (tokens [1])));
						break;
					case "TOTEM_INFO_VIDEO_BITRATE":
						AddProperty (Beagle.Property.NewUnsearched ("fixme:video:bitrate", Convert.ToInt32 (tokens [1])));
						break;
					case "TOTEM_INFO_HAS_AUDIO":
						break;
					case "TOTEM_INFO_AUDIO_BITRATE":
						AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:bitrate", Convert.ToInt32 (tokens [1])));
						break;
					case "TOTEM_INFO_AUDIO_CODEC":
						AddProperty (Beagle.Property.NewKeyword ("fixme:audio:codec", tokens [1]));
						break;
					case "TOTEM_INFO_AUDIO_SAMPLE_RATE":
						AddProperty (Beagle.Property.NewUnsearched ("fixme:audio:samplerate", Convert.ToInt32 (tokens [1])));
						break;
					case "TOTEM_INFO_AUDIO_CHANNELS":
						//FIXME this is very broken, needs fixing in Totem
						break;
					default:
						// Mismatching version of Totem with more information, possibly
						break;
				}
			}
			
			pout.Close ();
			pc.Close ();

			Finished ();
		}
예제 #26
0
		public static string ReadPasswordKDEWallet (string folder, string username)
		{
			if (String.IsNullOrEmpty (folder) || String.IsNullOrEmpty (username))
				throw new ArgumentException ("folder, username", "cannot be empty");

			// Get name of the local wallet
			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "localWallet" };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = false;
			pc.UseLangC = true;

			pc.Start ();
			string localWallet = null;
			using (StreamReader pout = new StreamReader (pc.StandardOutput))
				localWallet = pout.ReadLine ();
			pc.Close ();

			if (String.IsNullOrEmpty (localWallet) || localWallet == "-1")
				throw new ArgumentException ("kwalletd", "Unable to reach local KDE wallet");

			// Open local wallet
			pc = new SafeProcess ();
			pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "open", localWallet, "K" };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = false;
			pc.UseLangC = true;

			pc.Start ();
			string wallet_id = null;
			using (StreamReader pout = new StreamReader (pc.StandardOutput))
				wallet_id = pout.ReadLine ();
			pc.Close ();

			if (String.IsNullOrEmpty (wallet_id) || wallet_id == "-1")
				throw new ArgumentException ("kwalletd", "Unable to open local KDE wallet");

			// Read password from the given folder and for the given username
			pc = new SafeProcess ();
			pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "readPassword", wallet_id, folder, username };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = false;
			pc.UseLangC = true;

			pc.Start ();
			string password = null;
			using (StreamReader pout = new StreamReader (pc.StandardOutput))
				password = pout.ReadLine ();
			pc.Close ();

			if (String.IsNullOrEmpty (password))
				throw new ArgumentException ("kwalletd", "Unable to read password.");

			return password;
		}
예제 #27
0
		public void OpenFromUri (string uri)
                {
#if ENABLE_DESKTOP_LAUNCH || ENABLE_XDG_OPEN
			SafeProcess p = new SafeProcess ();

#  if ENABLE_DESKTOP_LAUNCH
			p.Arguments = new string[] { "desktop-launch", uri };
#  elif ENABLE_XDG_OPEN
			p.Arguments = new string[] { "xdg-open", uri };
#  endif

			try {
				p.Start ();
			} catch (Exception e) {
				Console.WriteLine ("Could not load handler for {0}: {1}", uri, e);
			}
#else			
			try {
				Gnome.Url.Show (uri);
			} catch (Exception e) {
				Console.WriteLine ("Could not load handler for {0}: {1}", uri, e);
			}
#endif
		}
예제 #28
0
		protected override bool PullPackageProperties ()
		{
			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string [] { "dpkg-deb", "-I", FileInfo.FullName};
			pc.RedirectStandardOutput = true;
			pc.UseLangC = true;
			
			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				return false;
			}
			
			StreamReader pout = new StreamReader (pc.StandardOutput);
			
			string str = null;
			string[] tokens = null;
			char[] splits = { ',', '|'};
			string[] list = null;

			while ((str = pout.ReadLine ()) != null) {
				tokens = str.Split (':');
				if (tokens.Length <= 1) 
					continue;

				switch (tokens[0].Trim ()) {
					
				case "Package":
					PackageName = tokens [1];
					break;
					
				case "Maintainer":
					Packager = tokens [1];
					break;
					
				case "Version":
					PackageVersion = tokens [1];
					break;
					
				case "Section":
					Category = tokens [1];
					break;
					
				case "Architecture":
					AddProperty (Beagle.Property.NewUnsearched ("fixme:arch", tokens [1]));
					break;
					
				case "Depends":
					list = tokens [1].Split (splits);
					foreach (string s in list)
						AddProperty (Beagle.Property.NewUnsearched ("fixme:depends", s));
					break;
					
				case "Recommends":
					list = tokens [1].Split (splits);
					foreach (string s in list)
						AddProperty (Beagle.Property.NewUnsearched ("fixme:recommend", s));
					break;

				case "Conflicts":
					list = tokens [1].Split (splits);
					foreach (string s in list)
						AddProperty (Beagle.Property.NewUnsearched ("fixme:conflict", s));
					break;
					
				case "Replaces":
					list = tokens [1].Split (splits);
					foreach (string s in list)
						AddProperty (Beagle.Property.NewUnsearched ("fixme:replaces", s));
					break;
					
				case "Provides":
					list = tokens [1].Split (splits);
					foreach (string s in list)
						AddProperty (Beagle.Property.NewUnsearched ("fixme:provides", s));
					break;
					
				case "Installed-Size":
					// Installed-Size is given in number of KBs
					AddProperty (Beagle.Property.NewUnsearched ("fixme:size", tokens [1] + "000"));
					break;
					
				case "Description":
					AppendText (tokens [1]);
					AppendStructuralBreak ();
					while ((str = pout.ReadLine ()) != null) {
						if(str.Trim () == ".")
							AppendStructuralBreak ();
						else
							AppendText (str);
					}
					break;
				}
			}

			pout.Close ();
			pc.Close ();
			return true;
		}
예제 #29
0
		public void SendInMail ()
		{
			SafeProcess p = new SafeProcess ();

			string uri;
			if (Hit.ParentUri != null)
				uri = Hit.EscapedParentUri;
			else
				uri = Hit.EscapedUri;

			p.Arguments = new string [] { "evolution", String.Format ("{0};forward=attached", uri) };

			try {
				p.Start () ;
			} catch (Exception e) {
				Console.WriteLine ("Error launching Evolution composer: " + e.Message);
			}
		}
예제 #30
0
		protected override void DoPull ()
		{
			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string [] { "rpm", "-qp", "--queryformat", text_queryformat, FileInfo.FullName };
			pc.RedirectStandardOutput = true;

			// Let rpm run for 90 seconds for text, max.
			pc.CpuLimit = 90;
			
			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				Error ();
				return;
			}

			StreamReader pout = new StreamReader (pc.StandardOutput);

			string s;
			while ((s = pout.ReadLine ()) != null) {
				if (s == "(none)")
					continue;
				AppendWord (s);
			}

			pout.Close ();
			pc.Close ();

			Finished ();
		}
예제 #31
0
		protected virtual void OnSendEmail (object o, EventArgs args)
		{
			string mail = null;
			SafeProcess process;
			
			if (contact ["PrimaryEmail"] != null)
				mail = contact ["PrimaryEmail"] as string;
			else if (contact ["SecondEmail"] != null)
				mail = contact ["SecondMail"] as string;
			else {
				MessageDialog dialog = new MessageDialog (
					null,
					DialogFlags.DestroyWithParent, 
					MessageType.Warning,
					ButtonsType.Ok, 
					Catalog.GetString ("Could not find a valid E-mail address!"));
				
				dialog.Run ();
				dialog.Destroy ();
				return;
			}
			
			process = new SafeProcess ();
			process.Arguments = new string [2];
			process.Arguments [0] = Thunderbird.ExecutableName;
			process.Arguments [1] = String.Format ("mailto:{0}", mail);
			process.Start ();
		}
예제 #32
0
		public void DoQuery (Query query, IQueryResult result, IQueryableChangeData data)
		{
			string search = null;
			foreach (QueryPart qp in query.Parts) {
				if (qp is QueryPart_Text) {
					search = ((QueryPart_Text) qp).Text;
					break;
				}
			}

			if (String.IsNullOrEmpty (search))
				return;

			SafeProcess pc = new SafeProcess ();
			// Double the max-hits since it is hard to tell locate to ignore
			// hidden files and directories; so we prune them later.
			// So if hidden files are returned first, you are doomed
			pc.Arguments = new string[] { "locate", "-P", "-e", "-l", (2 * query.MaxHits).ToString (), search };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = false;
			pc.UseLangC = true;

			try {
				pc.Start ();
			} catch (Beagle.Util.SafeProcessException e) {
				Log.Error (e, "Error while running 'locate -P -e -l {0} {1}'", (2 * query.MaxHits), search);
				return;
			}

			string match = null;
			ArrayList result_batch = new ArrayList ();
			const int MAX_QUEUED_HITS = 25;
			Hit hit;
			int count = 0;

			using (StreamReader pout = new StreamReader (pc.StandardOutput)) {
				while (count < query.MaxHits && ! pout.EndOfStream) {
					match = pout.ReadLine ();
					hit = PathToHit (match);
					if (hit == null)
						continue;

					result_batch.Add (hit);

					if (result_batch.Count >= MAX_QUEUED_HITS) {
						result.Add (result_batch);
						result_batch.Clear ();
					}
					count ++;
				}
			}

			result.Add (result_batch, count);

			pc.Close ();
		}
예제 #33
0
		public static void StorePasswordKDEWallet (string folder, string username, string password)
		{
			if (String.IsNullOrEmpty (folder) || String.IsNullOrEmpty (username) || String.IsNullOrEmpty (password))
				throw new ArgumentException ("folder, username or password", "cannot be empty");

			// Get name of the local wallet
			SafeProcess pc = new SafeProcess ();
			pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "localWallet" };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = false;
			pc.UseLangC = true;

			pc.Start ();
			string localWallet = null;
			using (StreamReader pout = new StreamReader (pc.StandardOutput))
				localWallet = pout.ReadLine ();
			pc.Close ();

			if (String.IsNullOrEmpty (localWallet) || localWallet == "-1")
				throw new ArgumentException ("kwalletd", "Local KDE Wallet is not found. Please run kwalletmanager to enable KDE Wallet.");

			// Open local wallet
			pc = new SafeProcess ();
			pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "open", localWallet, "K" };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = false;
			pc.UseLangC = true;

			pc.Start ();
			string wallet_id = null;
			using (StreamReader pout = new StreamReader (pc.StandardOutput))
				wallet_id = pout.ReadLine ();
			pc.Close ();

			if (String.IsNullOrEmpty (wallet_id) || wallet_id == "-1")
				throw new ArgumentException ("kwalletd", "Unable to open local KDE wallet");

			// Write given password for the given folder and username
			pc = new SafeProcess ();
			pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "writePassword", wallet_id, folder, username, password };
			pc.RedirectStandardOutput = true;
			pc.RedirectStandardError = false;
			pc.UseLangC = true;

			pc.Start ();
			string ret = null;
			using (StreamReader pout = new StreamReader (pc.StandardOutput))
				ret = pout.ReadLine ();
			pc.Close ();

			if (ret != "0")
				throw new ArgumentException ("kwalletd", "Unable to save password.");
		}