Update .travis.yml
[appimagekit/gsi.git] / AppImageAssistant.AppDir / package
blob08ee29d458b1372c6103b081204adeee368ce8aa
1 #!/usr/bin/env python
3 # /**************************************************************************
4 #
5 # Copyright (c) 2005-12 Simon Peter
6 #
7 # All Rights Reserved.
8 #
9 # Permission is hereby granted, free of charge, to any person obtaining a copy
10 # of this software and associated documentation files (the "Software"), to deal
11 # in the Software without restriction, including without limitation the rights
12 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 # copies of the Software, and to permit persons to whom the Software is
14 # furnished to do so, subject to the following conditions:
16 # The above copyright notice and this permission notice shall be included in
17 # all copies or substantial portions of the Software.
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 # THE SOFTWARE.
27 # **************************************************************************/
29 from __future__ import division
30 import os, sys
31 import subprocess
32 import xdgappdir
33 from locale import gettext as _
36 # Also search for dependency binaries and libraries next to myself
37 dependenciesdir = os.path.dirname(__file__) + "/usr/"
38 os.environ['PATH'] = dependenciesdir + "/bin:" + os.getenv('PATH')
39 # print os.environ['PATH']
40 lddp = os.getenv('LD_LIBRARY_PATH')
41 if lddp == None: lddp = ""
42 os.environ['LD_LIBRARY_PATH'] = dependenciesdir + "/lib:" + lddp
44 if len(sys.argv) == 2:
45 print("Assuming I should inject a new runtime")
46 destinationfile = os.path.realpath(sys.argv[1])
47 should_compress = False
48 elif len(sys.argv) < 3:
49 print("")
50 print("This packs a direcory")
51 print("")
52 print("Usage: %s sourcedir destinationfile" % (os.path.basename(sys.argv[0])))
53 print("")
54 exit(1)
55 else:
56 sourcedir = os.path.realpath(sys.argv[1])
57 destinationfile = os.path.realpath(sys.argv[2])
58 should_compress = True
60 if should_compress == True:
61 if not os.path.exists(sourcedir):
62 print("Directory not found: %s" % (sourcedir))
63 exit(1)
65 if should_compress == True:
66 H = xdgappdir.AppDirXdgHandler(sourcedir)
67 iconfile = H.get_icon_path_by_icon_name(H.get_icon_name_from_desktop_file(H.desktopfile))
68 if iconfile == None:
69 print("Icon could not be found based on information in desktop file, aborting")
70 exit(1)
72 print("Creating %s..." % (destinationfile))
73 if os.path.exists(destinationfile):
74 print (_("Destination path already exists, exiting")) # xorriso would append another session to a pre-existing image
75 exit(1)
76 # As great as xorriso is, as cryptic its usage is :-(
77 command = ["xorriso", "-dev",
78 destinationfile, "-padding", "0", "-map",
79 sourcedir, "/", "--", "-map", iconfile, "/.DirIcon",
80 "-zisofs", "level=9:block_size=128k", "-chown_r", "0",
81 "/", "--", "set_filter_r", "--zisofs", "/" ]
83 subprocess.Popen(command).communicate()
85 print("ok")
87 print("Embedding runtime...")
88 elf = os.path.realpath(os.path.dirname(__file__)) + "/runtime"
89 s = open(elf, 'rb')
90 f = open(destinationfile, 'rb+')
91 f.write(bytes(s.read()))
92 f.close()
93 s.close()
94 print("ok")
96 print("Making %s executable..." % (destinationfile))
98 os.chmod(destinationfile, 0o755)
100 print("ok")
102 filesize = int(os.stat(destinationfile).st_size)
103 print (_("Size: %f MB") % (filesize/1024/1024))