File: prepare_debian.py

package info (click to toggle)
mrpt 1%3A1.4.0-7
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 65,000 kB
  • ctags: 84,479
  • sloc: cpp: 417,767; ansic: 95,106; xml: 3,792; python: 412; sh: 276; makefile: 225; ruby: 30
file content (203 lines) | stat: -rwxr-xr-x 7,186 bytes parent folder | download
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
#!/usr/bin/env python

import argparse
import os
import platform
import sys
import shutil
import subprocess

DEFAULT_MRPT_VERSION = '1:1.3.0-1'

# args
parser = argparse.ArgumentParser()
parser.add_argument('-b', '--build_dir', help='Path to the build directory.')
parser.add_argument('-m', '--mrpt_version', help='The MRPT lib version those bindings are generated from. DEFAULT: {}'.format(DEFAULT_MRPT_VERSION))
parser.add_argument('-a', '--architecture', required=True, help='The architecture the bindings are built for (i386, amd, armhf, etc.).')
args = parser.parse_args()

# check requirements
def check_required_program(program):
    try:
        subprocess.call(['which', program])
    except:
        print 'Required program "{}" not found.'.format(program)
        sys.exit(1)
print 'Looking for required programs:'
check_required_program('sudo')
check_required_program('dpkg')
check_required_program('chrpath')
check_required_program('lintian')

# get supplied build path, otherwise set default
if args.build_dir:
    build_dir = args.build_dir
else:
    build_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'build')

# save current dir
curr_dir = str(os.path.abspath(os.path.curdir))

# find pymrpt.so in build dir
built_lib = os.path.join(build_dir, 'lib', 'pymrpt.so')
if os.path.exists(os.path.join(built_lib)):
    print 'Found local build: "{}".'.format(built_lib)
else:
    print 'Could not find "pymrpt.so" in {}. Supply path to build directory as argument!'.format(build_dir)
    print 'Example: {} <path/to/build>'.format(sys.argv[0])
    print '\nExit.'
    sys.exit(1)

# TODO find version automatically
built_lib_version = args.mrpt_version if args.mrpt_version else DEFAULT_MRPT_VERSION
built_lib_size = os.path.getsize(built_lib)
built_lib_arch = args.architecture

# user home
home_dir = os.path.expanduser('~')

# packaging dir
pkg_dir = os.path.join(home_dir, 'mrpt-python-bindings')

# check if packaging dir exists
if os.path.exists(pkg_dir):
    cont = raw_input('Packaging dir already exists. Continue anyway? (y/N): ')
    if cont != 'y':
        print '\nExit.'
        sys.exit(0)
    # remove existing dir (utilizing sudo)
    try:
        command = 'rm -rf {}'.format(pkg_dir)
        subprocess.call(["/usr/bin/sudo", "sh", "-c", command])
    except:
        raise
    print 'Removed existing packaging dir.'

print 'Preparing:'
print '========='

# create packaging directory
os.mkdir(pkg_dir)
print 'Created packaging dir: "{}".'.format(pkg_dir)

# create DEBIAN directory
deb_dir = os.path.join(pkg_dir, 'DEBIAN')
os.mkdir(deb_dir)
print 'Created DEBIAN dir: "{}".'.format(deb_dir)

# create install directory (utilizing sudo)
inst_dir = os.path.join(pkg_dir, 'usr', 'lib', 'python2.7', 'dist-packages')
try:
    command = 'mkdir -p {}'.format(inst_dir)
    subprocess.call(["/usr/bin/sudo", "sh", "-c", command])
except:
    raise
print 'Created install dir: "{}".'.format(inst_dir)

# copy local built pymrpt.so to install dir (utilizing sudo)
command = 'cp {} {}'.format(built_lib, inst_dir)
subprocess.call(["/usr/bin/sudo", "sh", "-c", command])
print 'Copied library file: "{}" to "{}".'.format(built_lib, inst_dir)

