def initialize(themeName): """Initialize Miro. This sets up things like logging and the config system and should be called as early as possible. """ # set debugmode if it hasn't already been set if app.debugmode == None: app.debugmode = app.config.get(prefs.APP_VERSION).endswith("-git") # this is platform specific setup_logging() # this is portable general util.setup_logging() app.controller = controller.Controller() config.set_theme(themeName)
def launch(): # Make all output flush immediately. # Don't add extra import statements here. If there's a problem importing # something we want to see the error in the log. import logging import sys import os from miro import util sys.stdout = util.AutoFlushingStream(sys.stdout) sys.stderr = sys.stdout override_modules() from miro.plat.utils import setup_logging, initialize_locale setup_logging(in_downloader=True) util.setup_logging() initialize_locale() if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') != '1': logging.info("Starting new downloader log") else: logging.info("Launching Downloader Daemon") log_versions() # Start of normal imports import threading from miro.dl_daemon import daemon from miro import httpclient addr = os.environ['DEMOCRACY_DOWNLOADER_ADDR'] port = int(os.environ['DEMOCRACY_DOWNLOADER_PORT']) short_app_name = os.environ['DEMOCRACY_SHORT_APP_NAME'] httpclient.start_thread() server = daemon.DownloaderDaemon(addr, port, short_app_name) # setup config for the downloader from miro import eventloop config.load(config.DownloaderConfig()) app.downloader_config_watcher = config.ConfigWatcher( lambda foo, *args: eventloop.add_idle(foo, "config watcher", args=args)) # start things up eventloop.startup()
def initialize(themeName): """Initialize Miro. This sets up things like logging and the config system and should be called as early as possible. """ # set debugmode if it hasn't already been set if app.debugmode == None: if app.config.get(prefs.APP_FINAL_RELEASE) == u"0": # if it's not a final release, then we're in debugmode app.debugmode = True else: # if it is a final release, then we're not in debugmode app.debugmode = False # this is platform specific setup_logging() # this is portable general util.setup_logging() app.controller = controller.Controller() config.set_theme(themeName)
def setup_logging(): pathname = app.config.get(prefs.LOG_PATHNAME) try: rotater = logging.handlers.RotatingFileHandler(pathname, mode="w", maxBytes=100000, backupCount=5) except IOError: # bug 13338. sometimes there's a file there and it causes # RotatingFileHandler to flip out when opening it. so we # delete it and then try again. os.remove(pathname) rotater = logging.handlers.RotatingFileHandler(pathname, mode="w", maxBytes=100000, backupCount=5) rotater.setLevel(logging.WARN) formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(message)s") rotater.setFormatter(formatter) logging.getLogger("").addHandler(rotater) rotater.doRollover() from miro import util util.setup_logging()
def _subprocess_setup(stdin, stdout): """Does initial setup for a subprocess. Returns a SubprocessHandler to use for the subprocess raises the same exceptions that _load_obj does, namely: :raises IOError: low-level error while reading from the pipe :raises LoadError: data read was corrupted """ global logging_setup # disable warnings so we don't get too much junk on stderr warnings.filterwarnings("ignore") # setup MessageHandler for messages going to the main process msg_handler = PipeMessageProxy(stdout) SubprocessResponse.install_handler(msg_handler) # load startup info msg = _load_obj(stdin) if not isinstance(msg, StartupInfo): raise LoadError("first message must a StartupInfo obj") # setup some basic modules like config and gtcache utils.initialize_locale() config.load(config.ManualConfig()) app.config.set_dictionary(msg.config_dict) gtcache.init() if not msg.in_unit_tests: utils.setup_logging(app.config.get(prefs.HELPER_LOG_PATHNAME)) util.setup_logging() logging_setup = True logging.info("Logging Started") # setup our handler msg = _load_obj(stdin) if not isinstance(msg, HandlerInfo): raise LoadError("second message must a HandlerInfo obj") try: return msg.handler_class(*msg.handler_args) except StandardError, e: # log this exception for easier debugging. send_subprocess_error_for_exception() raise LoadError("Exception while constructing handler: %s" % e)
def launch(): # Make all output flush immediately. # Don't add extra import statements here. If there's a problem importing # something we want to see the error in the log. from miro import util sys.stdout = util.AutoFlushingStream(sys.stdout) sys.stderr = sys.stdout override_modules() from miro.plat.utils import setup_logging, initialize_locale setup_logging(in_downloader=True) util.setup_logging() initialize_locale() if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') != '1': logging.info("Starting new downloader log") else: logging.info("Launching Downloader Daemon") log_versions() # Start of normal imports from miro.dl_daemon import daemon from miro import httpclient addr = os.environ['DEMOCRACY_DOWNLOADER_ADDR'] port = int(os.environ['DEMOCRACY_DOWNLOADER_PORT']) short_app_name = os.environ['DEMOCRACY_SHORT_APP_NAME'] httpclient.start_thread() daemon.DownloaderDaemon(addr, port, short_app_name) # setup config for the downloader from miro import eventloop config.load(config.ManualConfig()) app.downloader_config_watcher = config.ConfigWatcher( lambda foo, *args: eventloop.add_idle(foo, "config watcher", args=args )) # start things up eventloop.startup()
from miro import httpauth from miro import httpclient from miro import iteminfocache from miro import util from miro import databaseupgrade from miro import prefs from miro import searchengines from miro import signals from miro import storedatabase from miro import subscription from time import sleep from miro import models from miro.test import testhttpserver util.setup_logging() # Generally, all test cases should extend MiroTestCase or # EventLoopTest. MiroTestCase cleans up any database changes you # might have made, and EventLoopTest provides an API for accessing the # eventloop in addition to managing the thread pool and cleaning up # any events you may have scheduled. # # Our general strategy here is to "revirginize" the environment after # each test, rather than trying to reset applicable pieces of the # environment before each test. This way, when writing new tests you # don't have to anticipate what another test may have changed, you # just have to make sure you clean up what you changed. Usually, that # is handled transparently through one of these test cases class HadToStopEventLoop(Exception):
from miro import httpauth from miro import httpclient from miro import iteminfocache from miro import moviedata from miro import util from miro import prefs from miro import searchengines from miro import signals from miro import storedatabase from time import sleep from miro import models from miro import workerprocess from miro.test import testhttpserver util.setup_logging() # Generally, all test cases should extend MiroTestCase or # EventLoopTest. MiroTestCase cleans up any database changes you # might have made, and EventLoopTest provides an API for accessing the # eventloop in addition to managing the thread pool and cleaning up # any events you may have scheduled. # # Our general strategy here is to "revirginize" the environment after # each test, rather than trying to reset applicable pieces of the # environment before each test. This way, when writing new tests you # don't have to anticipate what another test may have changed, you # just have to make sure you clean up what you changed. Usually, that # is handled transparently through one of these test cases import sys