#!/usr/bin/python -t #-*- coding:utf-8 -*- # Glipper - Clipboardmanager for GNOME # Copyright (C) 2007 Glipper Team # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # import logging import time import getopt, sys from datetime import datetime from os.path import * from os import environ now = datetime.now() # Beware what and where you log, you might copy a password... log_file = environ['HOME'] + '/.glipper/glipper.log' logging.basicConfig( filename = log_file, level = logging.DEBUG ) # See whether we're starting at all... logging.info( '_________________________ Trying to start glipper... ' + datetime.now().isoformat() ) try: logging.debug( "Importing gobject..." + datetime.now().isoformat() ) import gobject except StandardError: logging.fatal( "Unable to import gobject!" ) try: logging.debug( "Importing gtk..." + datetime.now().isoformat() ) import gtk except StandardError: logging.fatal( "Unable to import gtk!" ) try: logging.debug( "Importing gnome..." + datetime.now().isoformat() ) import gnome except StandardError: logging.fatal( "Unable to import gnome!" ) try: logging.debug( "Importing gnomeapplet..." + datetime.now().isoformat() ) import gnomeapplet except StandardError: logging.fatal( "Unable to import gnomeapplet!" ) try: logging.debug( "Importing glipper..." + datetime.now().isoformat() ) import glipper except StandardError: logging.fatal( "Unable to import glipper!" ) try: logging.debug( "Importing glipper.defs..." + datetime.now().isoformat() ) import glipper.defs except StandardError: logging.fatal( "Unable to import glipper.defs!" ) try: logging.debug( "Importing glipper.Applet..." + datetime.now().isoformat() ) import glipper.Applet except StandardError: logging.fatal( "Unable to import glipper.Applet!" ) logging.debug( 'Initiating threads... ' + datetime.now().isoformat() ) gobject.threads_init() sys.path.insert(0, glipper.PLUGINS_DIR) try: # attempt to set a name for killall logging.debug( 'Importing glipper.osutils... ' + datetime.now().isoformat() ) import glipper.osutils glipper.osutils.set_process_name("glipper") except: logging.warn( "Unable to set process name at " + datetime.now().isoformat() ) logging.debug( 'Importing gettext, locale... ' + datetime.now().isoformat() ) import gettext, locale gettext.bindtextdomain('glipper', abspath(join(glipper.defs.DATA_DIR, "locale"))) if hasattr(gettext, 'bind_textdomain_codeset'): gettext.bind_textdomain_codeset('glipper','UTF-8') gettext.textdomain('glipper') locale.bindtextdomain('glipper', abspath(join(glipper.defs.DATA_DIR, "locale"))) if hasattr(locale, 'bind_textdomain_codeset'): locale.bind_textdomain_codeset('glipper','UTF-8') locale.textdomain('glipper') def applet_factory(applet, iid): logging.debug( 'Starting Glipper instance: ' + applet.__str__() + iid.__str__() ) glipper.Applet.Applet(applet) return True # Return a standalone window that holds the applet def build_window(): logging.debug( 'Building application... ' + datetime.now().isoformat() ) app = gtk.Window(gtk.WINDOW_TOPLEVEL) app.set_title("Glipper") app.connect("destroy", gtk.main_quit) app.set_property('resizable', False) applet = gnomeapplet.Applet() applet.get_orient = lambda: gnomeapplet.ORIENT_DOWN applet_factory(applet, None) applet.reparent(app) app.show_all() return app def usage(): print """=== Glipper: Usage $ glipper [OPTIONS] OPTIONS: -h, --help Print this help notice. -w, --window Launch the applet in a standalone window for test purposes (default=no). """ sys.exit() if __name__ == "__main__": standalone = False do_trace = False try: opts, args = getopt.getopt(sys.argv[1:], "hw", ["help", "window"]) except getopt.GetoptError: # Unknown args were passed, we fallback to bahave as if # no options were passed logging.info( "Unknown arguments passed, using defaults." ) opts = [] args = sys.argv[1:] for o, a in opts: if o in ("-h", "--help"): usage() elif o in ("-w", "--window"): standalone = True logging.debug( 'Running with options:' + { 'standalone': standalone }.__str__() ) gnome.program_init('glipper', '1.0', properties= { gnome.PARAM_APP_DATADIR : glipper.DATA_DIR }) if standalone: logging.info( 'Running standalone... ' + datetime.now().isoformat() ) gnome.init(glipper.defs.PACKAGE, glipper.defs.VERSION) build_window() gtk.main() else: logging.info( 'Running as applet... ' + datetime.now().isoformat() ) gnomeapplet.bonobo_factory( "OAFIID:Glipper_Factory", gnomeapplet.Applet.__gtype__, glipper.defs.PACKAGE, glipper.defs.VERSION, applet_factory)