[DEV] create a basic bundle for windows

This commit is contained in:
Edouard DUPIN 2015-04-22 22:36:29 +02:00
parent 50103d4c74
commit a40a25dba5
3 changed files with 78 additions and 4 deletions

View File

@ -56,9 +56,12 @@ def file_size(path):
statinfo = os.stat(path)
return statinfo.st_size
def file_read_data(path):
def file_read_data(path, binary=False):
if not os.path.isfile(path):
return ""
if binary == True:
file = open(path, "rb")
else:
file = open(path, "r")
data_file = file.read()
file.close()

39
lutinZip.py Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/python
##
## @author Edouard DUPIN
##
## @copyright 2012, Edouard DUPIN, all right reserved
##
## @license APACHE v2.0 (see license file)
##
import lutinDebug as debug
import lutinTools as tools
import platform
import os
import zipfile
def create_zip(path, outputFile):
debug.debug("Create Zip : '" + outputFile + "'")
debug.debug(" from '" + path + "'")
basePathlen = len(path)
zf = zipfile.ZipFile(outputFile, mode='w')
for root, dirnames, filenames in os.walk(path):
# List all files :
for filename in filenames:
file = os.path.join(root, filename)
debug.verbose(" ADD zip = " + str(file))
zf.write(file, file[basePathlen:])
zf.close()
"""
print('creating archive')
zf = zipfile.ZipFile('zipfile_write.zip', mode='w')
try:
print('adding README.md')
zf.write('README.md')
finally:
print('closing')
zf.close()
"""

View File

@ -9,11 +9,12 @@
import lutinDebug as debug
import lutinTarget
import lutinTools
import lutinTools as tools
import lutinHost
import os
import stat
import sys
import lutinZip as zip
class Target(lutinTarget.Target):
def __init__(self, config):
@ -67,7 +68,38 @@ class Target(lutinTarget.Target):
debug.debug("------------------------------------------------------------------------")
debug.info("Generate package '" + pkgName + "'")
debug.debug("------------------------------------------------------------------------")
debug.warning(" ==> TODO")
debug.print_element("zip", "data.zip", "<==", "data/*")
zipPath = self.get_staging_folder(pkgName) + "/data.zip"
zip.create_zip(self.get_staging_folder_data(pkgName), zipPath)
binPath = self.get_staging_folder(pkgName) + "/" + self.folder_bin + "/" + pkgName + self.suffix_binary
binSize = tools.file_size(binPath)
debug.info("binarysize : " + str(binSize/1024) + " ko ==> " + str(binSize) + " octets")
#now we create a simple bundle binary ==> all file is stored in one file ...
self.get_staging_folder(pkgName)
finalBin = self.get_final_folder() + "/" + pkgName + self.suffix_binary
tools.create_directory_of_file(finalBin);
debug.print_element("pkg", finalBin, "<==", pkgName + self.suffix_binary)
tmpFile = open(finalBin, 'wb')
dataExecutable = tools.file_read_data(binPath, binary=True)
tmpFile.write(dataExecutable)
residualToAllign = len(dataExecutable) - int(len(dataExecutable)/32)*32
for iii in range(1,residualToAllign):
tmpFile.write(b'j');
positionOfZip = len(dataExecutable) + residualToAllign;
debug.print_element("pkg", finalBin, "<==", "data.zip")
dataData = tools.file_read_data(zipPath, binary=True)
tmpFile.write(dataData)
tmpLen = len(dataData) + positionOfZip
residualToAllign = tmpLen - int(tmpLen/32)*32
for iii in range(1,residualToAllign):
tmpFile.write(b'j');
tmpFile.write(bin(positionOfZip))
tmpFile.flush()
tmpFile.close()
debug.info("zip position=" + str(positionOfZip))
def install_package(self, pkgName):
debug.debug("------------------------------------------------------------------------")