Ejemplo n.º 1
0
    public static void PrintUsageAndExit()
    {
        VersionFu.PrintHeader();

        string usage =
            "Usage: beagrep-query [OPTIONS] <query string>\n\n" +
            "Options:\n" +
            "  --verbose\t\tPrint detailed information about each hit.\n" +
            "  --cache\t\tShow the entire cached text instead of a snippet\n" +
            "         \t\tshowing the matches, requires --verbose.\n" +
            "         \t\tFor large documents this will produce extremely large output,\n" +
            "         \t\tso use this with uri queries or queries returning only a few results\n" +
            "         \t\tNot recommended for live-queries or stats-only queries.\n" +
            "  --keywords\t\tLists the keywords allowed in 'query string'.\n" +
            "            \t\tKeyword queries can be specified as keywordname:value e.g. ext:jpg\n" +
            "  --stats-only\t\tOnly display statistics about the query, not\n" +
            "              \t\tthe actual results.\n" +
            "  --max-hits\t\tLimit number of search results per backend\n" +
            "            \t\t(default 100)\n" +
            "\n" +
            "\n" +
            "  --help\t\tPrint this usage message.\n" +
            "  --version\t\tPrint version information.\n" +
            "\n" +
            "Query string supports an advanced query syntax.\n" +
            "For details of the query syntax, please see http://beagrep-project.org/Searching_Data\n" +
            "Note: Quotes (\" or \') need to be shell escaped if used.\n";

        Console.WriteLine(usage);

        System.Environment.Exit(0);
    }
Ejemplo n.º 2
0
    static int Main(string[] args)
    {
        if (args.Length == 0 || Array.IndexOf(args, "--help") > -1)
        {
            PrintUsageAndExit();
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            return(0);
        }

        if (Array.IndexOf(args, "--list-filters") > -1)
        {
            PrintFilterInformation();
        }
        else if (Array.IndexOf(args, "--list-backends") > -1)
        {
            PrintBackendInformation();
        }
        else if (Array.IndexOf(args, "--list-static-indexes") > -1)
        {
            PrintStaticIndexInformation();
        }
        else
        {
            return(PrintDaemonInformation(args));
        }

        return(0);
    }
Ejemplo n.º 3
0
    public static int Main(string[] args)
    {
        if (Array.IndexOf(args, "--help") > -1)
        {
            VersionFu.PrintHeader();
            return(0);
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            return(0);
        }

        ShutdownRequest request = new ShutdownRequest();

        try {
            request.Send();
        } catch {
            Console.WriteLine("ERROR: The Beagle daemon does not appear to be running");
            return(1);
        }

        return(0);
    }
Ejemplo n.º 4
0
        private static void PrintUsage()
        {
            VersionFu.PrintHeader();

            string usage =
                "Usage: beagrepd [OPTIONS]\n\n" +
                "Options:\n" +
                "  --foreground, --fg\tRun the daemon in the foreground.\n" +
                "  --background, --bg\tRun the daemon in the background.\n" +
                "  --backend\t\tConfigure which backends to use.  Specifically:\n" +
                "    --backend <name>\tOnly start backend 'name'\n" +
                "    --backend +<name>\tAdditionally start backend 'name'\n" +
                "    --backend -<name>\tDisable backend 'name'\n" +
                "  --replace\t\tReplace a running daemon with a new instance.\n" +
                "  --list-backends\tList all the available backends.\n" +
                "  --add-static-backend\tAdd a static backend by path.\n" +
                "  --help\t\tPrint this usage message.\n" +
                "  --version\t\tPrint version information.\n" +
                "\n" +
                "Advanced options:\n" +
                "  --debug\t\tWrite out debugging information.\n" +
                "  --mono-debug\t\tShow mono related debugging information.\n" +
                "  --debug-memory\tWrite out debugging information about memory use.\n" +
                "  --indexing-test-mode\tRun in foreground, and exit when fully indexed.\n" +
                "  --indexing-delay <t>\tWait 't' seconds before indexing.  (Default 60 seconds)\n" +
                "  --disable-scheduler\tDisable the use of the scheduler.\n" +
                "  --disable-text-cache\tDisable the use of the text cache used to provide snippets.\n";

            Console.WriteLine(usage);
        }
Ejemplo n.º 5
0
        /////////////////////////////////////////////////////////////////

        static void PrintUsage()
        {
            VersionFu.PrintHeader();

            string usage =
                "Usage: beagrep-build-index [OPTIONS] --target <index_path> <path> [path]\n\n" +

                "** WARNING **\n" +
                "beagrep-build-index will *delete all existing data* within the target\n" +
                "directory.  Ensure that the target path is set correctly before running.\n\n" +

                "Options:\n" +
                "  --source [name]\t\tThe index's source name.  Defaults to the target directory name\n" +
                // FIXME: remap doesnt seem to be implemented !
                // Implementing remap might some fixes to --enable-deletion, see IndexWorker
                //"  --remap [path1:path2]\t\tRemap data paths to fit target. \n" +
                "  --tag [tag]\t\t\tTag index data for identification.\n" +
                "  --recursive\t\t\tCrawl source path recursivly.\n" +
                "  --enable-deletion\t\tRemove deleted files and directories from index.\n" +
                "                   \t\tIndex should be created and always updated with this option.\n" +
                "  --enable-text-cache\t\tBuild text-cache of documents used for snippets.\n" +
                "  --disable-directories\t\tDon't add directories to the index.\n" +
                "  --deny-directory-pattern\t\tKeep any directory and files under it matching this pattern from being indexed.\n" +
                "  --disable-filtering\t\tDisable all filtering of files. Only index attributes.\n" +
                "  --allow-pattern [pattern]\tOnly allow files that match the pattern to be indexed.\n" +
                "  --deny-pattern [pattern]\tKeep any files that match the pattern from being indexed.\n" +
                "  --disable-restart\t\tDon't restart when memory usage gets above a certain threshold.\n" +
                "  --disable-on-battery\t\tDisable indexer while on battery power.\n";

            Console.WriteLine(usage);
            Environment.Exit(0);
        }
