#!/usr/bin/env python import os import tempfile class BerryManager: def __init__(self): self.base_dir="/usr/share/n4d-lliurexberry/" self.orig_data_file=self.base_dir+"/orig-data/berryterminal-standalone-20150618.zip" self.llx_data_dir=self.base_dir+"/llx-data/" #def __init__ def unzip(self,data_file=None): if data_file==None: data_file=self.orig_data_file tmp_dir=tempfile.mkdtemp() cmd="unzip %s -d %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_boot_path,tmp_cpio_path): cmd="cp -r %s/boot/* %s"%(self.llx_data_dir,tmp_boot_path) os.system(cmd) cmd="cp -r %s/cpio/* %s"%(self.llx_data_dir,tmp_cpio_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): boot_path=self.unzip(data_file) #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 boot_path #def generate_llxberry_files #class BerryManager if __name__=="__main__": bm=BerryManager() print bm.generate_llxberry_files()