Commits

Martin Tournoij  committed db6f231

Update

  • Participants
  • Parent commits 0cdb9b1

Comments (0)

Files changed (7)

File README

-For installation, run:
-./setup.py install
-
-Running from the source directory is not supported.
-
-For more docs, see:
-https://bitbucket.org/Carpetsmoker/battray/wiki/Home
+For installation, run:
+./setup.py install
+
+Running from the source directory is not supported.
+
+For more docs, see:
+https://code.arp242.net/battray/wiki/Home
 #!/usr/bin/env python
 #
-# Battray 1.5 by Martin Tournoij <martin@arp242.net>
-# https://bitbucket.org/Carpetsmoker/battray
+# Battray 1.6 by Martin Tournoij <martin@arp242.net>
+# https://code.arp242.net/battray
 #
 # Feel free to use, modify, and redistribute as you see fit. There are no
 # restrictions.
 # For information, take a look at the manpage
 #
 
+from __future__ import print_function
+
 import getopt
+import imp
 import os
 import subprocess
 import sys
 import traceback
 
-try:
-	import thread
-except ImportError:
-	import dummy_thread as thread
+if sys.version_info[0] == 2:
+	try:
+		import thread as _thread
+	except ImportError:
+		import _dummy_thread as dummy_thread
+else:
+	try:
+		import _thread
+	except ImportError:
+		import _dummy_thread
 
 # py-gtk2 2.10 or higher required
 try:
 	import gobject
 	import gtk
 except ImportError:
-	print >> sys.stderr, 'Battray: Error, PyGTK 2.10 or higher is required, unable to find PyGTK.'
-	print >> sys.stderr, 'Battray: PyGTK homepage http://www.pygtk.org/'
+	print('Battray: Error, PyGTK 2.10 or higher is required, unable to find PyGTK.', file=sys.stderr)
+	print('Battray: PyGTK homepage http://www.pygtk.org/', file=sys.stderr)
 	sys.exit(1)
 
 # Only works on Linux and FreeBSD
 try:
 	import ossaudiodev
 except ImportError:
-	print 'Unable to load ossaudiodev module'
-	print sys.exc_info()[1]
+	print('Unable to load ossaudiodev module')
+	print(sys.exc_info()[1])
 	sys.exit(1)
 
 try:
 	import wave
 except ImportError:
