modified: AppImageAssistant.AppDir/testappimage
[appimagekit/gsi.git] / AppImageAssistant.AppDir / package
blob0c9dffeee4ad78b6cb16371b2a840380abcf2446
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 import commands
34 from locale import gettext as _
37 # Also search for dependency binaries and libraries next to myself
38 dependenciesdir = os.path.dirname(__file__) + "/usr/"
39 os.environ['PATH'] = dependenciesdir + "/bin:" + os.getenv('PATH')
40 # print os.environ['PATH']
41 lddp = os.getenv('LD_LIBRARY_PATH')
42 if lddp == None: lddp = ""
43 os.environ['LD_LIBRARY_PATH'] = dependenciesdir + "/lib:" + lddp
45 if len(sys.argv) == 2:
46 print "Assuming I should inject a new runtime"
47 destinationfile = os.path.realpath(sys.argv[1])
48 should_compress = False
49 elif len(sys.argv) < 3:
50 print("")
51 print("This packs a direcory")
52 print("")
53 print("Usage: %s sourcedir destinationfile" % (os.path.basename(sys.argv[0])))
54 print("")
55 exit(1)
56 else:
57 sourcedir = os.path.realpath(sys.argv[1])
58 destinationfile = os.path.realpath(sys.argv[2])
59 should_compress = True
61 if should_compress == True:
62 if not os.path.exists(sourcedir):
63 print("Directory not found: %s" % (sourcedir))
64 exit(1)
66 if should_compress == True:
67 H = xdgappdir.AppDirXdgHandler(sourcedir)
68 iconfile = H.get_icon_path_by_icon_name(H.get_icon_name_from_desktop_file(H.desktopfile))
69 if iconfile == None:
70 print "Icon could not be found based on information in desktop file, aborting"
71 exit(1)
73 print("Creating %s..." % (destinationfile))
74 if os.path.exists(destinationfile):
75 print _("Destination path already exists, exiting") # xorriso would append another session to a pre-existing image
76 exit(1)
77 # As great as xorriso is, as cryptic its usage is :-(
78 command = ["xorriso", "-dev",
79 destinationfile, "-padding", "0", "-map",
80 sourcedir, "/", "--", "-map", iconfile, "/.DirIcon",
81 "-zisofs", "level=9:block_size=128k", "-chown_r", "0",
82 "/", "--", "set_filter_r", "--zisofs", "/" ]
84 subprocess.Popen(command).communicate()
86 print "ok"
88 print("Embedding runtime...")
90 elf = os.path.realpath(os.path.dirname(__file__)) + "/runtime"
91 s = file(elf, 'r')
92 f = file(destinationfile, 'r+')
93 f.write(s.read())
94 f.close()
95 s.close()
96 print "ok"
98 print("Making %s executable..." % (destinationfile))
100 os.chmod(destinationfile, 0755)
102 print "ok"
104 filesize = int(os.stat(destinationfile).st_size)
105 print (_("Size: %f MB") % (filesize/1024/1024))