4 // Copyright (C) 2005 Novell, Inc.
5 // Copyright (C) 2006 Debajyoti Bera <dbera.web@gmail.com>
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
31 using System
.Reflection
;
32 using System
.Collections
;
40 public static void PrintUsageAndExit ()
43 "beagle-info: Statistics from the Beagle daemon.\n" +
44 "Web page: http://www.gnome.org/projects/beagle\n" +
45 "Copyright (C) 2004-2005 Novell, Inc.\n\n";
47 "Usage: beagle-info <OPTIONS>\n\n" +
49 " --daemon-version\t\tPrint the version of the running daemon.\n" +
50 " --status\t\t\tDisplay status of the running daemon.\n" +
51 " --index-info\t\t\tDisplay statistics of the Beagle indexes.\n" +
52 " --list-backends\t\tList the currently available backends.\n" +
53 " --list-filters\t\tList the currently available filters.\n" +
54 " --list-static-indexes\t\tList the available static indexes.\n" +
55 " --help\t\t\tPrint this usage message.\n";
57 Console
.WriteLine (usage
);
59 System
.Environment
.Exit (0);
62 static int Main (string[] args
)
64 if (args
.Length
== 0 || Array
.IndexOf (args
, "--help") > -1)
67 if (Array
.IndexOf (args
, "--list-filters") > -1)
68 PrintFilterInformation ();
69 else if (Array
.IndexOf (args
, "--list-backends") > -1)
70 PrintBackendInformation ();
71 else if (Array
.IndexOf (args
, "--list-static-indexes") > -1)
72 PrintStaticIndexInformation ();
74 return PrintDaemonInformation (args
);
79 private static int PrintDaemonInformation (string[] args
)
81 DaemonInformationRequest request
= new DaemonInformationRequest ();
82 DaemonInformationResponse response
;
85 response
= (DaemonInformationResponse
) request
.Send ();
86 } catch (Beagle
.ResponseMessageException
) {
87 Console
.WriteLine ("Could not connect to the daemon.");
91 if (Array
.IndexOf (args
, "--daemon-version") > -1)
92 Console
.WriteLine ("Daemon version: {0}", response
.Version
);
94 if (Array
.IndexOf (args
, "--status") > -1)
95 Console
.Write (response
.HumanReadableStatus
);
97 if (Array
.IndexOf (args
, "--index-info") > -1) {
98 Console
.WriteLine ("Index information:");
99 Console
.WriteLine (response
.IndexInformation
);
102 if (Array
.IndexOf (args
, "--is-indexing") > -1)
103 Console
.WriteLine ("Daemon indexing: {0}", response
.IsIndexing
);
108 private static void PrintFilterInformation ()
110 ReflectionFu
.ScanEnvironmentForAssemblies ("BEAGLE_FILTER_PATH", PathFinder
.FilterDir
, PrintFilterDetails
);
113 static void PrintFilterDetails (Assembly assembly
)
115 StringBuilder sb
= new StringBuilder ();
116 foreach (Type t
in ReflectionFu
.ScanAssemblyForClass (assembly
, typeof (Filter
))) {
117 Filter filter
= null;
120 filter
= (Filter
) Activator
.CreateInstance (t
);
121 } catch (Exception ex
) {
122 Logger
.Log
.Error ("Caught exception while instantiating {0}", t
);
123 Logger
.Log
.Error (ex
);
131 if (t
.FullName
.StartsWith (t
.Namespace
))
132 name
= t
.FullName
.Substring (t
.Namespace
.Length
+ 1);
137 sb
.Append (name
+ " - Version " + filter
.Version
+ " (" + assembly
.Location
+ ")\n");
138 bool has_filter
= false;
140 foreach (FilterFlavor flavor
in filter
.SupportedFlavors
) {
141 if (flavor
.MimeType
!= null && (! flavor
.MimeType
.StartsWith ("beagle"))) {
142 sb
.Append (" - " + flavor
.MimeType
+ "\n");
145 if (flavor
.Extension
!= null) {
146 sb
.Append (" - *" + flavor
.Extension
+ "\n");
152 Console
.WriteLine (sb
.ToString ());
156 private static void PrintBackendInformation ()
158 ArrayList assemblies
= ReflectionFu
.ScanEnvironmentForAssemblies ("BEAGLE_BACKEND_PATH", PathFinder
.BackendDir
);
160 // Add BeagleDaemonLib if it hasn't already been added.
161 bool found_daemon_lib
= false;
162 foreach (Assembly assembly
in assemblies
) {
163 if (assembly
.GetName ().Name
== "BeagleDaemonLib") {
164 found_daemon_lib
= true;
169 if (!found_daemon_lib
) {
171 assemblies
.Add (Assembly
.LoadFrom (Path
.Combine (PathFinder
.PkgLibDir
, "BeagleDaemonLib.dll")));
172 } catch (FileNotFoundException
) {
173 Console
.WriteLine ("WARNING: Could not find backend list.");
174 Environment
.Exit (1);
178 foreach (Assembly assembly
in assemblies
) {
179 foreach (Type type
in ReflectionFu
.ScanAssemblyForInterface (assembly
, typeof (Beagle
.Daemon
.IQueryable
))) {
180 foreach (Beagle
.Daemon
.QueryableFlavor flavor
in ReflectionFu
.ScanTypeForAttribute (type
, typeof (Beagle
.Daemon
.QueryableFlavor
))) {
181 Console
.WriteLine ("{0,-20} (" + assembly
.Location
+ ")", flavor
.Name
);
187 private static void PrintStaticIndexInformation ()
190 foreach (DirectoryInfo index_dir
in new DirectoryInfo (PathFinder
.SystemIndexesDir
).GetDirectories ())
191 Console
.WriteLine ("[System index] " + index_dir
.Name
+ " (" + index_dir
.FullName
+ ")");
192 } catch (DirectoryNotFoundException
) { }
194 foreach (string index_path
in Conf
.Daemon
.StaticQueryables
)
195 Console
.WriteLine ("[User index] " + index_path
);