import os import sys import logging class DosDisk: drive= "a:" mformat= "mformat" mmkdir= "mmd" mcopy= "mcopy" mdir= "mdir" class DiskError( Exception): pass def __init__(self, drive = None): if drive is not None: self.drive = drive def system(self, command): logging.warning( command) code= os.system( command) if code: raise DosDisk.DiskError( "'%s' status=%x"%(command, code)) def format(self): command= self.mformat+" "+self.drive self.system( command) def copy(self, filename, targetpath = None): if targetpath is None: targetpath= filename command= self.mcopy+" '"+filename+"' '"+self.drive+targetpath+"'" self.system( command) def mkdir(self, targetpath): command= self.mmkdir+" '"+self.drive+targetpath+"'" self.system( command) def dir(self, targetpath = None): if targetpath is not None: command= self.mmkdir+" '"+self.drive+targetpath+"'" else: command= self.mmkdir+" "+self.drive self.system( command) def devdevice(self): if self.drive == "a:": return "/dev/fd0" if self.drive == "b:": return "/dev/fd1" raise DiskError("no /dev/device for "+self.drive); def grubdevice(self): if self.drive == "a:": return "(fd0)" if self.drive == "b:": return "(fd1)" raise DiskError("no grub device for "+self.drive); if __name__ == "__main__": if len( sys.argv) > 1: DosDisk().dir(sys.argv[1]) else: DosDisk().dir()