mirror of
https://github.com/xcat2/confluent.git
synced 2024-12-24 12:11:52 +00:00
451ff6b5a3
The geometry was incorrect in dir2img, ensure the file is a multiple of 512 bytes.
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
#!/usr/bin/python
|
|
# This will take a given directory and make a 'big floppy image'
|
|
# out of it, suitable for nodemedia upload.
|
|
|
|
import glob
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
def create_image(directory, image):
|
|
ents = 0
|
|
datasz = 512
|
|
for dir in os.walk(sys.argv[1]):
|
|
ents += 1
|
|
for filen in dir[2]:
|
|
ents += 1
|
|
filename = os.path.join(dir[0], filen)
|
|
currsz = os.path.getsize(filename)
|
|
# assuming up to 65k cluster
|
|
currsz = (currsz // 512 +1) * 512
|
|
datasz += currsz
|
|
datasz += ents * 32768
|
|
datasz = datasz // 512 + 1
|
|
with open(image, 'wb') as imgfile:
|
|
imgfile.seek(datasz * 512 - 1)
|
|
imgfile.write(b'\x00')
|
|
subprocess.check_call(['mformat', '-i', image, '-d', '1', '-t',
|
|
str(datasz), '-s', '1','-h', '1', '::'])
|
|
cpycmd = ['mcopy', '-i', image, '-s']
|
|
cpycmd.extend(glob.glob('{0}/*'.format(directory)))
|
|
cpycmd.append('::')
|
|
subprocess.check_call(cpycmd)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 3:
|
|
sys.stderr.write("Usage: {0} <directory> <imagefile>".format(
|
|
sys.argv[0]))
|
|
sys.exit(1)
|
|
create_image(sys.argv[1], sys.argv[2]) |