Ejemplo n.º 6
0
        private static string ParseArgs(String[] args)
        {
            int    i     = 0;
            string query = String.Empty;

            while (i < args.Length)
            {
                switch (args [i])
                {
                case "--help":
                case "--usage":
                    PrintUsageAndExit();
                    return(null);

                case "--version":
                    VersionFu.PrintVersion();
                    Environment.Exit(0);
                    break;

                case "--icon":
                    icon_enabled = true;
                    break;

                case "--search-docs":
                    docs_enabled = true;
                    break;

                // Ignore session management
                case "--sm-config-prefix":
                case "--sm-client-id":
                case "--screen":
                    // These all take an argument, so
                    // increment i
                    i++;
                    break;

                default:
                    if (args [i].Length < 2 || args [i].Substring(0, 2) != "--")
                    {
                        if (query.Length != 0)
                        {
                            query += " ";
                        }
                        query += args [i];
                    }
                    break;
                }

                i++;
            }

            return(query);
        }
Ejemplo n.º 7
0
        private static void PrintUsageAndExit()
        {
            VersionFu.PrintHeader();

            Console.WriteLine("USAGE: beagle-imlogviewer --client <CLIENT> [OPTIONS] <log file or directory>\n" +
                              "Options:\n" +
                              "  --client\t\t\tClient that the log belongs to (e.g. Pidgin).\n" +
                              "  --highlight-search\t\tWords to highlight in the buffer.\n" +
                              "  --search\t\t\tSearch query to filter hits on.\n" +
                              "  --help\t\t\tPrint this usage message.\n" +
                              "  --version\t\t\tPrint version information.\n");

            Environment.Exit(0);
        }
Ejemplo n.º 8
0
        public static void PrintUsageAndExit()
        {
            VersionFu.PrintHeader();

            string usage =
                "Usage: beagle-search [OPTIONS] [<query string>]\n\n" +
                "Options:\n" +
                "  --icon\t\t\tAdd an icon to the notification area rather than opening a search window.\n" +
                "  --search-docs\t\t\tAlso search the system-wide documentation index.\n" +
                "  --help\t\t\tPrint this usage message.\n" +
                "  --version\t\t\tPrint version information.\n";

            Console.WriteLine(usage);

            System.Environment.Exit(0);
        }
Ejemplo n.º 9
0
    private static void PrintUsage()
    {
        VersionFu.PrintHeader();

        string usage =
            "Usage: beagrep-removable-index --indexdir INDEXDIR --mount DIR\n" +
            "       beagrep-removable-index --indexdir INDEXDIR --unmount DIR\n" +
            "Options:\n" +
            "  --indexdir DIR\tSpecify the path to the index directory.\n" +
            "  --mount DIR \tTell beagrepd to load a removable index from the given directory.\n" +
            "  --umount DIR\tTell beagrepd to unload a removable index from the given directory.\n" +
            "               \tGive full path to the directory in the above options.\n\n" +
            "  --help\t\tPrint this usage message.\n" +
            "  --version\t\tPrint version information.\n";

        Console.WriteLine(usage);
    }
Ejemplo n.º 10
0
    static void PrintUsage()
    {
        VersionFu.PrintHeader ();

        Console.WriteLine ("Usage: beagle-extract-content [OPTIONS] file [file ...]");
        Console.WriteLine ();
        Console.WriteLine ("Options:");
        Console.WriteLine ("  --debug\t\t\tPrint debug info to the console");
        Console.WriteLine ("  --tokenize\t\t\tTokenize the text before printing");
        Console.WriteLine ("  --analyze\t\t\tAnalyze the text before printing.\n\t\t\t\tThis will output exactly the words, separated by whitespace, that go into beagle index.");
        Console.WriteLine ("  --show-generated\t\tShow filtering information for items created by filters");
        Console.WriteLine ("  --mimetype=<mime_type>\tUse filter for mime_type");
        Console.WriteLine ("  --outfile=<filename>\t\tOutput file name");
        Console.WriteLine ("  --help\t\t\tShow this message");
        Console.WriteLine ("  --version\t\t\tPrint version information");
        Console.WriteLine ();
    }
