Marc-Alexandre Chan avatar Marc-Alexandre Chan committed 16ec299

Bootstrap scripts

Comments (0)

Files changed (2)

 #
 #-------------------------------------------------------------------------------
 
-""" Daemon bootstrap script. """
+""" The Daily Prompt: Minibot (daemon mode) bootstrap script. Use this script to
+run the Minibot as a console application. Run this script without arguments. """
 
-from minibot.minibot import DailyPromptMinibot
-
-from daemon.runner import DaemonRunner
+from minibot import DailyPromptMinibot, InvalidRedditError
+from minibot.config import ConfigValueError
+from reddit.errors import InvalidUserPass
+from urllib2 import HTTPError
+import sys
 
 def main():
-    pass
+    try:
+        minibot_app = DailyPromptMinibot('minibot.ini')
+    except IOError as e:
+        sys.exit("Error opening configuration file: " + e.message)
+    except (ConfigValueError, ValueError) as e:
+        sys.exit("Invalid configuration value: " + e.message)
+    except InvalidUserPass as e:
+        sys.exit("Error logging into Reddit account: " + e.message)
+    except HTTPError as e:
+        sys.exit("An error occurred accessing Reddit: " + e.message)
+    except (SQLAlchemyError, DBAPIError):
+        raise # let Python handle it. Here to document possible exceptions
 
 if __name__ == '__main__':
     main()
+#!/usr/bin/env python
+#-------------------------------------------------------------------------------
+# The Daily Prompt Mini-Bot - A Shut Up and Write Project
+# Version 0.0.1a
+# Author: Marc-Alexandre Chan <laogeodritt at arenthil.net>
+#-------------------------------------------------------------------------------
+#
+# Copyright (c) 2012 Marc-Alexandre Chan. Licensed under the GNU GPL version 3
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#-------------------------------------------------------------------------------
+
+""" The Daily Prompt: Minibot (daemon mode) bootstrap script. Use this script to
+run the Minibot in daemon mode (UNIX and UNIX-like systems only!). This script
+accepts an argument that can take one of three values: 'start', 'restart' or
+'stop'. """
+
+from minibot import DailyPromptMinibot, InvalidRedditError
+from minibot.config import ConfigValueError
+from reddit.errors import InvalidUserPass
+from daemon.runner import DaemonRunner, DaemonRunnerInvalidActionError,\
+    DaemonRunnerStartFailureError, DaemonRunnerStopFailureError
+from urllib2 import HTTPError
+import sys
+
+def main():
+    try:
+        minibot_app = DailyPromptMinibot('minibot.ini')
+    except IOError as e:
+        sys.exit("Error opening configuration file: " + e.message)
+    except (ConfigValueError, ValueError) as e:
+        sys.exit("Invalid configuration value: " + e.message)
+    except InvalidUserPass as e:
+        sys.exit("Error logging into Reddit account: " + e.message)
+    except HTTPError as e:
+        sys.exit("An error occurred accessing Reddit: " + e.message)
+    except (SQLAlchemyError, DBAPIError):
+        raise # let Python handle it. Here to document possible exceptions
+
+    try:
+        daemon = DaemonRunner(minibot_app)
+        daemon.do_action()
+    except DaemonRunnerInvalidActionError as e:
+        sys.exit(str(e))
+    except DaemonRunnerStartFailureError as e:
+        sys.exit("Failed to start daemon: " + e.message)
+    except DaemonRunnerStopFailure as e:
+        sys.exit("Failed to end daemon: " + e.message)
+
+if __name__ == '__main__':
+    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.