#!/usr/bin/env python import os import tempfile import sys class BerryManager: def __init__(self,tmp_dir): self.tmp_dir=tmp_dir self.base_dir="/usr/share/n4d-lliurexberry/" self.orig_data_file=self.base_dir+"/orig-data/fs.tar.xz" self.llx_data_dir=self.base_dir+"/llx-data/" #def __init__ def unzip(self,data_file=None,tmp_dir=None): if data_file==None: data_file=self.orig_data_file cmd="tar xfJ %s -C %s 1>/dev/null 2>/dev/null"%(data_file,tmp_dir) os.system(cmd) return tmp_dir #def unzip # def gunzip_cpio(self,unzipped_path,v=None): # # if v==None: # v="" # # # tmp_dir=tempfile.mkdtemp() # cmd="cp %s/berryterminal%s.img %s/uncompressed_berryterminal.gz 2>/dev/null"%(unzipped_path,v,tmp_dir) # os.system(cmd) # cmd="gunzip %s/uncompressed_berryterminal.gz 1>/dev/null 2>/dev/null; rm -rf %s/uncompressed_berryterminal.gz 2>/dev/null"%(tmp_dir,tmp_dir) # os.system(cmd) # cmd="cd %s; cpio --quiet -id < %s/uncompressed_berryterminal; rm -rf %s/uncompressed_berryterminal 2>/dev/null"%(tmp_dir,tmp_dir,tmp_dir) # os.system(cmd) # # return tmp_dir # # #def gunzip_cpio def copy_lliurex_files(self,tmp_path): cmd="rsync -aHAXS %s/fs/ %s/"%(self.llx_data_dir,tmp_path) os.system(cmd) #def copy_lliurex_files # def regenerate_cpio(self,boot_path,cpio_path,v=None): # # if v==None: # v="" # # cmd="cd %s; find . | cpio --quiet --create --format='newc' > %s/newinitrd && gzip %s/newinitrd 1>/dev/null 2>/dev/null; mv %s/newinitrd.gz %s/berryterminal%s.img"%(cpio_path,boot_path,boot_path,boot_path,boot_path,v) # os.system(cmd) # # #def regenerate_cpio def generate_llxberry_files(self,data_file=None): decompressed_path=self.unzip(data_file,self.tmp_dir) self.copy_lliurex_files(decompressed_path) #Rpi v1 # cpio_path=self.gunzip_cpio(boot_path,1) # self.copy_lliurex_files(boot_path,cpio_path) # self.regenerate_cpio(boot_path,cpio_path,1) # os.system("rm -rf %s"%cpio_path) #Rpi v2 # cpio_path=self.gunzip_cpio(boot_path,2) # self.copy_lliurex_files(boot_path,cpio_path) # self.regenerate_cpio(boot_path,cpio_path,2) # os.system("rm -rf %s"%cpio_path) return decompressed_path #def generate_llxberry_files #class BerryManager if __name__=="__main__": if len(sys.argv) != 2: sys.exit(1) bm=BerryManager(sys.argv[1]) print bm.generate_llxberry_files()