Ejemplo n.º 11
0
    public static void PrintUsageAndExit()
    {
        VersionFu.PrintHeader();

        string usage =
            "Usage: beagle-settings-qt [OPTIONS]\n\n" +
            "Options:\n" +
            "--general    : Open the page with general options.(default)\n" +
            "--indexing   : Open the page with indexing specific options.\n" +
            "--backends   : Open the page with a list of backends to choose.\n" +
            "--networking : Open the page with networking related options.\n\n" +
            "--google     : OPen the page with google backend specific options.\n\n";

        Console.WriteLine(usage);

        System.Environment.Exit(0);
    }
Ejemplo n.º 12
0
    static void PrintUsage()
    {
        VersionFu.PrintHeader();

        string usage =
            "Usage: beagle-index-url <OPTIONS>\n\n" +
            "Options:\n" +
            "  --url URL\t\tURL for the web page being indexed.\n" +
            "  --title TITLE\t\tTitle for the web page.\n" +
            "  --sourcefile PATH\tFile containing content to index.\n" +
            "\t\t\tIf not set, content is read from STDIN.\n" +
            "  --deletesourcefile\tDelete file passed to --sourcefile after index.\n" +
            "  --help\t\tPrint this usage message.\n" +
            "  --version\t\tPrint version information.\n";

        Console.WriteLine(usage);
    }
Ejemplo n.º 13
0
    private static void PrintUsageAndExit()
    {
        VersionFu.PrintHeader();

        string usage =
            "Usage: \n" +
            "     beagle-config [OPTIONS]\n" +
            " * to list sections:\n" +
            "     beagle-config --list-sections\n" +
            " * to list options in a section:\n" +
            "     beagle-config SECTION\n" +
            " * to view current values of an option:\n" +
            "     beagle-config SECTION SECTIONOPTION\n" +
            " * to change values of a boolean or a string options:\n" +
            "     beagle-config SECTION SECTIONOPTION VALUE\n" +
            " * to add values to a list option:\n" +
            "     beagle-config SECTION SECTIONOPTION PARAMS\n" +
            " * to remove a value from a list option:\n" +
            "     beagle-config SECTION SECTIONOPTION - PARAMS\n\n" +
            "Options:\n" +
            "  --list-sections\t\tList the available sections.\n" +
            "  --beagled-reload-config\tAsk the beagle daemon to reload\n" +
            "                         \tthe configuration file.\n" +
            "  --list-backends\t\tList the available backends.\n" +
            "\n" +
            "  Xml based operations:\n" +
            "  The following two methods can be used by non-C# programs to\n" +
            "  read and set config options.\n" +
            "  --write-xml SECTION\t\tPrint the section in xml format.\n" +
            "                     \t\tSuitable for parsing by other programs.\n" +
            "  --read-xml SECTION\t\tReads the xml of a section from stdin.\n" +
            "                    \t\tSuitable for setting options by other programs.\n" +
            "  In case of any error, the following error codes are returned:\n" +
            "     1 : Bad section name\n" +
            "     2 : Invalid xml\n" +
            "     3 : Xml does not correspond to the section name\n" +
            "\n" +
            "  --help\t\t\tPrint this usage message.\n" +
            "  --version\t\t\tPrint version information.\n\n";

        Console.WriteLine(usage);

        System.Environment.Exit(0);
    }
Ejemplo n.º 14
0
    public static void PrintUsageAndExit()
    {
        VersionFu.PrintHeader();

        string usage =
            "Usage: beagle-info <OPTIONS>\n\n" +
            "Options:\n" +
            "  --daemon-version\t\tPrint the version of the running daemon.\n" +
            "  --status\t\t\tDisplay status of the running daemon.\n" +
            "  --index-info\t\t\tDisplay statistics of the Beagle indexes.\n" +
            "  --is-indexing\t\t\tDisplay whether the indexer is currently active.\n" +
            "  --all-info\t\t\tAll of the above information.\n" +
            "  --list-backends\t\tList the currently available backends.\n" +
            "  --list-filters\t\tList the currently available filters.\n" +
            "  --list-static-indexes\t\tList the available static indexes.\n" +
            "  --help\t\t\tPrint this usage message.\n" +
            "  --version\t\t\tPrint version information.\n";

        Console.WriteLine(usage);

        System.Environment.Exit(0);
    }
Ejemplo n.º 15
0
    public static void PrintUsageAndExit()
    {
        VersionFu.PrintHeader();

        string usage =
            "Usage: beagle-query [OPTIONS] <query string>\n\n" +
            "Options:\n" +
            "  --verbose\t\tPrint detailed information about each hit.\n" +
            "  --cache\t\tShow the entire cached text instead of a snippet\n" +
            "         \t\tshowing the matches, requires --verbose.\n" +
            "         \t\tFor large documents this will produce extremely large output,\n" +
            "         \t\tso use this with uri queries or queries returning only a few results\n" +
            "         \t\tNot recommended for live-queries or stats-only queries.\n" +
            "  --keywords\t\tLists the keywords allowed in 'query string'.\n" +
            "            \t\tKeyword queries can be specified as keywordname:value e.g. ext:jpg\n" +
            "  --live-query\t\tRun continuously, printing notifications if a\n" +
            "              \t\tquery changes.\n" +
            "  --stats-only\t\tOnly display statistics about the query, not\n" +
            "              \t\tthe actual results.\n" +
            "  --max-hits\t\tLimit number of search results per backend\n" +
            "            \t\t(default 100)\n" +
            "  --raw-uri\t\tDisplay the actual (unescaped) uri used internally.\n" +
            "           \t\tOnly use this form of the uri in uri queries.\n" +
            "\n" +
            "  --domain <local|system|network|global|all> Specify query domain (default local + system)\n" +
            "\n" +
            "  --flood\t\tExecute the query over and over again.  Don't do that.\n" +
            "  --listener\t\tExecute an index listener query.  Don't do that either.\n" +
            "  --help\t\tPrint this usage message.\n" +
            "  --version\t\tPrint version information.\n" +
            "\n" +
            "Query string supports an advanced query syntax.\n" +
            "For details of the query syntax, please see http://beagle-project.org/Searching_Data\n" +
            "Note: Quotes (\" or \') need to be shell escaped if used.\n";

        Console.WriteLine(usage);

        System.Environment.Exit(0);
    }
