On Tue, Aug 17, 2010 at 8:39 PM, Richard Shaw <hobbes1069(a)gmail.com> wrote:
I put in a bunch of inline comments. I decided it was better to
communicate my changes there instead of in the email. You can comment
back here or there or delete them if you understand what I was trying
to do and agree. I probably should have made a diff patch as well but
I didn't save a copy of the original and I'm to lazy to do it now :) I
don't think most of it was drastic.
def mount(src, dst, options=None):
if os.path.exists(src): # Is src the lodev device?
mount is a generic mount procedure, src can be a file, a loop device..
and ISO, a disk. Anything really.
if options: # None is the same as Null so
you can test for existence instead.
I'm pretty sure if options: without making options=None will cause
and IndexErroor. So I probably should just test for thing: when I set
offset=None or
options=None in the function.
else: # Let's make sure only one
return statement get's triggered.
return False # Might as well return
something useful so we can test for failure.
This is sort of debateable.
I mean, if the mount operation fails, we can't really do anything to correct it.
In other words, it should succeed, else return nothing.
I am pretty sure return will just return nothing.
else:
print "Something is wrong, %s has no size." % ent
return False
I think this is good, you never know when the file you are trying to
use may not be the right one.
def blocks(block_size, size):
# Round up to nearest block
# Make sure floating math, not integer math or we don't get remainders.
# Turn back into an integer for return statement.
return int(math.ceil(size / float(block_size)))
I'm not sure why we would need this.
Any idea?
def setup(x86, x64, multi):
# Reworked the logic a bit.
block_size = 2048 # Should this be a global
constant instead?
sz = size(x86) + size(x64)
count = blocks(block_size, sz)
multi = mkimage(str(blsz), count)
losetup(multi, lo())
block size is a constant, in the scope of setup() which is about the only place
we would need to use it. Unless that changes.
I'm using "2048"
def parse(x86, x64, multi):
for file in x86, x64, multi: # Do we expect that multi exists yet?
if os.path.exists(file): # Should we test for existance
or isfile?
pass
else:
parser.error("One of the images does not exist.")
setup(x86, x64, multi)
multi is our end-result target file.
This begins with a temporary file, that is then partitioned and formatted.
Copied to, and closed up eventually, then shutil.move(tmpfile, multi)
Maybe both. if os.path.exixts() and if os.path.isfile()
Then again, there shouldn't be a reason we should disallow use of
hardlinked ISO image files or soft linked ones. Have any logic behind
preventing use of the files if they are links and not files?
try: # Any reason this would fail?
parse(args[0], args[1], args[2])
except:
parser.error("Something failed. Better luck next time!")
sys.exit(1)
Yes, when the files don't exist it will fail with an IndexError
on sys.argv[]
I think I might also do something different with the syslinux.cfg stuff.
Instead of having the huge text data as a content "" and filled.
Instead read the ISOLINUX.CFG and use re.search and re.match
To find what we need, then concatenate using line indexes
from readlines().
Can contents = fd.readlines() be written to?
Do you know? Is the content of contents static?
Still looking at the module investigator text you sent.
It is hard to tell how to do simple things with that module.
All we need to do is, partition it.. type 0x83
Start cylinder 1 or 63, and end, up to the end of the file.
Then, write that partition table.
Format the partition.
Move to mounting our ISO files and doing extraction of the UUID
and other things. Copy the files to the partition.
Close it up.