| |
---|
| | |
---|
| | # Program Information |
---|
| | |
---|
| | PROGNAME = "twander" |
---|
| | RCSID = "$Id: twander.py,v 3.118 2003/03/01 08:21:28 tundra Exp $" |
---|
| | RCSID = "$Id: twander.py,v 3.119 2003/03/01 11:05:35 tundra Exp $" |
---|
| | VERSION = RCSID.split()[2] |
---|
| | |
---|
| | # Copyright Information |
---|
| | |
---|
| |
---|
| | for x in [fNONE, fPERMISSIONS, fLINKS, fOWNER, fGROUP, fLENGTH, fDATE, fNAME]: |
---|
| | Name2Key[x.lower()] = index |
---|
| | index += 1 |
---|
| | |
---|
| | MAXSORTFIELD = len(Name2Key) |
---|
| | # Highest key index needed by Drive List View |
---|
| | |
---|
| | MAXDLVKEY = 5 |
---|
| | |
---|
| | |
---|
| | ##### |
---|
| | # System-Related Defaults |
---|
| |
---|
| | SYMPTR = " -> " |
---|
| | UNAVAILABLE = "Unavailable" |
---|
| | WIN32GROUP = "win32" + FILEGROUP |
---|
| | WIN32OWNER = "win32" + FILEOWNER |
---|
| | WIN32FREE = "free" |
---|
| | WIN32TOTAL = "total" |
---|
| | |
---|
| | |
---|
| | ##### |
---|
| | # Configuration File-Related Constants & Globals |
---|
| |
---|
| | # of exactly the specified with whose last character is |
---|
| | # a space. |
---|
| | ##### |
---|
| | |
---|
| | def PadString(string, width): |
---|
| | |
---|
| | string = string[:(width-1)] |
---|
| | string += " " * (width - len(string)) |
---|
| | def PadString(string, width, Rjust=FALSE): |
---|
| | |
---|
| | string = string[:(width-1)] |
---|
| | if Rjust: |
---|
| | string = string.rjust(width) |
---|
| | else: |
---|
| | string = string.ljust(width) |
---|
| | |
---|
| | return string |
---|
| | |
---|
| | # End of 'PadString()' |
---|
| | |
---|
| |
---|
| | |
---|
| | # The user requested Drive List View. |
---|
| | else: |
---|
| | |
---|
| | |
---|
| | dlv = {} |
---|
| | dList = [] |
---|
| | |
---|
| | # There are more keys in normal view than in Drive List View |
---|
| | # If the user has selected one of these, map them to sort |
---|
| | # by name in Drive List View. |
---|
| | |
---|
| | dlvkey = Name2Key[SORTBYFIELD.lower()] + 1 |
---|
| | if dlvkey > MAXDLVKEY: |
---|
| | dlvkey = MAXDLVKEY |
---|
| | |
---|
| | drivelist = GetWin32Drives() |
---|
| | |
---|
| | # Sort and, optionally, reverse the order |
---|
| | |
---|
| | drivelist.sort() |
---|
| | if SORTREVERSE: |
---|
| | drivelist.reverse() |
---|
| | |
---|
| | # If details are off, just return the list of drives |
---|
| | if not UI.DetailsOn: |
---|
| | return drivelist |
---|
| | |
---|
| | # We're returning detailed information about each drive |
---|
| | else: |
---|
| | # Create a detailed entry for each drive on the system |
---|
| | # Store it as a string in the details list which will |
---|
| | # then be returned to the caller |
---|
| | |
---|
| | for drive in drivelist: |
---|
| | |
---|
| | fields = [""] |
---|
| | |
---|
| | # Drive Label - Drive Might Not Be Available |
---|
| | try: |
---|
| | label = GetVolumeInformation(drive)[0] |
---|
| | except: |
---|
| | label = NODRIVE |
---|
| | |
---|
| | if not label: |
---|
| | label = NOLABEL |
---|
| | |
---|
| | # Type Of Drive - We need this now to get hostname |
---|
| | drivetype = GetDriveType(drive) |
---|
| | typestring = '' |
---|
| | |
---|
| | for type, stype in win32all_type: |
---|
| | if drivetype == type: |
---|
| | typestring = stype |
---|
| | |
---|
| | # Machine Hosting The Drive |
---|
| | if drivetype == win32con.DRIVE_REMOTE: |
---|
| | name = WNetGetUniversalName(drive, 1) |
---|
| | else: |
---|
| | name = label |
---|
| | |
---|
| | entry = PadString(name, SZ_DRIVE_HOST + SZ_DRIVE_LABEL) |
---|
| | fields.append(name) |
---|
| | |
---|
| | # Add the drive type |
---|
| | entry += PadString(typestring, SZ_DRIVE_TYPE) |
---|
| | fields.append(typestring) |
---|
| | |
---|
| | # Get Drive Space Information - Drive Might Not Be Available |
---|
| | try: |
---|
| | clustersz, sectorsz, freeclusters, totalclusters = GetDiskFreeSpace(drive) |
---|
| | |
---|
| | # Free Space |
---|
| | fspace = clustersz * sectorsz * freeclusters |
---|
| | freespace = FileLength(fspace) |
---|
| | |
---|
| | # Total Space |
---|
| | tspace = clustersz * sectorsz * totalclusters |
---|
| | totalspace = FileLength(tspace) |
---|
| | except: |
---|
| | fspace, tspace = (0, 0) |
---|
| | freespace, totalspace = ('0', '0') |
---|
| | |
---|
| | |
---|
| | freespace = PadString(freespace, SZ_DRIVE_FREE, Rjust=TRUE) |
---|
| | totalspace = PadString(totalspace, SZ_DRIVE_TTL, Rjust=TRUE) |
---|
| | |
---|
| | |
---|
| | entry += "%s %s %s %s" % (freespace, WIN32FREE, totalspace, WIN32TOTAL) |
---|
| | fields.append(fspace) |
---|
| | fields.append(tspace) |
---|
| | |
---|
| | # Finally, tack on the drive name with some leading space |
---|
| | entry += " %s" % drive |
---|
| | fields.append(drive) |
---|
| | |
---|
| | # If we're not going to sort later, just build the list |
---|
| | # of drives now |
---|
| | |
---|
| | if SORTBYFIELD.lower() == fNONE.lower(): |
---|
| | if UI.DetailsOn: |
---|
| | dList.append(entry) |
---|
| | else: |
---|
| | dList.append(drive) |
---|
| | |
---|
| | # Nope, prepare to sort later |
---|
| | else: |
---|
| | idx = fields[dlvkey] |
---|
| | dlv.setdefault(idx,[]).append((drive, entry)) |
---|
| | |
---|
| | |
---|
| | # Now that we've built the list, sort by indicated parameter |
---|
| | # if user has so indicated |
---|
| | |
---|
| | if SORTBYFIELD.lower() != fNONE.lower(): |
---|
| | |
---|
| | |
---|
| | details = [] |
---|
| | |
---|
| | # Create a detailed entry for each drive on the system |
---|
| | # Store it as a string in the details list which will |
---|
| | # then be returned to the caller |
---|
| | |
---|
| | for drive in drivelist: |
---|
| | |
---|
| | # Drive Label - Drive Might Not Be Available |
---|
| | try: |
---|
| | label = GetVolumeInformation(drive)[0] |
---|
| | except: |
---|
| | label = NODRIVE |
---|
| | |
---|
| | if not label: |
---|
| | label = NOLABEL |
---|
| | indexes = dlv.keys() |
---|
| | indexes.sort() |
---|
| | |
---|
| | if SORTREVERSE: |
---|
| | indexes.reverse() |
---|
| | |
---|
| | # Now build output list in sorted order |
---|
| | |
---|
| | for x in indexes: |
---|
| | |
---|
| | for entry in dlv[x]: |
---|
| | |
---|
| | if UI.DetailsOn: |
---|
| | dList.append(entry[1]) |
---|
| | else: |
---|
| | dList.append(entry[0]) |
---|
| | |
---|
| | # Return the list |
---|
| | |
---|
| | return dList |
---|
| | |
---|
| | # Type Of Drive - We need this now to get hostname |
---|
| | drivetype = GetDriveType(drive) |
---|
| | typestring = '' |
---|
| | |
---|
| | for type, stype in win32all_type: |
---|
| | if drivetype == type: |
---|
| | typestring = stype |
---|
| | |
---|
| | # Machine Hosting The Drive |
---|
| | if drivetype == win32con.DRIVE_REMOTE: |
---|
| | name = WNetGetUniversalName(drive, 1) |
---|
| | else: |
---|
| | name = label |
---|
| | |
---|
| | entry = PadString(name, SZ_DRIVE_HOST + SZ_DRIVE_LABEL) |
---|
| | |
---|
| | # Add the drive type |
---|
| | entry += PadString(typestring, SZ_DRIVE_TYPE) |
---|
| | |
---|
| | # Get Drive Space Information - Drive Might Not Be Available |
---|
| | try: |
---|
| | clustersz, sectorsz, freeclusters, totalclusters = GetDiskFreeSpace(drive) |
---|
| | |
---|
| | # Free Space |
---|
| | freespace = FileLength(clustersz * sectorsz * freeclusters) |
---|
| | |
---|
| | # Total Space |
---|
| | totalspace = FileLength(clustersz * sectorsz * totalclusters) |
---|
| | except: |
---|
| | freespace, totalspace = ('0', '0') |
---|
| | |
---|
| | sizes = "%s/%s" % (freespace, totalspace) |
---|
| | entry += PadString(sizes, SZ_DRIVE_FREE + SZ_DRIVE_TTL) |
---|
| | |
---|
| | # Finally, tack on the drive name |
---|
| | entry += drive |
---|
| | |
---|
| | # Save final result in detailed list |
---|
| | details.append(entry) |
---|
| | |
---|
| | return details |
---|
| | |
---|
| | |
---|
| | # End of 'BuildDirList()' |
---|
| | |
---|
| | |
---|
| |
---|
| | |