2
# vim:se tw=0 sts=4 ts=4 et ai:
3
import os, re, sys, glob
4
import debmake.copyright
7
Copyright © 2013 Osamu Aoki
9
Permission is hereby granted, free of charge, to any person obtaining a
10
copy of this software and associated documentation files (the "Software"),
11
to deal in the Software without restriction, including without limitation
12
the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
and/or sell copies of the Software, and to permit persons to whom the
14
Software is furnished to do so, subject to the following conditions:
16
The above copyright notice and this permission notice shall be included
17
in all copies or substantial portions of the Software.
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
#######################################################################
31
source_local_options(para)
46
print('I: run "debmake -x" to get more template files', file=sys.stderr)
47
if os.getcwd() != para['cwd']:
48
print('I: upon return to the shell, current directory becomes {}'.format(para['cwd']), file=sys.stderr)
49
print('I: please execute "cd {0}"'.format(os.getcwd()), file=sys.stderr)
50
print('I: before building binary package with dpkg-buildpackage (or debuild, pdebuild, sbuild, ...).', file=sys.stderr)
53
#######################################################################
56
return os.makedirs(path, exist_ok=True)
58
#######################################################################
59
# cat >file and cat >>file
60
def writefile(para, file, text, append=False, end='\n'):
64
if not para['overwrite'] and os.path.isfile(file) and os.stat(file).st_size != 0:
65
# skip if a file exists and non-zero content
66
print('I: File already exits, skipping: {}'.format(file), file=sys.stderr)
69
print(text, file=f, end=end)
71
print('I: File written: {} (append)'.format(file), file=sys.stderr)
73
print('I: File written: {}'.format(file), file=sys.stderr)
77
#######################################################################
79
def subst(para, text):
81
'@PACKAGE@': para['package'],
82
'@UCPACKAGE@': para['package'].upper(),
83
'@YEAR@': para['year'],
84
'@FULLNAME@': para['fullname'],
85
'@EMAIL@': para['email'],
86
'@SHORTDATE@': para['shortdate'],
88
for k in subst.keys():
89
text = text.replace(k, subst[k])
92
#######################################################################
96
for root, dirname, filenames in os.walk('./'):
97
if dirname[:6] != 'debian':
98
for filename in filenames:
99
matches.append(os.path.join(root, dirname, filename))
102
#######################################################################
103
def source_format(para):
104
mkdirp('debian/source')
106
writefile(para, 'debian/source/format', '3.0 (native)')
108
writefile(para, 'debian/source/format', '3.0 (quilt)')
111
#######################################################################
112
def source_local_options(para):
113
mkdirp('debian/source')
115
#### Uncomment some of the following lines if you wish :-) See dpkg-source(1)
117
#abort-on-upstream-changes
119
writefile(para, 'debian/source/local-options', msg)
122
#######################################################################
123
def patches_series(para):
124
mkdirp('debian/patches')
126
# This is manually managed by users with dquilt (quilt(1) wrapper)
127
# See http://www.debian.org/doc/manuals/maint-guide/modify.en.html#quiltrc
128
# Also this may be updated by dpkg-source(1) when making a package.
130
writefile(para, 'debian/patches/series', msg)
133
#######################################################################
136
writefile(para, 'debian/compat', msg)
139
#######################################################################
141
if len(para['debs']) == 1:
142
p = para['debs'][0]['package'] # first binary package name
145
build_dir = 'debian/' + p
146
###################################################################
147
# build_mode independent portion
150
# uncomment to enable verbose mode for debhelper
152
# uncomment to exclude VCS paths
153
#DH_ALWAYS_EXCLUDE=CVS:.svn:.git
158
###################################################################
159
# dh $@: main build script of debhelper v9
160
if para['dh_with'] == set([]):
161
msg += '\tdh $@\n' # no dh_with
163
msg += '\tdh $@ --with "{}"\n'.format(','.join(para['dh_with']))
165
###################################################################
166
# override build script of debhelper v9
167
###################################################################
168
if 'python3' in para['dh_with']:
169
# line tail // are meant to be / in debian/rule
170
# make sure to keep tab code for each line (make!)
173
# special work around for python3 (#538978 and #597105 bugs)
174
PY3REQUESTED := $(shell py3versions -r)
175
PY3DEFAULT := $(shell py3versions -d)
176
PYTHON3 := $(filter-out $(PY3DEFAULT),$(PY3REQUESTED)) python3
178
override_dh_auto_clean:
181
override_dh_auto_build:
182
set -ex; for python in $(PYTHON3); do \\
183
$$python setup.py build; \\
186
override_dh_auto_install:
187
set -ex; for python in $(PYTHON3); do \\
188
$$python setup.py install \\
189
--root=''' + build_dir + '''\\
190
--install-layout=deb; \\
193
msg += '\n# Customize by adding override scripts\n'
194
###################################################################
196
###################################################################
197
writefile(para, 'debian/rules', msg)
200
#######################################################################
201
def README_Debian(para):
202
sep = '-' * (len(para['package']) + 11)
207
Please edit this to provide information specific information on
208
this {0} Debian package.
210
(Automatically generated by {2} Version {3})
216
para['program_name'],
217
para['program_version'],
221
###################################################################
223
writefile(para, 'debian/README.Debian', msg)
226
#######################################################################
230
{0} ({1}) UNRELEASED; urgency=low
232
* Initial release. Closes: #nnnn
233
<nnnn is the bug number of your ITP>
244
{0} ({1}-{2}) UNRELEASED; urgency=low
246
* Initial release. Closes: #nnnn
247
<nnnn is the bug number of your ITP>
257
###################################################################
259
writefile(para, 'debian/changelog', msg)
261
#######################################################################
263
file = 'debian/control'
264
if not para['overwrite'] and os.path.isfile(file) and os.stat(file).st_size != 0:
265
print('I: File already exits, skipping: {}'.format(file), file=sys.stderr)
268
msg = control_src(para)
269
for deb in para['debs']:
270
msg += control_bin(para, deb)
271
writefile(para, 'debian/control', msg)
274
#######################################################################
275
def control_src(para):
280
Maintainer: {3} <{4}>
282
Standards-Version: {6}
292
',\n\t'.join(para['build_depends']),
293
para['standard_version'],
295
guess_vcsvcs(para['vcsvcs']),
297
guess_vcsbrowser(para['vcsbrowser']),
299
if 'python2' in para['dh_with']:
300
msg += 'X-Python-Version: >= 2.6\n'
301
if 'python3' in para['dh_with']:
302
msg += 'X-Python3-Version: >= 3.2\n'
303
# anythong for perl and others XXX FIXME XXX
305
###################################################################
308
#######################################################################
309
def guess_vcsvcs(vcsvcs):
310
if re.search('\.git$', vcsvcs):
312
elif re.search('\.hg$', vcsvcs):
314
elif re.search('^:pserver:', vcsvcs):
315
# CVS :pserver:anonymous@anonscm.debian.org:/cvs/webwml
317
elif re.search('^:ext:', vcsvcs):
318
# CVS :ext:username@cvs.debian.org:/cvs/webwml
320
elif re.search('^svn[:+]', vcsvcs):
321
# SVN svn://svn.debian.org/ddp/manuals/trunk manuals
322
# SVN svn+ssh://svn.debian.org/svn/ddp/manuals/trunk
327
#######################################################################
328
def guess_vcsbrowser(vcsbrowser):
329
if re.search('\.git$', vcsbrowser):
331
elif re.search('\.hg$', vcsbrowser):
333
elif re.search('^:pserver:', vcsbrowser):
334
# CVS :pserver:anonymous@anonscm.debian.org:/cvs/webwml
336
elif re.search('^:ext:', vcsbrowser):
337
# CVS :ext:username@cvs.debian.org:/cvs/webwml
339
elif re.search('^svn[:+]', vcsbrowser):
340
# SVN svn://svn.debian.org/ddp/manuals/trunk manuals
341
# SVN svn+ssh://svn.debian.org/svn/ddp/manuals/trunk
344
return '#Vcs-Browser'
346
#######################################################################
347
def control_bin(para, deb):
358
',\n\t'.join(deb['depends']),
374
',\n\t'.join(deb['pre-depends']),
375
',\n\t'.join(deb['depends']),
380
#######################################################################
382
###################################################################
383
# Write copyright and license
384
# using writefile(para, file, text, append=False)
385
###################################################################
387
if not para['overwrite'] and os.path.isfile('debian/copyright') and os.stat('debian/copyright').st_size != 0:
388
print('I: File already exits, skipping: {}'.format('debian/copyright'), file=sys.stderr)
390
# get scan result of copyright
391
(bdata, nonlink_files, binary_files, huge_files) = debmake.copyright.scan_copyright_data()
394
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
396
Source: <url://example.com>
398
'''.format(para['package'])
400
text += '#----------------------------------------------------------------------------\n'
401
text += 'Files: {}\n'.format('\n\t'.join(bd[1]))
404
for name in bd[2].keys():
406
if bd[2][name][0] == bd[2][name][1]:
407
if bd[2][name][1] == 0: # max == 0 for binary etc.
408
text += ' {}\n'.format(name) # XXXXX FIXME
410
text += ' {} {}\n'.format(bd[2][name][0], name)
412
if bd[2][name][1] == 0: # max == 0 means not found
413
text += ' {}\n'.format(name)
415
text += ' {}-{} {}\n'.format(bd[2][name][0], bd[2][name][1], name)
417
text += 'License: NO_LICENSE_TEXT_FOUND\n\n'
419
text += 'License:\n {}\n'.format(debmake.copyright.format_license(bd[3]))
422
text += '#............................................................................\n'
423
text += '# Gray hits with matching text of "copyright":\n'
425
if binary_files != []:
426
text += '#----------------------------------------------------------------------------\n'
427
text += '# Binary files (skipped):\n# {}\n\n'.format('\n# '.join(binary_files))
429
text += '#----------------------------------------------------------------------------\n'
430
text += '# Huge files (skipped):\n# {}\n\n'.format('\n# '.join(huge_files))
432
#----------------------------------------------------------------------------
433
# This is meant only as a template example.
435
# Edit this accordinng to the "Machine-readable debian/copyright file" as
436
# http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ .
438
# Generate typical license templates with the "debmake -x" and merge them
439
# into here as needed. See "man 8 debmake" for more.
441
# Please avoid to pick license terms that are more restrictive than the
442
# packaged work, as it may make Debian's contributions unacceptable upstream.
445
for f in debmake.copyright.license_files(para):
446
text += '#----------------------------------------------------------------------------\n'
447
text += '# License: {}\n'.format(f)
448
text += debmake.copyright.license_text(f)
451
writefile(para, 'debian/copyright', text)
454
#######################################################################
456
for file in glob.glob(para['base_path'] + '/share/debmake/extra/*'):
457
with open(file, 'r') as f:
460
'debian/' + os.path.basename(file),
464
#######################################################################
465
#debs =[{'package': p,
470
# 'desc_long': desc_long,
472
# 'pre-depends': pd}, ...}
473
#######################################################################
475
#text = '# see dh_install'
476
for deb in para['debs']:
477
if deb['type'] == 'lib':
478
text = 'lib/\nusr/lib/\n'
479
elif deb['type'] == 'bin' or deb['type'] == 'script':
480
text = 'bin/\nusr/bin/\nsbin/\nusr/sbin/\n'
481
elif deb['type'] == 'data':
482
text = 'usr/share/' + para['package'] + '/\n'
486
'debian/' + deb['package'] +'.install',
490
#######################################################################
491
def installdocs(para):
492
#text = '# see dh_install'
493
for deb in para['debs']:
494
if deb['type'] == 'doc':
495
text = 'usr/share/doc/' + deb['package'] + '/\n'
497
'debian/' + deb['package'] +'.docs',
501
#######################################################################
503
for deb in para['debs']:
504
if deb['type'] == 'doc':
507
Title: Debian {1} Manual
508
Author: <insert document author here>
509
Abstract: This manual describes what {1} is
510
and how it can be used to
511
manage online manuals on Debian systems.
515
Files: /usr/share/doc/{0}/{1}.pdf.gz
518
Files: /usr/share/doc/{0}/{1}.text.gz
521
Index: /usr/share/doc/{0}/html/index.html
522
Files: /usr/share/doc/{0}/html/*.html
523
'''.format(deb['package'], para['package'])
525
'debian/' + deb['package'] +'.doc-base',
529
#######################################################################
531
for deb in para['debs']:
532
if deb['type'] == 'bin':
533
text = '# See dh_installman(1)\n'
535
'debian/' + deb['package'] +'.manpages',
539
#######################################################################
541
#######################################################################
542
if __name__ == '__main__':
544
para['package'] = 'package'
545
para['year'] = '9999'
546
para['fullname'] = 'fullname'
547
para['email'] = 'foo@example.org'
548
para['shortdate'] = '1919-12-19'
549
text = '@PACKAGE@ @UCPACKAGE@ @YEAR@ @USERNAME@ @EMAIL@ @SHORTDATE@'
550
print(subst(para, text))