Skip to content

Commit

Permalink
Use ext4fs_utils from droidtools to generate cache
Browse files Browse the repository at this point in the history
refs #30 build python c extensions for some of the binaries
  • Loading branch information
tgalal committed Aug 6, 2015
1 parent c8fd316 commit 34fae08
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 37 deletions.
4 changes: 2 additions & 2 deletions inception/generators/cacheimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def addFile(self, src, dest = None):
else:
shutil.copy(src, dest)

def generate(self, out, adbBinPath = None):
def generate(self, out):
#write command
if len(self.commands):
commandFile = open(self.recoveryDir + "/command", "w")
commandFile.write("\n".join(self.commands))
commandFile.close()

super(CacheImgGenerator, self).generate(self.workingDir, out, adbBinPath)
super(CacheImgGenerator, self).generate(self.workingDir, out)
41 changes: 8 additions & 33 deletions inception/generators/ext4fs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from .generator import Generator, GenerationFailedException
from exceptions import Ext4FSGenerationFailedException
from ..constants import InceptionConstants
import time, sys
from droidtools import ext4fs_utils
class Ext4FSGenerator(Generator):
def __init__(self, ext4bin):
def __init__(self, ext4bin = None):
super(Ext4FSGenerator, self).__init__()
self.bin = ext4bin
self.size = 0
Expand All @@ -22,37 +21,13 @@ def setMountPoint(self, mountPoint):
def setSparsed(self, sparsed):
self.sparsed = True if sparsed else False

def generateArgs(self, src, out):
cmd = ("-l", str(self.size))
if self.sparsed:
cmd += ("-s",)
if self.mountPoint is not None:
cmd += ("-a", self.mountPoint)

cmd += (out, src)

return cmd

def generate(self, src, out, adbBinPath = None):
def generate(self, src, out):
if self.size <= 0:
raise Ext4FSGenerationFailedException("Ext4 fs size cannot be %s" % self.size)
if not self.bin.startswith("device://"):
args = self.generateArgs(src, out)
cmd = (self.bin,) + args
self.execCmd(*cmd)
else:
if not adbBinPath:
print "Adb bin not specified"
sys.exit(1)
remoteBin = self.bin.split("device://")[1]
remoteSrc = "/tmp/cache"
remoteOut = "/tmp/cache.img"
remoteArgs = self.generateArgs(remoteSrc, remoteOut)
remoteCmd = (remoteBin,) + remoteArgs
adb = self.getAdb(adbBinPath)
adb.cmd("mkdir", remoteSrc)
adb.push(src, remoteSrc)
adb.cmd(*remoteCmd)
adb.pull(remoteOut, out)

ext4fs_utils.make_ext4fs(out, src,
self.size,
self.mountPoint,
mode=ext4fs_utils.MODE_SPARSED if self.sparsed else ext4fs_utils.MODE_NORMAL)

return True
2 changes: 1 addition & 1 deletion inception/generators/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class Generator(InceptionObject):
def __init__(self):
super(Generator, self).__init__()

def generate(self):
def generate(self, *args, **kwargs):
pass
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
deps = ['dulwich', 'argparse', 'pycrypto', 'android-dumpkey']
deps = ['dulwich', 'argparse', 'pycrypto', 'android-dumpkey', 'droidtools']
from setuptools import setup, find_packages
import inception
setup(
Expand Down

0 comments on commit 34fae08

Please sign in to comment.