Ejemplo n.º 16
0
    public static void Main(string[] args)
    {
        if (Array.IndexOf(args, "--help") > -1)
        {
            PrintUsageAndExit();
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            // Console.WriteLine (Qt.QT_VERSION_STR); // Uncomment when does not crash
            Environment.Exit(0);
        }

        // FIXME: Cant seem to pass the args to Qt!
        new QApplication(args);

        MainForm mf = new MainForm(args);

        mf.Show();

        QApplication.Exec();
    }
Ejemplo n.º 17
0
    public static void Main(string[] args)
    {
        // Initialize GObject type system
        g_type_init();

        string index_dir  = null;
        string target_dir = null;
        bool   mount      = false;

        int i = 0;

        while (i < args.Length)
        {
            string arg = args [i];
            ++i;
            string next_arg = i < args.Length ? args [i] : null;

            switch (arg)
            {
            case "-h":
            case "--help":
                PrintUsage();
                Environment.Exit(0);
                break;

            case "--indexdir":
                if (next_arg != null)
                {
                    index_dir = next_arg;
                }
                ++i;
                break;

            case "--mount":
                if (next_arg != null)
                {
                    target_dir = next_arg;
                    mount      = true;
                }
                ++i;
                break;

            case "--unmount":
                if (next_arg != null)
                {
                    target_dir = next_arg;
                    mount      = false;
                }
                ++i;
                break;

            case "--version":
                VersionFu.PrintVersion();
                Environment.Exit(0);
                break;

            default:
                PrintUsage();
                Environment.Exit(1);
                break;
            }
        }

        if (target_dir == null || index_dir == null)
        {
            PrintUsage();
            Environment.Exit(1);
        }

        if (mount)
        {
            MountRemovableIndex(index_dir, target_dir);
        }
        else
        {
            UnmountRemovableIndex(index_dir, target_dir);
        }
    }
