~khurshid-alam/gwibber/gwibber-hack

« back to all changes in this revision

Viewing changes to bin/gwibber

  • Committer: Khurshid Alam
  • Date: 2012-04-06 14:38:38 UTC
  • Revision ID: khurshid.alam@linuxmail.org-20120406143838-nz7hjg8vtzi2wl7i
initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""
 
4
 
 
5
Gwibber Client
 
6
SegPhault (Ryan Paul) - 05/29/2007
 
7
 
 
8
"""
 
9
 
 
10
import sys, gtk, optparse, dbus, wnck, time
 
11
from os.path import join, dirname, exists, realpath, abspath
 
12
from dbus.mainloop.glib import DBusGMainLoop
 
13
from dbus import DBusException
 
14
import gettext
 
15
from gettext import lgettext as _
 
16
if hasattr(gettext, 'bind_textdomain_codeset'):
 
17
    gettext.bind_textdomain_codeset('gwibber','UTF-8')
 
18
gettext.textdomain('gwibber')
 
19
 
 
20
######################################################################
 
21
# Don't run again if we are already running
 
22
progname = "gwibber"
 
23
screen = wnck.screen_get_default()
 
24
while gtk.events_pending():
 
25
  gtk.main_iteration()
 
26
for w in screen.get_windows():
 
27
  if w.get_application().get_name() == progname:
 
28
    w.activate(int(time.time()))
 
29
    w.move_to_workspace(screen.get_active_workspace())
 
30
    quit()
 
31
 
 
32
######################################################################
 
33
# Setup path
 
34
 
 
35
LAUNCH_DIR = abspath(sys.path[0])
 
36
SOURCE_DIR = join(LAUNCH_DIR, "..", "gwibber")
 
37
 
 
38
DBusGMainLoop(set_as_default=True)
 
39
 
 
40
# If we were invoked from a Gwibber source directory add that as the
 
41
# preferred module path ...
 
42
if exists(join(SOURCE_DIR, "client.py")):
 
43
    sys.path.insert(0, realpath(dirname(SOURCE_DIR)))
 
44
    try:
 
45
      from gwibber.microblog.util import log
 
46
      log.logger.name = "Gwibber GNOME Client"
 
47
      log.logger.info("Running from the source tree")
 
48
      from gwibber import client
 
49
    finally:
 
50
        del sys.path[0]
 
51
else:
 
52
    from gwibber.microblog.util import log
 
53
    log.logger.name = "Gwibber GNOME Client"
 
54
    log.logger.info("Running from the system path")
 
55
    from gwibber import client
 
56
 
 
57
######################################################################
 
58
# Options 
 
59
from optparse import OptionParser
 
60
parser = OptionParser()
 
61
parser.add_option("-d", "--debug", action="store_true",
 
62
                  dest="debug", default=False,  
 
63
                  help=_("Log debug messages"))
 
64
parser.add_option("-o", action="store_true",
 
65
                  dest="stdout", default=False,
 
66
                  help="Log to stdout")
 
67
(options, args) = parser.parse_args()
 
68
 
 
69
if options.debug:
 
70
  log.logger.setLevel(log.logging.DEBUG)
 
71
else:
 
72
  log.logger.setLevel(log.logging.INFO)
 
73
if options.stdout:
 
74
  # define a Handler which writes INFO messages or higher to the sys.stderr
 
75
  console = log.logging.StreamHandler()
 
76
  if options.debug:
 
77
    console.setLevel(log.logging.DEBUG)
 
78
  else:
 
79
    console.setLevel(log.logging.INFO)
 
80
  # set a format which is simpler for console use
 
81
  formatter = log.logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
 
82
  console.setFormatter(formatter)
 
83
  log.logger.addHandler(console)
 
84
 
 
85
######################################################################
 
86
 
 
87
client.Client()
 
88
gtk.main()