~ubuntu-branches/ubuntu/jaunty/beagle/jaunty-security

« back to all changes in this revision

Viewing changes to tools/Query.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
using System.Reflection;
32
32
using System.Threading;
33
33
using System.Text;
34
 
using System.Text.RegularExpressions;
35
34
using System.Runtime.InteropServices;
36
35
 
37
36
using GLib;
70
69
                                           (lastQueryTime - queryStartTime).TotalSeconds);
71
70
                }
72
71
 
73
 
                if (verbose && response.NumMatches >= 0)
74
 
                        Console.WriteLine ("Returned latest {0} results out of total {1} matches", response.Hits.Count, response.NumMatches);
 
72
                if (verbose) {
 
73
                        if (response.NumMatches >= 0)
 
74
                                Console.WriteLine ("Returned latest {0} results out of total {1} matches", response.Hits.Count, response.NumMatches);
 
75
                        else
 
76
                                Console.WriteLine ("Returned latest {0} results", response.Hits.Count);
 
77
                }
75
78
 
76
79
                if (! display_hits) {
77
80
                        count += response.Hits.Count;
178
181
                        "  --max-hits\t\tLimit number of search results per backend\n" +
179
182
                        "            \t\t(default 100)\n" +
180
183
                        "\n" +
181
 
                        "  --network <yes|no>\tQuery other beagle systems in the network specified in config (default no)\n" +
 
184
                        "  --domain <local|system|network|global|all> Specify query domain (default local + system)\n" +
182
185
                        "\n" +
183
186
                        "  --flood\t\tExecute the query over and over again.  Don't do that.\n" +
184
187
                        "  --listener\t\tExecute an index listener query.  Don't do that either.\n" +
194
197
                System.Environment.Exit (0);
195
198
        }
196
199
 
197
 
        private static void ReadBackendMappings ()
198
 
        {
199
 
                ArrayList assemblies = ReflectionFu.ScanEnvironmentForAssemblies ("BEAGLE_BACKEND_PATH", PathFinder.BackendDir);
200
 
 
201
 
                // Add BeagleDaemonLib if it hasn't already been added.
202
 
                bool found_daemon_lib = false;
203
 
                foreach (Assembly assembly in assemblies) {
204
 
                        if (assembly.GetName ().Name == "BeagleDaemonLib") {
205
 
                                found_daemon_lib = true;
206
 
                                break;
207
 
                        }
208
 
                }
209
 
 
210
 
                if (!found_daemon_lib) {
211
 
                        try {
212
 
                                assemblies.Add (Assembly.LoadFrom (Path.Combine (PathFinder.PkgLibDir, "BeagleDaemonLib.dll")));
213
 
                        } catch (FileNotFoundException) {
214
 
                                Console.WriteLine ("WARNING: Could not find backend list.");
215
 
                                Environment.Exit (1);
216
 
                        }
217
 
                }
218
 
 
219
 
                foreach (Assembly assembly in assemblies) {
220
 
                        foreach (Type type in ReflectionFu.GetTypesFromAssemblyAttribute (assembly, typeof (IQueryableTypesAttribute))) {
221
 
                                object[] attributes = type.GetCustomAttributes (false);
222
 
                                foreach (object attribute in attributes) {
223
 
                                        PropertyKeywordMapping mapping = attribute as PropertyKeywordMapping;
224
 
                                        if (mapping == null)
225
 
                                                continue;
226
 
                                        //Logger.Log.Debug (mapping.Keyword + " => " 
227
 
                                        //              + mapping.PropertyName + 
228
 
                                        //              + " is-keyword=" + mapping.IsKeyword + " (" 
229
 
                                        //              + mapping.Description + ") "
230
 
                                        //              + "(" + type.FullName + ")");
231
 
                                        PropertyKeywordFu.RegisterMapping (mapping);
232
 
                                }
233
 
                        }
234
 
                }
235
 
        }
236
 
 
237
200
        private static void OnClosed ()
238
201
        {
239
202
                if (flood)
284
247
 
285
248
                query = new Query ();
286
249
 
 
250
                QueryDomain domain = 0;
 
251
 
287
252
                // Parse args
288
253
                int i = 0;
289
254
                while (i < args.Length) {
314
279
                                keep_running = true;
315
280
                                break;
316
281
                        case "--keywords":
317
 
                                ReadBackendMappings ();
318
 
                                QueryDriver.ReadKeywordMappings ();
 
282
                                PropertyKeywordFu.ReadKeywordMappings ();
319
283
 
320
284
                                Console.WriteLine ("Supported query keywords are:");
321
285
 
322
286
                                foreach (string key in PropertyKeywordFu.Keys) {
323
 
                                        foreach (PropertyDetail prop in PropertyKeywordFu.Properties (key)) {
 
287
                                        foreach (QueryKeywordMapping mapping in PropertyKeywordFu.Properties (key)) {
324
288
                                                // Dont print properties without description; they confuse people
325
 
                                                if (string.IsNullOrEmpty (prop.Description))
 
289
                                                if (string.IsNullOrEmpty (mapping.Description))
326
290
                                                        continue;
327
 
                                                Console.WriteLine ("  {0,-20} for {1}", key, prop.Description);
 
291
                                                Console.WriteLine ("  {0,-20} for {1}", key, mapping.Description);
328
292
                                        }
329
293
                                }
330
294
 
331
295
                                System.Environment.Exit (0);
332
296
                                break;
333
297
 
334
 
                        case "--network":
 
298
                        case "--domain":
335
299
                                if (++i >= args.Length) PrintUsageAndExit ();
336
 
                                if (args [i].ToLower () == "yes")
337
 
                                        query.AddDomain (QueryDomain.Neighborhood);
 
300
                                switch (args [i].ToLower ()) {
 
301
                                case "local":
 
302
                                        domain |= QueryDomain.Local;
 
303
                                        break;
 
304
 
 
305
                                case "system":
 
306
                                        domain |= QueryDomain.System;
 
307
                                        break;
 
308
 
 
309
                                case "network":
 
310
                                        domain |= QueryDomain.Neighborhood;
 
311
                                        break;
 
312
 
 
313
                                case "global":
 
314
                                        domain |= QueryDomain.Global;
 
315
                                        break;
 
316
 
 
317
                                case "all":
 
318
                                        domain |= QueryDomain.All;
 
319
                                        break;
 
320
 
 
321
                                default:
 
322
                                        PrintUsageAndExit ();
 
323
                                        break;
 
324
                                }
338
325
                                break;
339
326
 
340
327
                        default:
350
337
                        ++i;
351
338
                }
352
339
 
 
340
                if (domain != 0)
 
341
                        query.QueryDomain = domain;
 
342
 
353
343
                if (listener) {
354
344
                        query.IsIndexListener = true;
355
345
                } else {
370
360
                main_loop.Run ();
371
361
        }
372
362
}
373