The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

install.py

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of install.py.
Create a library of the Graphics Gems code
1 #!/usr/bin/python 2 """ 3 Copyright (C) 2013 2014 2015 Johan Mattsson 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 """ 18 19 import os 20 import subprocess 21 import glob 22 import platform 23 from optparse import OptionParser 24 from scripts import config 25 from scripts import version 26 from scripts.run import run 27 28 def getDest (file, dir): 29 f = dest + prefix + dir + '/' 30 s = file.rfind ('/') 31 if s > -1: 32 f += file[s + 1:] 33 else: 34 f += file 35 return f 36 37 def getDestRoot (file, dir): 38 f = dest + dir + '/' 39 s = file.rfind ('/') 40 if s > -1: 41 f += file[s + 1:] 42 else: 43 f += file 44 return f 45 46 def install (file, dir, mode): 47 f = getDest (file, dir) 48 print ("install: " + f) 49 run ('install -d ' + dest + prefix + dir) 50 run ('install -m ' + `mode` + ' ' + file + ' ' + dest + prefix + dir + '/') 51 installed.write (f + "\n") 52 53 def install_root (file, dir, mode): 54 f = getDestRoot (file, dir) 55 print ("install: " + f) 56 run ('install -d ' + dest + dir) 57 run ('install -m ' + `mode` + ' ' + file + ' ' + dest + dir + '/') 58 59 def link (dir, file, linkname): 60 f = getDest (linkname, dir) 61 print ("install link: " + f) 62 run ('cd ' + dest + prefix + dir + ' && ln -sf ' + file + ' ' + linkname) 63 installed.write (f + "\n") 64 65 if not os.path.exists ("build/configured"): 66 print ("Project is not configured") 67 exit (1) 68 69 parser = OptionParser() 70 parser.add_option ("-d", "--dest", dest="dest", help="install to this directory", metavar="DEST") 71 parser.add_option ("-m", "--nogzip", dest="nogzip", help="don't gzip manpages", default=False) 72 parser.add_option ("-n", "--manpages-directory", dest="mandir", help="put man pages in this directory under prefix") 73 parser.add_option ("-l", "--libdir", dest="libdir", help="path to directory for shared libraries (lib or lib64).") 74 parser.add_option ("-c", "--skip-command-line-tools", dest="nocli", help="don't install command line tools") 75 parser.add_option ("-a", "--apport", dest="apport", help="install apport scripts", default=True) 76 77 (options, args) = parser.parse_args() 78 79 if not options.dest: 80 options.dest = "" 81 82 if not options.nocli: 83 options.nocli = False 84 85 nogzip = options.nogzip 86 87 if not options.mandir: 88 mandir = "/man/man1" 89 else: 90 mandir = options.mandir 91 92 prefix = config.PREFIX 93 dest = options.dest 94 95 # create uninstall file 96 installed = open ('build/installed', 'w') 97 installed.write ('build/installed\n') 98 99 # install it: 100 install ('resources/icons.bf', '/share/birdfont', 644) 101 install ('resources/bright.theme', '/share/birdfont', 644) 102 install ('resources/dark.theme', '/share/birdfont', 644) 103 install ('resources/high_contrast.theme', '/share/birdfont', 644) 104 install ('resources/key_bindings.xml', '/share/birdfont', 644) 105 install ('resources/roboto.bf', '/share/birdfont', 644) 106 install ('resources/linux/birdfont_window_icon.png', '/share/birdfont', 644) 107 install ('resources/linux/birdfont.desktop', '/share/applications', 644) 108 109 install ('resources/linux/256x256/birdfont.png', '/share/icons/hicolor/256x256/apps', 644) 110 install ('resources/linux/128x128/birdfont.png', '/share/icons/hicolor/128x128/apps', 644) 111 install ('resources/linux/48x48/birdfont.png', '/share/icons/hicolor/48x48/apps', 644) 112 113 install ('resources/linux/birdfont.appdata.xml', '/share/appdata', 644) 114 115 if os.path.isfile ('build/bin/birdfont'): 116 install ('build/bin/birdfont', '/bin', 755) 117 118 if not options.nocli: 119 install ('build/bin/birdfont-autotrace', '/bin', 755) 120 install ('build/bin/birdfont-export', '/bin', 755) 121 install ('build/bin/birdfont-import', '/bin', 755) 122 123 #library 124 if not options.libdir: 125 126 if platform.dist()[0] == 'Ubuntu' or platform.dist()[0] == 'Debian': 127 process = subprocess.Popen(['dpkg-architecture', '-qDEB_HOST_MULTIARCH'], stdout=subprocess.PIPE) 128 out, err = process.communicate() 129 libdir = '/lib/' + out.rstrip ('\n') 130 else: 131 p = platform.machine() 132 if p == 'i386' or p == 's390' or p == 'ppc' or p == 'armv7hl': 133 libdir = '/lib' 134 elif p == 'x86_64' or p == 's390x' or p == 'ppc64': 135 libdir = '/lib64' 136 else: 137 libdir = '/lib' 138 else: 139 libdir = options.libdir 140 141 if os.path.isfile ('build/bin/libbirdfont.so.' + version.SO_VERSION): 142 install ('build/bin/libbirdfont.so.' + version.SO_VERSION, libdir, 644) 143 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so.' + version.SO_VERSION_MAJOR) 144 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so') 145 elif os.path.isfile ('build/libbirdfont.so.' + version.SO_VERSION): 146 install ('build/libbirdfont.so.' + version.SO_VERSION, libdir, 644) 147 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so.' + version.SO_VERSION_MAJOR) 148 link (libdir, 'libbirdfont.so.' + version.SO_VERSION, ' libbirdfont.so') 149 elif os.path.isfile ('build/bin/libbirdfont.' + version.SO_VERSION + '.dylib'): 150 install ('build/bin/libbirdfont.' + version.SO_VERSION + '.dylib', libdir, 644) 151 link (libdir, 'libbirdfont.' + version.SO_VERSION + '.dylib', ' libbirdfont.dylib.' + version.SO_VERSION_MAJOR) 152 link (libdir, 'libbirdfont.' + version.SO_VERSION + '.dylib', ' libbirdfont.dylib') 153 else: 154 print ("Can't find libbirdfont.") 155 exit (1) 156 157 if os.path.isfile ('build/bin/libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION): 158 install ('build/bin/libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, libdir, 644) 159 link (libdir, 'libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, ' libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION_MAJOR) 160 link (libdir, 'libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, ' libbirdxml.so') 161 elif os.path.isfile ('build/libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION): 162 install ('build/libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, libdir, 644) 163 link (libdir, 'libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, ' libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION_MAJOR) 164 link (libdir, 'libbirdxml.so.' + version.LIBBIRDXML_SO_VERSION, ' libbirdxml.so') 165 elif os.path.isfile ('build/bin/libbirdxml.' + version.LIBBIRDXML_SO_VERSION + '.dylib'): 166 install ('build/bin/libbirdxml.' + version.LIBBIRDXML_SO_VERSION + '.dylib', libdir, 644) 167 link (libdir, 'libbirdxml.' + version.LIBBIRDXML_SO_VERSION + '.dylib', ' libbirdxml.dylib.' + version.LIBBIRDXML_SO_VERSION_MAJOR) 168 link (libdir, 'libbirdxml.' + version.LIBBIRDXML_SO_VERSION + '.dylib', ' libbirdxml.dylib') 169 else: 170 print ("Can't find libbirdxml.") 171 exit (1) 172 173 174 if os.path.isfile ('build/bin/libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION): 175 install ('build/bin/libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, libdir, 644) 176 link (libdir, 'libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, ' libbirdgems.so.' + version.LIBBIRDXML_SO_VERSION_MAJOR) 177 link (libdir, 'libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, ' libbirdgems.so') 178 elif os.path.isfile ('build/libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION): 179 install ('build/libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, libdir, 644) 180 link (libdir, 'libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, ' libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION_MAJOR) 181 link (libdir, 'libbirdgems.so.' + version.LIBBIRDGEMS_SO_VERSION, ' libbirdgems.so') 182 elif os.path.isfile ('build/bin/libbirdgems.' + version.LIBBIRDGEMS_SO_VERSION + '.dylib'): 183 install ('build/bin/libbirdgems.' + version.LIBBIRDGEMS_SO_VERSION + '.dylib', libdir, 644) 184 link (libdir, 'libbirdgems.' + version.LIBBIRDGEMS_SO_VERSION + '.dylib', ' libbirdgems.dylib.' + version.LIBBIRDGEMS_SO_VERSION_MAJOR) 185 link (libdir, 'libbirdgems.' + version.LIBBIRDGEMS_SO_VERSION + '.dylib', ' libbirdgems.dylib') 186 else: 187 print ("Can't find libbirdgems.") 188 exit (1) 189 190 191 #manpages 192 193 if not nogzip: 194 install ('build/birdfont.1.gz', mandir, 644) 195 196 if not options.nocli: 197 install ('build/birdfont-autotrace.1.gz', mandir, 644) 198 install ('build/birdfont-export.1.gz', mandir, 644) 199 install ('build/birdfont-import.1.gz', mandir, 644) 200 else: 201 install ('resources/linux/birdfont.1', mandir, 644) 202 203 if not options.nocli: 204 install ('resources/linux/birdfont-autotrace.1', mandir, 644) 205 install ('resources/linux/birdfont-export.1', mandir, 644) 206 install ('resources/linux/birdfont-import.1', mandir, 644) 207 208 #translations 209 for lang_dir in glob.glob('build/locale/*'): 210 lc = lang_dir.replace ('build/locale/', "") 211 install ('build/locale/' + lc + '/LC_MESSAGES/birdfont.mo', '/share/locale/' + lc + '/LC_MESSAGES' , 644); 212 213 #file type 214 install ('resources/linux/birdfont.xml', '/share/mime/packages', 644) 215 216 #apport hooks 217 if options.apport == "True": 218 install ('resources/birdfont.py', '/share/apport/package-hooks', 644) 219 install ('resources/source_birdfont.py', '/share/apport/package-hooks', 644) 220 install_root ('resources/birdfont-crashdb.conf', '/etc/apport/crashdb.conf.d', 644) 221 222 installed.close () 223