Ejemplo n.º 18
0
        public static void DoMain(string[] args)
        {
            SystemInformation.InternalCallInitializer.Init();
            SystemInformation.SetProcessName("beagrepd");

            // Process the command-line arguments
            bool arg_debug        = false;
            bool arg_debug_memory = false;
            bool arg_fg           = false;

            int i = 0;

            while (i < args.Length)
            {
                string arg = args [i];
                ++i;
                string next_arg = i < args.Length ? args [i] : null;

                switch (arg)
                {
                case "-h":
                case "--help":
                    PrintUsage();
                    Environment.Exit(0);
                    break;

                case "--mdb":
                case "--mono-debug":
                    // Silently ignore these arguments: they get handled
                    // in the wrapper script.
                    break;

                case "--list-backends":
                    Console.WriteLine("Current available backends:");
                    Console.Write(QueryDriver.ListBackends());
                    Environment.Exit(0);
                    break;

                case "--fg":
                case "--foreground":
                    arg_fg = true;
                    break;

                case "--bg":
                case "--background":
                    arg_fg = false;
                    break;

                case "--replace":
                    arg_replace = true;
                    break;

                case "--debug":
                    arg_debug = true;
                    break;

                case "--heap-shot":
                    arg_heap_shot    = true;
                    arg_debug        = true;
                    arg_debug_memory = true;
                    break;

                case "--no-snapshots":
                case "--no-snapshot":
                    arg_heap_shot_snapshots = false;
                    break;

                case "--heap-buddy":
                case "--debug-memory":
                    arg_debug        = true;
                    arg_debug_memory = true;
                    break;

                case "--indexing-test-mode":
                    arg_indexing_test_mode = true;
                    arg_fg = true;
                    break;

                case "--backend":
                    if (next_arg == null)
                    {
                        Console.WriteLine("--backend requires a backend name");
                        Environment.Exit(1);
                        break;
                    }

                    if (next_arg.StartsWith("--"))
                    {
                        Console.WriteLine("--backend requires a backend name. Invalid name '{0}'", next_arg);
                        Environment.Exit(1);
                        break;
                    }

                    if (next_arg [0] != '+' && next_arg [0] != '-')
                    {
                        QueryDriver.OnlyAllow(next_arg);
                    }
                    else
                    {
                        if (next_arg [0] == '+')
                        {
                            QueryDriver.Allow(next_arg.Substring(1));
                        }
                        else
                        {
                            QueryDriver.Deny(next_arg.Substring(1));
                        }
                    }

                    ++i;                     // we used next_arg
                    break;

                case "--add-static-backend":
                    if (next_arg != null)
                    {
                        QueryDriver.AddStaticQueryable(next_arg);
                    }
                    ++i;
                    break;

                case "--disable-scheduler":
                    arg_disable_scheduler = true;
                    break;

                case "--indexing-delay":
                    if (next_arg != null)
                    {
                        try {
                            QueryDriver.IndexingDelay = Int32.Parse(next_arg);
                        } catch {
                            Console.WriteLine("'{0}' is not a valid number of seconds", next_arg);
                            Environment.Exit(1);
                        }
                    }

                    ++i;
                    break;

                case "--autostarted":
                    // FIXME: This option is deprecated and will be removed in a future release.
                    break;

                case "--disable-text-cache":
                    disable_textcache = true;
                    break;

                case "--version":
                    VersionFu.PrintVersion();
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Unknown argument '{0}'", arg);
                    Environment.Exit(1);
                    break;
                }
            }

            if (Environment.GetEnvironmentVariable("SABAYON_SESSION_RUNNING") == "yes")
            {
                Console.WriteLine("Beagrep is running underneath Sabayon, exiting.");
                Environment.Exit(0);
            }

            if (arg_indexing_test_mode)
            {
                LuceneQueryable.OptimizeRightAway = true;
            }

            // Bail out if we are trying to run as root
            if (Environment.UserName == "root" && Environment.GetEnvironmentVariable("SUDO_USER") != null)
            {
                Console.WriteLine("You appear to be running beagrep using sudo.  This can cause problems with");
                Console.WriteLine("permissions in your .beagrep and .wapi directories if you later try to run");
                Console.WriteLine("as an unprivileged user.  If you need to run beagrep as root, please use");
                Console.WriteLine("'su -c' instead.");
                Environment.Exit(-1);
            }

            if (Environment.UserName == "root" && !Conf.Daemon.GetOption(Conf.Names.AllowRoot, false))
            {
                Console.WriteLine("You can not run beagrep as root.  Beagrep is designed to run from your own");
                Console.WriteLine("user account.  If you want to create multiuser or system-wide indexes, use");
                Console.WriteLine("the beagrep-build-index tool.");
                Console.WriteLine();
                Console.WriteLine("You can override this setting using the beagrep-config or beagrep-settings tools.");
                Environment.Exit(-1);
            }

            try {
                string tmp = PathFinder.HomeDir;
            } catch (Exception e) {
                Console.WriteLine("Unable to start the daemon: {0}", e.Message);
                Environment.Exit(-1);
            }

            MainLoopThread = Thread.CurrentThread;

            // FIXME: We always turn on full debugging output!  We are still
            // debugging this code, after all...
            // arg_debug ? LogLevel.Debug : LogLevel.Warn

            Log.Initialize(PathFinder.LogDir, "Beagrep", LogLevel.Debug, arg_fg);
            Log.Always("Starting Beagrep Daemon (version {0})", ExternalStringsHack.Version);
            Log.Always("Running on {0}", SystemInformation.MonoRuntimeVersion);
            Log.Always("Command Line: {0}",
                       Environment.CommandLine != null ? Environment.CommandLine : "(null)");

            if (!ExtendedAttribute.Supported)
            {
                Logger.Log.Warn("Extended attributes are not supported on this filesystem. " +
                                "Performance will suffer as a result.");
            }

            if (disable_textcache)
            {
                Log.Warn("Running with text-cache disabled!");
                Log.Warn("*** Snippets will not be returned for documents indexed in this session.");
            }

            // Check if global configuration files are installed
            if (!Conf.CheckGlobalConfig())
            {
                Console.WriteLine("Global configuration files not found in '{0}'", PathFinder.ConfigDataDir);
                Environment.Exit(-1);
            }

            // Start our memory-logging thread
            if (arg_debug_memory)
            {
                ExceptionHandlingThread.Start(new ThreadStart(LogMemoryUsage));
            }

            // Do BEAGREP_EXERCISE_THE_DOG_HARDER-related processing.
            ExerciseTheDogHarder();

            // Initialize GObject type system
            g_type_init();


            // Lower our CPU priority
            SystemPriorities.Renice(7);

            QueryDriver.Init();
            Server.Init();

#if MONO_1_9
            Shutdown.SetupSignalHandlers(new Shutdown.SignalHandler(HandleSignal));
#else
            SetupSignalHandlers();
#endif

            Shutdown.ShutdownEvent += OnShutdown;

            main_loop = new MainLoop();
            Shutdown.RegisterMainLoop(main_loop);

            // Defer all actual startup until the main loop is
            // running.  That way shutdowns during the startup
            // process work correctly.
            GLib.Idle.Add(new GLib.IdleHandler(StartupProcess));

            // Start our event loop.
            main_loop.Run();

            // We're out of the main loop now, join all the
            // running threads so we can exit cleanly.
            ExceptionHandlingThread.JoinAllThreads();

            // If we placed our sockets in a temp directory, try to clean it up
            // Note: this may fail because the helper is still running
            if (PathFinder.GetRemoteStorageDir(false) != PathFinder.StorageDir)
            {
                try {
                    Directory.Delete(PathFinder.GetRemoteStorageDir(false));
                } catch (IOException) { }
            }

            Log.Always("Beagrep daemon process shut down cleanly.");
        }