# change file permissions
inst_so = os.path.join(inst_dir, 'pymrpt.so')
command = 'chmod 0644 {}'.format(inst_so)
subprocess.call(["/usr/bin/sudo", "sh", "-c", command])
print 'Changed "{}" permissions to: 0644.'.format(inst_so)

# remove rpath from shared lib
command = 'chrpath -d {}'.format(inst_so)
subprocess.call(["/usr/bin/sudo", "sh", "-c", command])
print 'Removed RPATH from "{}".'.format(inst_so)


# create control file
control_content = [
    'Package: mrpt-python-bindings',
    'Version: {}'.format(built_lib_version),
    'Architecture: {}'.format(built_lib_arch),
    'Maintainer: Peter Rudolph <semael23@gmail.com>',
    'Installed-Size: {}'.format(built_lib_size),
    'Depends: libmrpt-base1.3, libmrpt-slam1.3, libmrpt-obs1.3, libmrpt-maps1.3, libmrpt-nav1.3, libmrpt-opengl1.3, libmrpt-gui1.3, libboost-python1.54, libc6',
    'Section: devel',
    'Priority: optional',
    'Homepage: http://www.mrpt.org',
    'Description: MRPT python bindings.',
    ' This package contains the python bindings for',
    ' the Mobile Robot Programming Toolkit (MRPT).',
    '' # final new line
]
control_filename = os.path.join(pkg_dir, 'DEBIAN', 'control')
control_file = open(control_filename, 'w+')
control_file.write('\n'.join(control_content))
control_file.close()
print 'Created control file: "{}".'.format(control_filename)


# create copyright file
copyright_content = [
    'Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/',
    'Upstream-Name: mrpt-python-bindings',
    'Upstream-Contact: Peter Rudolph <semael23@gmail.com>',
    'Source: https://github.com/jlblancoc/mrpt',
    '',
    'Files: *',
    'Copyright: 2014-2015 Peter Rudolph',
    'License: Expat',
    '',
    'License: Expat',
    ' Permission is hereby granted, free of charge, to any person obtaining a copy',
    ' of this software and associated documentation files (the "Software"), to deal',
    ' in the Software without restriction, including without limitation the rights',
    ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell',
    ' copies of the Software, and to permit persons to whom the Software is',
    ' furnished to do so, subject to the following conditions:',
    ' ',
    ' The above copyright notice and this permission notice shall be included in',
    ' all copies or substantial portions of the Software.',
    ' ',
    ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR',
    ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,',
    ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE',
    ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER',
    ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,',
    ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN',
    ' THE SOFTWARE.',
    '',
]
copyright_filename = os.path.join(pkg_dir, 'DEBIAN', 'copyright')
copyright_file = open(copyright_filename, 'w+')
copyright_file.write('\n'.join(copyright_content))
copyright_file.close()
print 'Created copyright file: "{}".'.format(copyright_filename)

# TODO use auto-generated changelog
changelog_content = [
    'python-mrpt-bindings ({}) unstable; urgency=low'.format(built_lib_version),
    '',
    '  * Initial Release.',
    '',
    ' -- Peter Rudolph <semael23@gmail.com>  Tue, 20 Jan 2015 12:30:54 +0100',
    '',
]
changelog_filename = os.path.join(pkg_dir, 'DEBIAN', 'changelog')
changelog_file = open(changelog_filename, 'w+')
changelog_file.write('\n'.join(changelog_content))
changelog_file.close()
print 'Created changelog file: "{}".'.format(changelog_filename)


os.chdir(home_dir)

# build the package
print 'Build package:'
subprocess.call(['dpkg', '-b', 'mrpt-python-bindings'])

# check package with lintian
print 'Check package:'
subprocess.call(['lintian', os.path.join(home_dir, 'mrpt-python-bindings.deb')])

# go to initial dir
os.chdir(curr_dir)

print 'Done.'