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-2006 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 " --is-indexing\t\t\tDisplay whether the indexer is currently active.\n" +
53 " --all-info\t\t\tAll of the above information.\n" +
54 " --list-backends\t\tList the currently available backends.\n" +
55 " --list-filters\t\tList the currently available filters.\n" +
56 " --list-static-indexes\t\tList the available static indexes.\n" +
57 " --help\t\t\tPrint this usage message.\n";
59 Console
.WriteLine (usage
);
61 System
.Environment
.Exit (0);
64 static int Main (string[] args
)
66 if (args
.Length
== 0 || Array
.IndexOf (args
, "--help") > -1)
69 if (Array
.IndexOf (args
, "--list-filters") > -1)
70 PrintFilterInformation ();
71 else if (Array
.IndexOf (args
, "--list-backends") > -1)
72 PrintBackendInformation ();
73 else if (Array
.IndexOf (args
, "--list-static-indexes") > -1)
74 PrintStaticIndexInformation ();
76 return PrintDaemonInformation (args
);
81 private static int PrintDaemonInformation (string[] args
)
83 DaemonInformationRequest request
= new DaemonInformationRequest ();
84 DaemonInformationResponse response
;
86 bool get_version
= false;
87 bool get_sched_info
= false;
88 bool get_index_status
= false;
89 bool get_is_indexing
= false;
91 get_version
= (Array
.IndexOf (args
, "--daemon-version") > -1);
92 get_sched_info
= (Array
.IndexOf (args
, "--status") > -1);
93 get_index_status
= (Array
.IndexOf (args
, "--index-info") > -1);
94 get_is_indexing
= (Array
.IndexOf (args
, "--is-indexing") > -1);
96 if (Array
.IndexOf (args
, "--all-info") > -1)
97 get_version
= get_sched_info
= get_index_status
= get_is_indexing
= true;
100 response
= (DaemonInformationResponse
) request
.Send ();
101 } catch (Beagle
.ResponseMessageException
) {
102 Console
.WriteLine ("Could not connect to the daemon.");
107 Console
.WriteLine ("Daemon version: {0}", response
.Version
);
110 Console
.Write (response
.HumanReadableStatus
);
112 if (get_index_status
) {
113 Console
.WriteLine ("Index information:");
114 Console
.WriteLine (response
.IndexInformation
);
118 Console
.WriteLine ("Daemon indexing: {0}", response
.IsIndexing
);
123 private static void PrintFilterInformation ()
125 ReflectionFu
.ScanEnvironmentForAssemblies ("BEAGLE_FILTER_PATH", PathFinder
.FilterDir
, PrintFilterDetails
);
128 static void PrintFilterDetails (Assembly assembly
)
130 StringBuilder sb
= new StringBuilder ();
131 foreach (Type t
in ReflectionFu
.GetTypesFromAssemblyAttribute (assembly
, typeof (FilterTypesAttribute
))) {
132 Filter filter
= null;
135 filter
= (Filter
) Activator
.CreateInstance (t
);
136 } catch (Exception ex
) {
137 Logger
.Log
.Error (ex
, "Caught exception while instantiating {0}", t
);
145 if (t
.FullName
.StartsWith (t
.Namespace
))
146 name
= t
.FullName
.Substring (t
.Namespace
.Length
+ 1);
151 sb
.Append (name
+ " - Version " + filter
.Version
+ " (" + assembly
.Location
+ ")\n");
152 bool has_filter
= false;
154 foreach (FilterFlavor flavor
in filter
.SupportedFlavors
) {
155 if (flavor
.MimeType
!= null && (! flavor
.MimeType
.StartsWith ("beagle"))) {
156 sb
.Append (" - " + flavor
.MimeType
+ "\n");
159 if (flavor
.Extension
!= null) {
160 sb
.Append (" - *" + flavor
.Extension
+ "\n");
166 Console
.WriteLine (sb
.ToString ());
170 private static void PrintBackendInformation ()
172 ArrayList assemblies
= ReflectionFu
.ScanEnvironmentForAssemblies ("BEAGLE_BACKEND_PATH", PathFinder
.BackendDir
);
174 // Add BeagleDaemonLib if it hasn't already been added.
175 bool found_daemon_lib
= false;
176 foreach (Assembly assembly
in assemblies
) {
177 if (assembly
.GetName ().Name
== "BeagleDaemonLib") {
178 found_daemon_lib
= true;
183 if (!found_daemon_lib
) {
185 assemblies
.Add (Assembly
.LoadFrom (Path
.Combine (PathFinder
.PkgLibDir
, "BeagleDaemonLib.dll")));
186 } catch (FileNotFoundException
) {
187 Console
.WriteLine ("WARNING: Could not find backend list.");
188 Environment
.Exit (1);
192 foreach (Assembly assembly
in assemblies
) {
193 foreach (Type type
in ReflectionFu
.GetTypesFromAssemblyAttribute (assembly
, typeof (IQueryableTypesAttribute
))) {
194 foreach (Beagle
.Daemon
.QueryableFlavor flavor
in ReflectionFu
.ScanTypeForAttribute (type
, typeof (Beagle
.Daemon
.QueryableFlavor
))) {
195 Console
.WriteLine ("{0,-20} (" + assembly
.Location
+ ")", flavor
.Name
);
201 private static void PrintStaticIndexInformation ()
204 foreach (DirectoryInfo index_dir
in new DirectoryInfo (PathFinder
.SystemIndexesDir
).GetDirectories ())
205 Console
.WriteLine ("[System index] " + index_dir
.Name
+ " (" + index_dir
.FullName
+ ")");
206 } catch (DirectoryNotFoundException
) { }
208 foreach (string index_path
in Conf
.Daemon
.StaticQueryables
)
209 Console
.WriteLine ("[User index] " + index_path
);