Ejemplo n.º 19
0
    static int Main(string[] args)
    {
        SystemInformation.SetProcessName ("beagle-extract-content");

        if (args.Length < 1 || Array.IndexOf (args, "--help") != -1) {
            PrintUsage ();
            return 0;
        }

        if (Array.IndexOf (args, "--debug") == -1)
            Log.Disable ();

        if (Array.IndexOf (args, "--version") != -1) {
            VersionFu.PrintVersion ();
            return 0;
        }

        if (Array.IndexOf (args, "--tokenize") != -1)
            tokenize = true;

        if (Array.IndexOf (args, "--analyze") != -1)
            analyze = true;

        if (Array.IndexOf (args, "--show-generated") != -1 || Array.IndexOf (args, "--show-children") != -1)
            show_generated = true;

        StreamWriter writer = null;
        string outfile = null;
        foreach (string arg in args) {

            // mime-type option
            if (arg.StartsWith ("--mimetype=")) {
                mime_type = arg.Substring (11);
                continue;
            // output file option
            // we need this in case the output contains different encoding
            // printing to Console might not always display properly
            } else if (arg.StartsWith ("--outfile=")) {
                outfile = arg.Substring (10);
                Console.WriteLine ("Redirecting output to " + outfile);
                FileStream f = new FileStream (outfile, FileMode.Create);
                writer = new StreamWriter (f, System.Text.Encoding.UTF8);
                continue;
            } else if (arg.StartsWith ("--")) // option, skip it
                continue;

            Uri uri = UriFu.PathToFileUri (arg);
            Indexable indexable = new Indexable (uri);
            if (mime_type != null)
                indexable.MimeType = mime_type;

            try {
                if (writer != null) {
                    Console.SetOut (writer);
                }

                Display (indexable);
                if (writer != null) {
                    writer.Flush ();
                }

                if (outfile != null) {
                    StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
                    standardOutput.AutoFlush = true;
                    Console.SetOut(standardOutput);
                }

            } catch (Exception e) {
                Console.WriteLine ("Unable to filter {0}: {1}", uri, e.Message);
                return -1;
            }

            // Super Lame Hack: gtk-sharp up to 2.10 requires a main loop
            // to dispose of any managed wrappers around GObjects.  Since
            // we don't have one, we'll process all the pending items in
            // a loop here.  This is particularly an issue with maildirs,
            // because we need the loop to clean up after GMime.  Without
            // it, GMime's streams are never completely unref'd, the
            // file descriptors aren't closed, and we run out and crash.
            while (GLib.MainContext.Pending ())
                GLib.MainContext.Iteration ();
        }
        if (writer != null)
            writer.Close ();

        return 0;
    }
Ejemplo n.º 20
0
        private static void ParseArgs(string [] args)
        {
            if (args.Length < 1)
            {
                PrintUsageAndExit();
            }

            for (int i = 0; i < args.Length; i++)
            {
                switch (args [i])
                {
                case "-h":
                case "--help":
                    PrintUsageAndExit();
                    break;

                case "--version":
                    VersionFu.PrintVersion();
                    Environment.Exit(0);
                    break;

                case "--highlight-search":
                    highlight = args [i + 1];
                    i++;
                    break;

                case "--search":
                    search = args [i + 1];
                    i++;
                    break;

                case "--client":
                    client = args [i + 1];
                    i++;
                    break;

                default:
                    if (args [i].StartsWith("--"))
                    {
                        Console.WriteLine("WARN: Invalid option {0}", args [i]);
                    }
                    else
                    {
                        path = args [i];
                    }
                    break;
                }
            }

            if (path == null)
            {
                Console.WriteLine("ERROR: Please specify a valid log path or log directory.");
                Environment.Exit(1);
            }

            if (client == null)
            {
                Console.WriteLine("ERROR: Please specify a valid client name.");
                Environment.Exit(2);
            }
        }
