/[gli]/trunk/src/GLIStorageDevice.py
Gentoo

Diff of /trunk/src/GLIStorageDevice.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 555 Revision 556
1import commands, string, os, parted 1import commands, string, os, parted
2from GLIException import *
2 3
3MEGABYTE = 1024 * 1024 4MEGABYTE = 1024 * 1024
4 5
5archinfo = { 'sparc': { 'fixedparts': [ { 'minor': 3, 'type': "wholedisk" } ], 'disklabel': 'sun', 'extended': False }, 6archinfo = { 'sparc': { 'fixedparts': [ { 'minor': 3, 'type': "wholedisk" } ], 'disklabel': 'sun', 'extended': False },
6 'hppa': { 'fixedparts': [ { 'minor': 1, 'type': "boot" } ], 'disklabel': 'msdos', 'extended': False }, 7 'hppa': { 'fixedparts': [ { 'minor': 1, 'type': "boot" } ], 'disklabel': 'msdos', 'extended': False },
385 # Prints disk geometry to STDOUT (no longer used) 386 # Prints disk geometry to STDOUT (no longer used)
386 def print_geometry(self): 387 def print_geometry(self):
387 print self._total_bytes, self._geometry 388 print self._total_bytes, self._geometry
388 389
389 ## 390 ##
390 # Utility function for raising an exception
391 # @param message Error message
392 def _error(self, message):
393 "Raises an exception"
394 raise GLIException("DeviceObjectError", 'fatal', 'Device', message)
395
396 ##
397 # Utility function for running a command and returning it's output as a list 391 # Utility function for running a command and returning it's output as a list
398 # @param cmd Command to run 392 # @param cmd Command to run
399 def _run(self, cmd): 393 def _run(self, cmd):
400 "Runs a command and returns the output" 394 "Runs a command and returns the output"
401 395
696 elif mb > self._mb: 690 elif mb > self._mb:
697 # Growing 691 # Growing
698 self._device._partitions[free_minor]._mb = mb - self._mb 692 self._device._partitions[free_minor]._mb = mb - self._mb
699 self._mb = mb 693 self._mb = mb
700 694
701 ##
702 # Utility function to raise an exception
703 # @param message Error message
704 def _error(self, message):
705 raise GLIException("PartitionObjectError", 'fatal', 'Partition', message)
706
707## 695##
708# Returns a list of detected partitionable devices 696# Returns a list of detected partitionable devices
709def detect_devices(): 697def detect_devices():
710 devices = [] 698 devices = []
711 699
712 # Make sure sysfs exists 700 # Make sure sysfs exists
713 if not os.path.exists("/sys/bus"): 701 if not os.path.exists("/sys/bus"):
714 raise Exception, "no sysfs found (you MUST use a kernel >2.6)" 702 raise GLIException("GLIStorageDeviceError", 'fatal', 'detect_devices', "no sysfs found (you MUST use a kernel >2.6)")
715 # Make sure /proc/partitions exists 703 # Make sure /proc/partitions exists
716 if not os.path.exists("/proc/partitions"): 704 if not os.path.exists("/proc/partitions"):
717 raise Exception, "/proc/partitions does not exist!" 705 raise GLIException("GLIStorageDeviceError", 'fatal', 'detect_devices', "/proc/partitions does not exist! Please make sure procfs is in your kernel and mounted!")
718 706
719 # Load /proc/partitions into the variable 'partitions' 707 # Load /proc/partitions into the variable 'partitions'
720 partitions = [] 708 partitions = []
721 for line in open("/proc/partitions"): 709 for line in open("/proc/partitions"):
722 if len(line.split()) < 4 or not line.split()[0].isdigit() or \ 710 if len(line.split()) < 4 or not line.split()[0].isdigit() or not line.split()[1].isdigit():
723 not line.split()[1].isdigit():
724 continue 711 continue
725 712
726 # Get the major, minor and device name 713 # Get the major, minor and device name
727 major = line.split()[0] 714 major = line.split()[0]
728 minor = line.split()[1] 715 minor = line.split()[1]
761 if os.path.exists("/sys/bus/" + dev_type): 748 if os.path.exists("/sys/bus/" + dev_type):
762 sysfs_devices = os.listdir("/sys/bus/"+dev_type+"/devices") 749 sysfs_devices = os.listdir("/sys/bus/"+dev_type+"/devices")
763 750
764 # For each device in the devices on that bus 751 # For each device in the devices on that bus
765 for sysfs_device in sysfs_devices: 752 for sysfs_device in sysfs_devices:
766 dev_file = "/sys/bus/" + dev_type + "/devices/"\ 753 dev_file = "/sys/bus/" + dev_type + "/devices/" + sysfs_device + "/block/dev"
767 + sysfs_device + "/block/dev"
768 754
769 # If the file is not a block device, loop 755 # If the file is not a block device, loop
770 if not os.path.exists(dev_file): 756 if not os.path.exists(dev_file):
771 continue 757 continue
772 758
774 try: 760 try:
775 major, minor = open(dev_file).read().split(":") 761 major, minor = open(dev_file).read().split(":")
776 major = int(major) 762 major = int(major)
777 minor = int(minor) 763 minor = int(minor)
778 except: 764 except:
779 raise Exception, "invalid major minor in "\ 765 raise GLIException("GLIStorageDeviceError", 'fatal', 'detect_devices', "invalid major minor in " + dev_file)
780 + dev_file
781 766
782 # Find a device listed in /proc/partitions 767 # Find a device listed in /proc/partitions
783 # that has the same minor and major as our 768 # that has the same minor and major as our
784 # current block device. 769 # current block device.
785 for record in partitions: 770 for record in partitions:

Legend:
Removed from v.555  
changed lines
  Added in v.556

  ViewVC Help
Powered by ViewVC 1.1.20