--- usbspindownd/usbspindownd.py 2008/01/31 07:58:04 33 +++ usbspindownd/usbspindownd.py 2008/02/01 02:44:52 37 @@ -35,9 +35,12 @@ keep_running = True signals = {} +class Error(Exception): + pass + + def signal_handler(signal, stack): global keep_running - global sigdict keep_running = False @@ -80,6 +83,9 @@ except IOError, e: print "Got a '%s' trying to read %s" % (e.strerror, options.config) sys.exit(1) + except ConfigParser.MissingSectionHeaderError, e: + print "Parser error: '%s'" % (e.message) + sys.exit(1) if cf.has_option("DEFAULT", "wait"): defaultwait = cf.get("DEFAULT", "wait") else: @@ -147,11 +153,11 @@ if msio == config[disk]["last_msio"]: debug(options, "Disk has been idle since last considered") now = int(time.time()) - if (now - config[disk]["timestamp"]) >= config[disk]["wait"]: + if (now - config[disk]["timestamp"]) >= int(config[disk]["wait"]): debug(options, "Disk eligible for spinning down") # We can spin this disk down if not config[disk]["spun_down"]: - if spin_down(disk): + if spin_down(options, disk): debug(options, "Disk spun down") config[disk]["spun_down"] = True else: @@ -162,10 +168,12 @@ # This disk is ineligible for spinning down at this time debug(options, "Disk idle for %s seconds, but not for long enough (%s)" % (now - config[disk]["timestamp"], config[disk]["wait"])) else: - debug(options, "Disk not idle (old msio: %s, current msio: %s)" % (config[disk]["last_msio"], msio)) config[disk]["last_msio"] = msio config[disk]["timestamp"] = int(time.time()) - config[disk]["spun_down"] = False + if config[disk]["spun_down"]: + debug(options, "%s presumed spun back up by activity" % (disk)) + config[disk]["spun_down"] = False + debug(options, "Disk not idle (old msio: %s, current msio: %s)" % (config[disk]["last_msio"], msio)) debug(options, "Sleeping") time.sleep(60) debug(options, "Shutting down")