Ejemplo n.º 21
0
    public static void Main(string[] args)
    {
        // Initialize GObject type system
        g_type_init();

        Beagrep.Util.Log.Level = LogLevel.Always;         // shhhh... silence

        if (args.Length == 0 || Array.IndexOf(args, "--help") > -1 || Array.IndexOf(args, "--usage") > -1)
        {
            PrintUsageAndExit();
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            Environment.Exit(0);
        }

        StringBuilder query_str = new StringBuilder();

        query = new Query();

        // Parse args
        int    i = 0;
        string next_arg;

        while (i < args.Length)
        {
            switch (args [i])
            {
            case "--verbose":
                verbose = true;
                break;

            case "--cache":
                display_cached_text = true;
                break;

            case "--stats-only":
                verbose      = true;
                display_hits = false;
                break;

            case "--max-hits":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }
                query.MaxHits = Int32.Parse(args[i]);
                break;

            case "--list-backends":
                Console.WriteLine("Current available backends:");
                Console.Write(QueryDriver.ListBackends());
                Environment.Exit(0);
                break;

            case "--backend":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }

                next_arg = args [i];
                if (next_arg.StartsWith("--"))
                {
                    Console.WriteLine("--backend requires a backend name. Invalid name '{0}'", next_arg);
                    Environment.Exit(1);
                    break;
                }

                if (next_arg [0] != '+' && next_arg [0] != '-')
                {
                    QueryDriver.OnlyAllow(next_arg);
                }
                else
                {
                    if (next_arg [0] == '+')
                    {
                        QueryDriver.Allow(next_arg.Substring(1));
                    }
                    else
                    {
                        QueryDriver.Deny(next_arg.Substring(1));
                    }
                }

                break;

            case "--add-static-backend":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }

                next_arg = args [i];
                if (!next_arg.StartsWith("--"))
                {
                    QueryDriver.AddStaticQueryable(next_arg);
                }
                break;

            case "--keywords":
                PropertyKeywordFu.ReadKeywordMappings();

                Console.WriteLine("Supported query keywords are:");

                foreach (string key in PropertyKeywordFu.Keys)
                {
                    foreach (QueryKeywordMapping mapping in PropertyKeywordFu.Properties(key))
                    {
                        // Dont print properties without description; they confuse people
                        if (string.IsNullOrEmpty(mapping.Description))
                        {
                            continue;
                        }
                        Console.WriteLine("  {0,-20} for {1}", key, mapping.Description);
                    }
                }

                System.Environment.Exit(0);
                break;

            default:
                if (args [i].StartsWith("--"))
                {
                    PrintUsageAndExit();
                }
                if (query_str.Length > 0)
                {
                    query_str.Append(' ');
                }
                query_str.Append(args [i]);

                break;
            }

            ++i;
        }

        if (verbose)
        {
            Beagrep.Util.Log.Level = LogLevel.Debug;
        }

        if (query_str.Length > 0)
        {
            query.AddText(query_str.ToString());
        }

        Stopwatch watch = new Stopwatch();

        watch.Start();
        StartQueryDriver();
        watch.Stop();
        if (verbose)
        {
            Console.WriteLine("QueryDriver started in {0}", watch);
        }

        QueryResult result = new QueryResult();

        result.HitsAddedEvent += OnHitsAdded;
        result.FinishedEvent  += OnFinished;

        queryStartTime = DateTime.Now;
        QueryDriver.DoQueryLocal(query, result);
    }
Ejemplo n.º 22
0
    public static void Main(string[] args)
    {
        // Initialize GObject type system
        g_type_init();

        main_loop = new MainLoop();

        if (args.Length == 0 || Array.IndexOf(args, "--help") > -1 || Array.IndexOf(args, "--usage") > -1)
        {
            PrintUsageAndExit();
        }

        if (Array.IndexOf(args, "--version") > -1)
        {
            VersionFu.PrintVersion();
            Environment.Exit(0);
        }

        StringBuilder query_str = new StringBuilder();

        query = new Query();

        QueryDomain domain = 0;

        // Parse args
        int i = 0;

        while (i < args.Length)
        {
            switch (args [i])
            {
            case "--live-query":
                keep_running = true;
                break;

            case "--verbose":
                verbose = true;
                break;

            case "--cache":
                display_cached_text = true;
                break;

            case "--stats-only":
                verbose      = true;
                display_hits = false;
                break;

            case "--max-hits":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }
                query.MaxHits = Int32.Parse(args[i]);
                break;

            case "--flood":
                flood = true;
                break;

            case "--listener":
                listener     = true;
                keep_running = true;
                break;

            case "--raw-uri":
                raw_uri = true;
                break;

            case "--keywords":
                PropertyKeywordFu.ReadKeywordMappings();

                Console.WriteLine("Supported query keywords are:");

                foreach (string key in PropertyKeywordFu.Keys)
                {
                    foreach (QueryKeywordMapping mapping in PropertyKeywordFu.Properties(key))
                    {
                        // Dont print properties without description; they confuse people
                        if (string.IsNullOrEmpty(mapping.Description))
                        {
                            continue;
                        }
                        Console.WriteLine("  {0,-20} for {1}", key, mapping.Description);
                    }
                }

                System.Environment.Exit(0);
                break;

            case "--domain":
                if (++i >= args.Length)
                {
                    PrintUsageAndExit();
                }
                switch (args [i].ToLower())
                {
                case "local":
                    domain |= QueryDomain.Local;
                    break;

                case "system":
                    domain |= QueryDomain.System;
                    break;

                case "network":
                    domain |= QueryDomain.Neighborhood;
                    break;

                case "global":
                    domain |= QueryDomain.Global;
                    break;

                case "all":
                    domain |= QueryDomain.All;
                    break;

                default:
                    PrintUsageAndExit();
                    break;
                }
                break;

            default:
                if (args [i].StartsWith("--"))
                {
                    PrintUsageAndExit();
                }
                if (query_str.Length > 0)
                {
                    query_str.Append(' ');
                }
                query_str.Append(args [i]);

                break;
            }

            ++i;
        }

        if (domain != 0)
        {
            query.QueryDomain = domain;
        }

        if (listener)
        {
            query.IsIndexListener = true;
        }
        else
        {
            if (query_str.Length > 0)
            {
                query.AddText(query_str.ToString());
            }
        }

        query.HitsAddedEvent      += OnHitsAdded;
        query.HitsSubtractedEvent += OnHitsSubtracted;

        if (!keep_running)
        {
            query.FinishedEvent += OnFinished;
        }
        else
        {
            query.ClosedEvent += OnClosed;
        }

        SendQuery();

        main_loop.Run();
    }