-	print 'Unable to load wave module'
-	print sys.exc_info()[1]
+	print('Unable to load wave module')
+	print(sys.exc_info()[1])
 	sys.exit(1)
 
 
 	Note: We do not exit
 	"""
 
-	print "  Usage: %s [-hv] [-p platform] [-d datadir] [-f configfile]" % os.path.basename(sys.argv[0])
-	print "  [-i pol_interval]"
-	print ""
-	print "\t-h, --help\tPrint this help message and exit."
-	print "\t-v, --version\tPrint version and exit."
-	print "\t-d, --datadir\tDatadir to use (For icons)."
-	print "\t-f, --file\tConfiguration file to use."
-	print "\t-i, --interval\tPoll the status every n seconds."
-	print "\t-p, --platform\tSpecify a specific platform file/"
-	print "\t              \tWill be imported, so make sure it's in sys.path"
-	print ""
-	print "  Please see battray(1) for more documentation."
+	print("  Usage: %s [-hv] [-p platform] [-d datadir] [-f configfile]" % os.path.basename(sys.argv[0]))
+	print("  [-i pol_interval]")
+	print("")
+	print("\t-h, --help\tPrint this help message and exit.")
+	print("\t-v, --version\tPrint version and exit.")
+	print("\t-d, --datadir\tDatadir to use (For icons).")
+	print("\t-f, --file\tConfiguration file to use.")
+	print("\t-i, --interval\tPoll the status every n seconds.")
+	print("\t-p, --platform\tSpecify a specific platform file/")
+	print("\t              \tWill be imported, so make sure it's in sys.path")
+	print("")
+	print("  Please see battray(1) for more documentation.")
 
 _config = {}
 _p = None
 	# Make sure we're using the right PyGTK version
 	ver = float('%i.%i' % (gtk.ver[0], gtk.ver[1]))
 	if ver <= 2.10:
-		print >> sys.stderr, 'Battray: Error, PyGTK 2.10 or higher is required, found version %.2f' % ver
-		print >> sys.stderr, 'Battray: PyGTK homepage http://www.pygtk.org/'
+		print('Battray: Error, PyGTK 2.10 or higher is required, found version %.2f' % ver, file=sys.stderr)
+		print('Battray: PyGTK homepage http://www.pygtk.org/', file=sys.stderr)
 		sys.exit(1)
 	
 	# Parse commandline arguments.
 			['help', 'version', 'datadir=', 'file=', 'platform=', 'interval='])
 	except getopt.GetoptError:
 		Usage()
-		print >> sys.stderr, "\nBattray: Error,", sys.exc_info()[1]
+		print("\nBattray: Error,", sys.exc_info()[1], file=sys.stderr)
 		sys.exit(1)
 
 	optionfile = ''
 			Usage()
 			sys.exit(0)
 		elif opt == '-v' or opt == '--version':
-			print 'Battray 1.5'
-			print 'Martin Tournoij <martin@arp242.net>'
-			print 'https://bitbucket.org/Carpetsmoker/battray'
+			print('Battray 1.6')
+			print('Martin Tournoij <martin@arp242.net>')
+			print('https://code.arp242.net/battray')
 			sys.exit(0)
 		elif opt == '-f' or opt == '--file':
 			if not os.path.exists(arg):
-				print >> sys.stderr, "Battray: Configuration file `%s' doesn't exists." % arg
+				print("Battray: Configuration file `%s' doesn't exists." % arg, file=sys.stderr)
 				sys.exit(1)
 			optionfile = arg
 		elif opt == '-d' or opt == '--datadir':
 	# No config file, use the default
 	if config is None:
 		if full:
-			print 'Battray: Using default config file.'
+			print('Battray: Using default config file.')
 		for f in sys.path:
 			if os.path.exists(f + '/battray/battrayrc_default.py'):
 				config = f + '/battray/battrayrc_default.py'
 
 	# exec config file
 	try:
-		exec open(config, 'r').read()
+		exec(open(config, 'r').read())
 		_config['icon'] = icon
 		_config['color'] = color
 		_config['blink'] = blink
 			_config['pollinterval'] = pollinterval
 
 	except:
-		print >> sys.stderr, "Battray: Unable to load configuration file `%s'" % config
-		print >> sys.stderr, sys.exc_info()[1]
-		print traceback.print_tb(sys.exc_info()[2])
+		print("Battray: Unable to load configuration file `%s'" % config, file=sys.stderr)
+		print(sys.exc_info()[1], file=sys.stderr)
+		print(traceback.print_tb(sys.exc_info()[2]))
 		sys.exit(1)
 
 	# Just in case someone added quotes
 
 	# Sanity checking
 	if not os.path.exists(_config['datadir']):
-		print >> sys.stderr, "Battray: Datadir `%s' doesn't exist." % _config['datadir']
+		print("Battray: Datadir `%s' doesn't exist." % _config['datadir'], file=sys.stderr)
 		sys.exit(1)
 
 	if full:
 	try:
 		_p = __import__('battray.platforms.' + os.path.basename(platform), fromlist=[platform])
 	except ImportError:
-		print >> sys.stderr, "Battray: Unable to get information for platform `%s'\n%s" % (
-			platform, sys.exc_info()[1])
+		print("Battray: Unable to get information for platform `%s'\n%s" % (
+			platform, sys.exc_info()[1]), file=sys.stderr)
 		sys.exit(1)
 
 	ReloadPlatform()
 		except RuntimeError:
 			if _usecolor:
 				_usecolor = False
-				print >> sys.stderr, 'Battray: py-gtk2 needs to be compiled with numpy',
-				print >> sys.stderr, 'to change the color of the status icon'
+				print('Battray: py-gtk2 needs to be compiled with numpy', end=' ', file=sys.stderr)
+				print('to change the color of the status icon', file=sys.stderr)
 
 		if _usecolor:
 			# 24 pixels wide
 def AboutDialog(widget, data = None):
 	about = gtk.AboutDialog()
 	about.set_authors(['Martin Tournoij <martin@arp242.net>', 'Andy Mikhaylenko <andy@neithere.net>', 'Keith W. Blackwell'])
-	about.set_version('1.5')
-	about.set_website('https://bitbucket.org/Carpetsmoker/battray')
+	about.set_version('1.6')
+	about.set_website('https://code.arp242.net/battray')
 	about.set_comments('Simple program that displays a tray icon to inform you on your notebooks battery status.')
 	about.run()
 	about.destroy()
 
 	if _p:
 		ac = _p.ac
-		reload(_p)
+		imp.reload(_p)
 
 		if not _p.ac and ac:
 			_p.switchedtobattery = True
 	"""
 
 	try:
