[go: up one dir, main page]

Menu

[r61]: / trunk / setup.py  Maximize  Restore  History

Download this file

216 lines (194 with data), 8.4 kB

  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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# setup.py
#
# Copyright 2010 Sandro Mani <manisandro.gmail.com>
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import glob, os, sys, fileinput, errno, time, subprocess, platform
from distutils.core import setup
# Change to the path where this file is
os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
########################### SETUP VARIABLES ############################
_name = "gimagereader"
_version = '0.6'
_release = '1'
_mantainer = 'Sandro Mani'
_mantainer_email = 'manisandro@gmail.com'
########################## UTILITY FUNCTIONS ###########################
def mkdirs(path):
try: os.makedirs(path)
except OSError as exc:
if exc.errno==errno.EEXIST: pass
else: raise
##################### CHANGELOG PARSING FUNCTIONS ######################
def parseChangeLog(file,formatter):
field=0;
data=['','','','']
output='';
for line in fileinput.input([file]):
if field==3:
if line!="\n":
data[3]+=line
else:
output+=formatter(data)
data[3]=''
field=0
else:
data[field]=line.replace('\n','')
field+=1
if field==3 and data[3]!='':
output+=formatter(data)
return output
def RPMFormatter(data):
date=data[2].split(' ')
return '* '+date[0][:-1]+' '+date[2]+' '+date[1]+' '+date[3]+' '+data[1]+' '+data[0]+'\n - '+data[3][:-1].replace('\n','\n - ')+'\n'
def DEBFormatter(data):
return _name+' ('+data[0]+') UNRELEASED; urgency=low\n * '+data[3][:-1].replace('\n','\n * ')+'\n -- '+data[1]+' '+data[2]+'\n\n'
############### SPECIALIZATIONS FOR RPM AND DEB PACKAGES ###############
package='none'
opts={}
if len(sys.argv)>=2:
if sys.argv[1]=="bdist_rpm":
package='RPM'
sys.argv.append('--release='+_release+'%{dist}')
sys.argv.append('--group=Applications/Productivity')
sys.argv.append('--vendor=Sandro Mani <manisandro@gmail.com>')
sys.argv.append('--packager='+_mantainer+' <'+_mantainer_email+'>')
sys.argv.append('--requires=%{name} = %{version}-%{release}, tesseract, ImageMagick, pygtk2, pycairo, gnome-python2-gtkspell, ghostscript')
sys.argv.append('--provides=%{name}-static = %{version}-%{release}')
sys.argv.append('--changelog='+parseChangeLog('ChangeLog.in',RPMFormatter))
print parseChangeLog('ChangeLog.in',RPMFormatter)
elif sys.argv[1]=="bdist_deb":
package='DEB'
builddir='build/bdist.linux-'+platform.machine()+'/deb'
mkdirs(builddir+'/DEBIAN')
try: changelog=open(builddir+'/DEBIAN/changelog','w')
except: raise
changelog.write(parseChangeLog('ChangeLog.in',DEBFormatter))
changelog.close()
# DEBIAN/control is below to also determine installed-size
copyright=open('deb/copyright.in');
copyrighttxt='This package was debianized by '+_mantainer+' <'+_mantainer_email+'>\n on '+time.strftime('%a, %d %b %Y %H:%M:%S %z')+'\n'+copyright.read()
copyright.close()
try: copyright=open(builddir+'/DEBIAN/copyright','w')
except: raise
copyright.write(copyrighttxt)
copyright.close()
sys.argv[1]='install'
sys.argv.append('--root')
sys.argv.append(builddir)
elif sys.argv[1]=="py2exe":
package='EXE'
try: import py2exe
except:
print "py2exe modules not found, please install them and try again."
sys.exit(0)
if not os.path.isdir("win32/gtklib"):
print "Missing win32 folder. Please download gimagereader-win32-support-<version>.zip from the project website and extract it, see INSTALL."
sys.exit(0)
opts = {"py2exe": {
"dist_dir" : "build/bdist.win32/dist",
"skip_archive" : 1,
"includes": "atk, cairo, ConfigParser, ctypes, gettext, gobject, gtk, gio, json, locale, math, os, pango, pangocairo, re, subprocess, sys, tempfile, threading, urllib2",
"dll_excludes": [
"iconv.dll","intl.dll","libatk-1.0-0.dll","libcairo-2.dll",
"libexpat-1.dll","libfontconfig-1.dll",
"libgio-2.0-0.dll","libpangocairo-1.0-0.dll",
"libpangoft2-1.0-0.dll","libpng14-14.dll",
"libgdk_pixbuf-2.0-0.dll","libgdk-win32-2.0-0.dll",
"libglib-2.0-0.dll","libgmodule-2.0-0.dll",
"libgobject-2.0-0.dll","libgthread-2.0-0.dll",
"libgtk-win32-2.0-0.dll","libpango-1.0-0.dll",
"libpangowin32-1.0-0.dll"]
}}
############################## MAIN PART ###############################
data = []
for filepath in glob.glob("src/locale/*/LC_MESSAGES/"):
data.append((filepath.replace('src/locale', 'share/locale'),[filepath+"gimagereader.mo"]))
data.append(('share/applications',['xdg/gnome-gimagereader.desktop']))
data.append(('share/pixmaps',['src/gimagereader.svg']))
data.append(('share/doc/'+_name+'-'+_version,['README','COPYING','AUTHORS','ChangeLog','TODO','src/manual.html']))
data.append(('share/man/man1',['man/gimagereader.1.gz']))
dist = setup(
scripts = ['bin/gimagereader'],
packages = ['gimagereader'],
package_dir = {'gimagereader':'src'},
package_data = {'gimagereader':['gimagereader.xml','gimagereader.svg','stripcrlf.svg','manual.html']},
data_files = data,
name = _name,
version = _version,
author = "Sandro Mani",
author_email = "manisandro@gmail.com",
maintainer = "Sandro Mani",
maintainer_email = "manisandro@gmail.com",
url = "http://www.sourceforge.com/projects/gimagereader",
license = "GPLv3+",
description = "A tesseract-ocr frontend",
long_description = "A graphical PyGTK front-end to tesseract-ocr",
# console = ["bin/gimagereader"],
windows = [{"script": "bin/gimagereader","icon_resources": [(1, "win32/gimagereader.ico")]}],
options=opts,
classifiers = [
'Development Status :: 4 - Beta',
'Environment :: X11 Applications',
'Environment :: X11 Applications :: GTK',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Topic :: Multimedia :: Graphics'
'Topic :: Multimedia :: Graphics :: Graphics Conversion',
'Natural Language :: English',
'Natural Language :: German',
'Natural Language :: Italian',
'Natural Language :: French']
)
if package=='DEB':
builddir
size = 0
for (path, dirs, files) in os.walk(builddir):
for file in files:
size += os.path.getsize(os.path.join(path, file))
control=open('deb/control.in');
controltxt='Version: '+_version+'-'+_release+'\nInstalled-Size: '+str(int(round(size/1024)))+'\n'+control.read()
control.close()
try: control=open(builddir+'/DEBIAN/control','w')
except: raise
control.write(controltxt)
control.close()
mkdirs('dist')
try:
subprocess.call(['dpkg', '-b', builddir, 'dist/'+_name+'_'+_version+'-'+_release+'_all.deb'])
except:
print "Failed to call dpkg, is it installed?"
elif package=='EXE': # Workaround py2exe ignoring package_data
import shutil
print "*** copying package_data ***"
shutil.copyfile('src/gimagereader.xml','build/bdist.win32/dist/gimagereader/gimagereader.xml')
shutil.copyfile('src/gimagereader.svg','build/bdist.win32/dist/gimagereader/gimagereader.svg')
shutil.copyfile('src/stripcrlf.svg','build/bdist.win32/dist/gimagereader/stripcrlf.svg')
shutil.copyfile('src/manual.html','build/bdist.win32/dist/gimagereader/manual.html')
if not os.path.isdir('build/bdist.win32/dist/gimagereader/locale'):
shutil.copytree('src/locale','build/bdist.win32/dist/gimagereader/locale')
mkdirs('dist')
try:
subprocess.call(['makensis', 'win32\installer.nsi'])
shutil.move('win32/gimagereader-installer.exe','dist/'+_name+'_'+_version+'-'+_release+'_win32.exe')
except:
print "Failed to call makensis, is it installed and in path?"