Ejemplo n.º 23
0
    static void Main(String[] args)
    {
        string uriStr           = null;
        string title            = null;
        string sourcefile       = null;
        bool   deletesourcefile = false;

        if (args.Length == 0 || Array.IndexOf(args, "--help") > -1)
        {
            PrintUsage();
            Environment.Exit(1);
        }

        for (int i = 0; i < args.Length; i++)
        {
            switch (args [i])
            {
            case "--url":
            case "--title":
            case "--sourcefile":
                if (i + 1 >= args.Length ||
                    args [i + 1].StartsWith("--"))
                {
                    PrintUsage();
                    Environment.Exit(1);
                }
                break;
            }

            switch (args [i])
            {
            case "--url":
                uriStr = args [++i];
                break;

            case "--title":
                title = args [++i];
                break;

            case "--sourcefile":
                sourcefile = args [++i];
                break;

            case "--deletesourcefile":
                deletesourcefile = true;
                break;

            case "--help":
                PrintUsage();
                return;

            case "--version":
                VersionFu.PrintVersion();
                return;
            }
        }

        if (uriStr == null)
        {
            Logger.Log.Error("URI not specified!\n");
            PrintUsage();
            Environment.Exit(1);
        }

        Uri uri = new Uri(uriStr, true);

        if (uri.Scheme == Uri.UriSchemeHttps)
        {
            // For security/privacy reasons, we don't index any
            // SSL-encrypted pages.
            Logger.Log.Error("Indexing secure https:// URIs is not secure!");
            Environment.Exit(1);
        }

        // We don't index file: Uris.  Silently exit.
        if (uri.IsFile)
        {
            return;
        }

        // We *definitely* don't index mailto: Uris.  Silently exit.
        if (uri.Scheme == Uri.UriSchemeMailto)
        {
            return;
        }

        Indexable indexable;

        indexable           = new Indexable(uri);
        indexable.HitType   = "WebHistory";
        indexable.MimeType  = "text/html";
        indexable.Timestamp = DateTime.Now;

        if (title != null)
        {
            indexable.AddProperty(Property.New("dc:title", title));
        }

        if (sourcefile != null)
        {
            if (!File.Exists(sourcefile))
            {
                Logger.Log.Error("sourcefile '{0}' does not exist!", sourcefile);
                Environment.Exit(1);
            }

            indexable.ContentUri    = UriFu.PathToFileUri(sourcefile);
            indexable.DeleteContent = deletesourcefile;
        }
        else
        {
            Stream stdin = Console.OpenStandardInput();
            if (stdin == null)
            {
                Logger.Log.Error("No sourcefile specified, and no standard input!\n");
                PrintUsage();
                Environment.Exit(1);
            }

            indexable.SetTextReader(new StreamReader(stdin));
        }

        IndexingServiceRequest req = new IndexingServiceRequest();

        req.Add(indexable);

        try {
            Logger.Log.Info("Indexing");
            Logger.Log.Debug("SendAsync");
            req.SendAsync();
            Logger.Log.Debug("Close");
            req.Close();
            Logger.Log.Debug("Done");
        } catch (Exception e) {
            Logger.Log.Error("Indexing failed: {0}", e);

            // Still clean up after ourselves, even if we couldn't
            // index the content.
            if (deletesourcefile)
            {
                File.Delete(sourcefile);
            }

            Environment.Exit(1);
        }
    }
Ejemplo n.º 24
0
    public static void Main(string [] args)
    {
        if (args.Length == 0)
        {
            PrintUsageAndExit();
        }

        for (int i = 0; i < args.Length; i++)
        {
            switch (args [i])
            {
            case "--list-sections":
                ListSections();
                return;

            case "--list-backends":
                ListBackends();
                return;

            case "--reload":
            case "--beagled-reload-config":
                ReloadConfig();
                return;

            case "--write-xml":
                if (args.Length == i + 1)
                {
                    PrintUsageAndExit();
                }
                PrintSectionXml(args [i + 1]);
                return;

            case "--read-xml":
                if (args.Length == i + 1)
                {
                    PrintUsageAndExit();
                }
                ReadSectionXml(args [i + 1]);
                return;

            case "--help":
            case "--usage":
                PrintUsageAndExit();
                return;

            case "--version":
                VersionFu.PrintVersion();
                Environment.Exit(0);
                break;

            default:
                break;
            }
        }

        if (args [0].StartsWith("--"))
        {
            PrintUsageAndExit();
        }

        Config config = Conf.Load(args [0]);

        if (config == null)
        {
            Console.WriteLine("No section found: " + args [0]);
            return;
        }

        if (args.Length >= 2)
        {
            try {
                if (HandleArgs(config, args))
                {
                    Conf.Save(config);
                }
            } catch (ArgumentException e) {
                Console.WriteLine("** Error: " + e.Message);
            }

            return;
        }

        foreach (Option option in config.Options.Values)
        {
            ShowOption(config, option);
        }
    }