/gtk/prep-images

To get this branch, use:
bzr branch http://bzr.ed.am/gtk/prep-images
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python

# prep-images
#
# Copyright (C) 2011 Tim Marston <edam@waxworlds.org>
#
# This file is part of prep-images (hereafter referred to as "this program").
# See http://www.waxworlds.org/edam/software/gtk/prep-images for more
# information.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# @PACKAGE_NAME@ version @PACKAGE_VERSION@

import sys, os
from os.path import join, abspath, exists
import getopt


# check for a development source directory and use that if it's there
PACKAGE_DIR = join( abspath( sys.path[ 0 ] ), "..", "lib" )
if exists( join( PACKAGE_DIR, "prep_images", "prefs_dialog.py" ) ):
	print >> sys.stderr, "!!! using development packages !!!"
	sys.path.insert( 0, PACKAGE_DIR )
else:
	del PACKAGE_DIR


def usage( error = True ):
	print >> sys.stderr, 'Try "@PACKAGE_NAME@ --help" for help'
	exit( 1 )


def help():
	print "Usage: @PACKAGE_NAME@ [OPTION]... FILE..."
	print
	print "Prepare the specified image FILEs for publishing."
	print
	print "Options:"
	print "     --help     display this help and exit"
	print "     --version  output version information and exit"
	exit( 0 )


def version():
	print "@PACKAGE_NAME@ @PACKAGE_VERSION@"
	print
	print "Copyright (C) 2011 to 2013 Tim Marston"
	print "License GPLv3+: GNU GPL version 3 or later " + \
	    "<http://gnu.org/licenses/gpl.html>"
	print "This is free software: you are free to change and " + \
	    "redistribute it."
	print
	print "For more information, including documentation, see the " +\
	    "project website, at"
	print "<@PACKAGE_URL@>. Please report bugs to <@PACKAGE_BUGREPORT@>."
	exit( 0 )


# handle command line
try:
	opts, args = getopt.gnu_getopt(
		sys.argv[ 1: ], "",
		[ "help", "version" ] )
except getopt.GetoptError as e:
	print str( e )
	usage()

# process options
for opt, args in opts:
	if opt == "--help":
		help()
	elif opt == "--version":
		version()
	else:
		print >> sys.stderr, "unknown option"
		usage()

# check for files
if len( args ) == 0:
	print >> sys.stderr, "no files specified"
	usage()

# try to detect no DISPLAY
if os.getenv( 'DISPLAY', '' ) == '':
	print >> sys.stderr, 'could not open display'
	exit( 1 )

# we only now import the main window stuff, because it pulls in PyGTK which
# complains if it can't connect to a display
from prep_images.main_window import *

# process each image in turn
for filename in args:
	MainWindow( filename ).main()