Oops, fix a broken part of the patch
[beagle.git] / tools / Info.cs
bloba7e71ec51cd4e06e090d269a4d6f54f80f05b786
1 //
2 // Info.cs
3 //
4 // Copyright (C) 2005 Novell, Inc.
5 // Copyright (C) 2006 Debajyoti Bera <dbera.web@gmail.com>
6 //
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in all
17 // copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 // SOFTWARE.
28 using System;
29 using System.Reflection;
31 using Beagle;
32 using Beagle.Daemon;
33 using Beagle.Util;
35 class InfoTool {
37 public static void PrintUsageAndExit ()
39 string usage =
40 "beagle-info: Statistics from the Beagle daemon.\n" +
41 "Web page: http://www.gnome.org/projects/beagle\n" +
42 "Copyright (C) 2004-2005 Novell, Inc.\n\n";
43 usage +=
44 "Usage: beagle-info <OPTIONS>\n\n" +
45 "Options:\n" +
46 " --daemon-version\t\tPrint the version of the running daemon.\n" +
47 " --status\t\t\tDisplay status of the running daemon.\n" +
48 " --index-info\t\t\tDisplay statistics of the Beagle indexes.\n" +
49 " --list-filters\t\tList the currently available filters.\n" +
50 " --help\t\t\tPrint this usage message.\n";
52 Console.WriteLine (usage);
54 System.Environment.Exit (0);
57 static int Main (string[] args)
59 if (args.Length == 0 || Array.IndexOf (args, "--help") > -1)
60 PrintUsageAndExit ();
62 if (Array.IndexOf (args, "--list-filters") > -1)
63 PrintFilterInformation ();
64 else
65 return PrintDaemonInformation (args);
67 return 0;
70 private static int PrintDaemonInformation (string[] args)
72 DaemonInformationRequest request = new DaemonInformationRequest ();
73 DaemonInformationResponse response;
75 try {
76 Console.WriteLine ("Sending begins at:" + DateTime.Now);
77 response = (DaemonInformationResponse) request.Send ();
78 Console.WriteLine ("Sending done at:" + DateTime.Now);
79 } catch (Beagle.ResponseMessageException) {
80 Console.WriteLine ("Could not connect to the daemon.");
81 return 1;
84 if (Array.IndexOf (args, "--daemon-version") > -1)
85 Console.WriteLine ("Daemon version: {0}", response.Version);
87 if (Array.IndexOf (args, "--status") > -1)
88 Console.Write (response.HumanReadableStatus);
90 if (Array.IndexOf (args, "--index-info") > -1) {
91 Console.WriteLine ("Index information:");
92 Console.WriteLine (response.IndexInformation);
95 if (Array.IndexOf (args, "--is-indexing") > -1)
96 Console.WriteLine ("Daemon indexing: {0}", response.IsIndexing);
98 return 0;
101 private static void PrintFilterInformation ()
103 ReflectionFu.ScanEnvironmentForAssemblies ("BEAGLE_FILTER_PATH", PathFinder.FilterDir, PrintFilterDetails);
106 static void PrintFilterDetails (Assembly assembly)
108 foreach (Type t in ReflectionFu.ScanAssemblyForClass (assembly, typeof (Filter))) {
109 Filter filter = null;
111 try {
112 filter = (Filter) Activator.CreateInstance (t);
113 } catch (Exception ex) {
114 Logger.Log.Error ("Caught exception while instantiating {0}", t);
115 Logger.Log.Error (ex);
118 if (filter == null)
119 continue;
121 string name;
123 if (t.FullName.StartsWith (t.Namespace))
124 name = t.FullName.Substring (t.Namespace.Length + 1);
125 else
126 name = t.FullName;
128 Console.WriteLine (name + " - Version " + filter.Version + " (" + assembly.Location + ")");
130 foreach (FilterFlavor flavor in filter.SupportedFlavors) {
131 if (flavor.MimeType != null)
132 Console.WriteLine (" - " + flavor.MimeType);
133 if (flavor.Extension != null)
134 Console.WriteLine (" - *" + flavor.Extension);
137 Console.WriteLine ();