3 # /**************************************************************************
5 # Copyright (c) 2005-12 Simon Peter
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
27 # **************************************************************************/
29 from __future__
import division
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:
51 print("This packs a direcory")
53 print("Usage: %s sourcedir destinationfile" % (os
.path
.basename(sys
.argv
[0])))
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
))
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
))
70 print "Icon could not be found based on information in desktop file, aborting"
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
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()
88 print("Embedding runtime...")
90 elf
= os
.path
.realpath(os
.path
.dirname(__file__
)) + "/runtime"
92 f
= file(destinationfile
, 'r+')
98 print("Making %s executable..." % (destinationfile
))
100 os
.chmod(destinationfile
, 0755)
104 filesize
= int(os
.stat(destinationfile
).st_size
)
105 print (_("Size: %f MB") % (filesize
/1024/1024))