~rrt/caffeine/trunk

« back to all changes in this revision

Viewing changes to caffeine/main.py

  • Committer: Reuben Thomas
  • Date: 2014-01-31 01:49:04 UTC
  • Revision ID: rrt@sc3d.org-20140131014904-pw78rf09p1h8672a
Use argparse instead of optparse; remove activate/deactivate command-line args, and add --version

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
from gi.repository import Gtk, GdkPixbuf, GObject, AppIndicator3
22
22
import ctypes
23
 
import optparse
 
23
import argparse
24
24
import signal
25
25
 
26
26
## local modules
139
139
    libc.prctl(15, 'caffeine', 0, 0, 0)
140
140
  
141
141
    ## handle command line arguments
142
 
    parser = optparse.OptionParser()
143
 
    parser.add_option("-a", "--activate", action="store_true",
144
 
            dest="activated", default=False,
145
 
            help="Disables power management and screen saving")
146
 
 
147
 
    parser.add_option("-d", "--deactivate", action="store_false",
148
 
            dest="activated", default=False,
149
 
            help="Re-enables power management and screen saving")
150
 
 
151
 
    global options
152
 
    options, args = parser.parse_args()
 
142
    parser = argparse.ArgumentParser(prog='caffeine', description='Manually and automatically prevent desktop idleness')
 
143
    parser.add_argument('-V', '--version', action='version', version='caffeine ' + VERSION)
 
144
    args = parser.parse_args()
153
145
    
154
146
    ## Makes sure that only one instance of the Caffeine is run for
155
147
    ## each user on the system.
160
152
 
161
153
    main = GUI()
162
154
        
163
 
    if options.activated:
164
 
        main.setActive(options.activated)
165
 
 
166
155
    appInstance.startApplication()
167
156
    Gtk.main()
168
157
    appInstance.exitApplication()