Commits

Marc-Alexandre Chan committed 1fcfdff

A few fixes for bootstrap scripts, revised events.txt, removed stray return in events.py

Comments (0)

Files changed (4)

 """ 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 import DailyPromptMinibot, InvalidRedditError
-from minibot.config import ConfigValueError
-from reddit.errors import InvalidUserPass
-from urllib2 import HTTPError
+from minibot import DailyPromptMinibot
+from minibot.errors import InvalidRedditError, ConfigValueError,\
+    InvalidUserPass, HTTPError
 import sys
 
 def main():
     try:
         minibot_app = DailyPromptMinibot('minibot.ini')
+        minibot_app.init_resources()
     except IOError as e:
         sys.exit("Error opening configuration file: " + e.message)
     except (ConfigValueError, ValueError) as e:
     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
+        raise # let Python handle it. This line just documents the possibility
+
+    minibot_app.run()
 
 if __name__ == '__main__':
     main()

minibot/events.py

     def _check_event_queue(self):
         """ Check whether a prompt add event for this prompt is in the
         scheduler. If so, remove it. """
-        return # TODO: remove me and test this method
         for ev in self.owner.get_events(PostPromptCommand):
             if ev.post_id == self.params['id']:
                 self.owner.remove_event(ev)

minibot/events.txt

       -1 = infinite duration event. Only meaningful if interval is specified
       and non-zero.
 * delay: optional. At the end of an iteration, when repeated events are
-      rescheduled, this value is added to the regular ``interval`` value. If
+      rescheduled, this value is added to the regular ``interval`` value for the
+      next iteration. Note that this affects the duration check. If
       this value is non-zero after handle_exception() is called (and returns
-      True), the event call is attempted again after this value in seconds.
+      True), the event call is attempted again after this value in seconds; in
+      this case, the resulting run-time may be after the allotted duration for a
+      re-attempt, but the event will be ended after this iteration.
       This is reset to None after every event call or handled exception in
       this event.
 * priority: default 100. If multiple events are scheduled to run simul-
 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 minibot import DailyPromptMinibot
+from minibot.errors import InvalidRedditError, ConfigValueError,\
+    InvalidUserPass, HTTPError
 from daemon.runner import DaemonRunner, DaemonRunnerInvalidActionError,\
     DaemonRunnerStartFailureError, DaemonRunnerStopFailureError
-from urllib2 import HTTPError
 import sys
 
 def main():
         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)
+        if daemon.action != 'stop':
+            minibot_app.init_resources()
         daemon.do_action()
     except DaemonRunnerInvalidActionError as e:
         sys.exit(str(e))
         sys.exit("Failed to start daemon: " + e.message)
     except DaemonRunnerStopFailure as e:
         sys.exit("Failed to end daemon: " + 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. This line just documents the possibility
 
 if __name__ == '__main__':
     main()