-		print cmd
+		print(cmd)
 		o = subprocess.Popen([cmd], stdout=subprocess.PIPE, shell=True).communicate()[0]
 	except OSError:
-		print >> sys.stderr, "Battray: Something went wrong executing `%s'\n%s" % (
-			cmd, sys.exc_info()[1])
+		print("Battray: Something went wrong executing `%s'\n%s" % (
+			cmd, sys.exc_info()[1]), file=sys.stderr)
 
 def play(sound):
 	"""
 	else:
 		sound = '%s/%s' % (_config['datadir'], sound.strip())
 
-	thread.start_new_thread(PlaySound, (sound,))
+	_thread.start_new_thread(PlaySound, (sound,))
 
 def playonce(sound, id):
 	if not _playonce.get(id):
 	try:
 		dsp = ossaudiodev.open('/dev/dsp', 'w')
 	except IOError:
-		print 'Unable to open /dev/dsp'
-		print sys.exc_info()[1]
+		print('Unable to open /dev/dsp')
+		print(sys.exc_info()[1])
 		sys.exit(1)
 
 	try:
 	dsp.write(data)
 	dsp.close()
 
-	thread.exit()
+	_thread.exit()
 
 if __name__ == '__main__':
 	try:
 
 		gtk.main()
 	except KeyboardInterrupt:
-		print ''
+		print('')
 		sys.exit(0)

File doc/battray.1

 Keith W. Blackwell a.k.a. zimbot from freesound.org
 .RE
 .P
-Feel free to use, modify, and redistribute battray as you see fit. There are no
-restrictions.
-.\" man code generated by txt2tags 2.6 (http://txt2tags.org)
-.\" cmdline: txt2tags -o - --target man doc/battray.t2t
+MIT License applies: http://opensource.org/licenses/MIT
+.P
+http://code.arp242.net/battray

File doc/battray.gwiki

-*battray*
-Martin Tournoij <martin@arp242.net>
-_Battray 1.5_
-= NAME =
-Battray -- Display an battery status notification tray icon
-= SYNOPSIS =
-battray [-hv] [-p platform] [-d datadir] [-f configfile] [-i pol_interval]
-= DESCRIPTION =
-battray is a tray icon aka status icon to notify you of your battery status and do
-some action depending on it.
-      _-h_, -_-help_
-        Display help message and exit.
-      _-v_, _--version_
-        Display version and exit.
-      _-p_, _--platform_
-        Use this platform file, normally this is autodetected.
-        Will be imported, so make sure it's in sys.path
-      _-d_, _--datadir_
-        Datadir to get icons and platform file from.
-      _-f_, _--file_
-        Configuration file to use. A configuration file is mandatory.
-      _-i_, _--interval_
-        Poll the system every n seconds.
-= CONFIGURATION =
-The configuration file is imported in Python, any valid Python code goes.
-You don't need to specify your own configuration, a basic conservative
-configuration is included.
-== Location ==
-The configuration file will be searched in the following locations. The first
-match wins:
- * Specified from commandline
- * ~/.battray/battrayrc.py
- * ~/.battrayrc.py
- * /usr/local/etc/battrayrc.py
- * /usr/local/etc/battray/battrayrc.py
- * /etc/battrayrc.py
- * /etc/battray/battrayrc.py
- * /usr/local/share/battray/battrayrc.py
- * /usr/local/share/examples/battray/battrayrc.py
- * /usr/share/battray/battrayrc.py
- * battrayrc.py
- * sys.path + /battray/battrayrc_default.py
-== Generic options ==
-_datadir_ (string)
-        Datadir to get icons and platform file from. Usually not
-        required.
-_pollInterval_ (int)
-        Poll the system every n seconds.
-== Available functions ==
-_charging()_
-        Return True if notebook is charging the battery
-_ac()_
-        Return True if notebook is connected to AC power
-_percent()_
-        Return percentage of battery time remaining
-_lifetime()_
-        Return remaining battery time in minutes
-_switchedto()_
-        Return 'battery' if we switched to battery since last poll.
-        'ac' if we  switched to ac since last poll.
-_run(cmd)_
-        Run cmd (string) in shell. Note: no escaping will be done on
-        the command.
-_play(sound)_
-        Play a sound. The path if relative to the datadir.
-_playonce(sound, id)_
-        Play a sound once until reset_playonce() is called for this id.
-        'id' can be any string.
-_playonce(id)_
-        Reset the playonce flag for the sound id
-== Available variables ==
-_icon = 'file.png'_
-        Set icon to this file. Can be relative to datadir
-_color = 'red|yellow|green'_
-        Fill battery icon with this color. Available are 'yellow', 'red',
-        and 'green'.
-_blink = True|False_
-        Set to True to blink the icon (Do not use is presence of
-        weeping angels!)
-= PLATFORM FILE =
-Battray gets its data from using a command-line utility provided by the
-Operating System. Almost every OS a slightly different utility and/or to
-fetch the battery status, this is why we need a platform file to imple-
-ment each platform.
-These files are imported (and reload()-ed when needed) by the main
-script. Any valid Python syntax goes.
-List of mandatory variables, these must be present:
-_ac_ (bool)
-        Connected to AC? None if unknown.
-_percent_ (int)
-        Battery power remaining in percent. 255 if unknown.
-_lifetime_ (int)
-        Battery time remaining in minutes. 255 if unknown.
-_charging_ (bool)
-        Are we charging the battery? None if unknown.
-Optional variables, these will just be ignored if not set:
-_tooltip_ (string)
-        Additional info in the tooltip.
-= BUGS =
- * Multiple batteries are not supported.
-= SEE ALSO =
-python(1), apm(8), acpidump(8), apm(4), acpi(4)
-= AUTHORS =
- * Martin Tournoij <mailto:martin@arp242.net>
- * Linux support by Andy Mikhaylenko <mailto:andy@neithere.net>
- * Keith W. Blackwell a.k.a. zimbot from freesound.org
-Feel free to use, modify, and redistribute battray as you see fit. There are no
-restrictions.

File doc/battray.t2t

-battray
-Martin Tournoij <martin@arp242.net>
-Battray 1.5
-
-%
-%!postproc(man): '@@' '\n'
-%!postproc(gwiki): '@@' '\n'
-%
-
-= NAME =
-Battray -- Display an battery status notification tray icon
-
-= SYNOPSIS =
-''' battray [-hv] [-p platform] [-d datadir] [-f configfile] [-i pol_interval]
-
-= DESCRIPTION =
-battray is a tray icon aka status icon to notify you of your battery status and do
-some action depending on it.
-
-      //-h//, -//-help//
-        Display help message and exit.
-
-      //-v//, //--version//
-        Display version and exit.
-
-      //-p//, //--platform//
-        Use this platform file, normally this is autodetected.
-        Will be imported, so make sure it's in sys.path
-
-      //-d//, //--datadir//
-        Datadir to get icons and platform file from.
-
-      //-f//, //--file//
-        Configuration file to use. A configuration file is mandatory.
-
-      //-i//, //--interval//
-        Poll the system every n seconds.
-
-= CONFIGURATION =
-The configuration file is imported in Python, any valid Python code goes.
-You don't need to specify your own configuration, a basic conservative
-configuration is included.
-
-== Location ==
-The configuration file will be searched in the following locations. The first
-match wins:
-
-- Specified from commandline
-- ~/.battray/battrayrc.py
-- ~/.battrayrc.py
-- /usr/local/etc/battrayrc.py
-- /usr/local/etc/battray/battrayrc.py
-- /etc/battrayrc.py
-- /etc/battray/battrayrc.py
-- /usr/local/share/battray/battrayrc.py
-- /usr/local/share/examples/battray/battrayrc.py
-- /usr/share/battray/battrayrc.py
-- battrayrc.py
-- sys.path + /battray/battrayrc_default.py
-
-
-== Generic options ==
-
-//datadir// (string)
-        Datadir to get icons and platform file from. Usually not
-        required.
-
-//pollInterval// (int)
-        Poll the system every n seconds.
-
-== Available functions ==
-
-//charging()//
-        Return True if notebook is charging the battery
-
-//ac()//
-        Return True if notebook is connected to AC power
-
-//percent()//
-        Return percentage of battery time remaining
-
-//lifetime()//
-        Return remaining battery time in minutes
-
-//switchedto()//
-        Return 'battery' if we switched to battery since last poll.
-        'ac' if we  switched to ac since last poll.
-
-//run(cmd)//
-        Run cmd (string) in shell. Note: no escaping will be done on
-        the command.
-
-//play(sound)//
-        Play a sound. The path if relative to the datadir.
-
-//playonce(sound, id)//
-        Play a sound once until reset_playonce() is called for this id.
-        'id' can be any string.
-
-//playonce(id)//
-        Reset the playonce flag for the sound id
-
-== Available variables ==
-
-//icon = 'file.png'//
-        Set icon to this file. Can be relative to datadir
-
-//color = 'red|yellow|green'//
-        Fill battery icon with this color. Available are 'yellow', 'red',
-        and 'green'.
-
-//blink = True|False//
-        Set to True to blink the icon (Do not use is presence of
-        weeping angels!)
-
-= PLATFORM FILE =
-Battray gets its data from using a command-line utility provided by the
-Operating System. Almost every OS a slightly different utility and/or to
-fetch the battery status, this is why we need a platform file to imple-
-ment each platform.
-
-These files are imported (and reload()-ed when needed) by the main
-script. Any valid Python syntax goes.
-
-List of mandatory variables, these must be present:
-
-
-//ac// (bool)
-        Connected to AC? None if unknown.
-
-//percent// (int)
-        Battery power remaining in percent. 255 if unknown.
-
-//lifetime// (int)
-        Battery time remaining in minutes. 255 if unknown.
-
-//charging// (bool)
-        Are we charging the battery? None if unknown.
-
-Optional variables, these will just be ignored if not set:
-
-
-//tooltip// (string)
-        Additional info in the tooltip.
-
-= BUGS =
-- Multiple batteries are not supported.
-
-
-= SEE ALSO =
-python(1), apm(8), acpidump(8), apm(4), acpi(4)
-
-= AUTHORS =
-- Martin Tournoij <martin@arp242.net>@@
-- Linux support by Andy Mikhaylenko <andy@neithere.net>
-- Keith W. Blackwell a.k.a. zimbot from freesound.org
-
-
-Feel free to use, modify, and redistribute battray as you see fit. There are no
-restrictions.
 	version = '1.5',
 	author = 'Martin Tournoij',
 	author_email = 'martin@arp242.net',
-	url = 'https://bitbucket.org/Carpetsmoker/battray',
+	url = 'https://code.arp242.net/battray',
 	description = '',
 	download_url = '',
 	classifiers = '',