Exemple #1
0
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage: drives.py

    shows the available drives on the system and (free space/total space)
    """
    args, opts = oss.gopt(argv[1:], [], [], main.__doc__)

    drives = w32.GetLogicalDrives()

    for i in range(26):
        if drives & (1 << i):
            dl = chr(i + ord('A'))
            rootpath = dl + ':\\'
            tp = w32.GetDriveType(rootpath)
            print("  %s:" % dl, S[tp], end='')

            try:
                f, t, d = w32.GetDiskFreeSpaceEx(rootpath)

                if tp == 4:
                    print(" (%s/%s)" %
                          (util.CvtGigMegKBytes(f), util.CvtGigMegKBytes(t)),
                          end='')
                    print(" [%s]" % wnet.WNetGetUniversalName(rootpath, 1))
                else:
                    print(" (%s/%s)" %
                          (util.CvtGigMegKBytes(f), util.CvtGigMegKBytes(t)))

            except:
                print("  -- not ready")

    oss.exit(0)
Exemple #2
0
def test_usb(type, fmt=False):
    if fmt:
        os.system('adb reboot')
        os.system('adb wait-for-device')
        while os.popen('adb shell getprop sys.boot_completed').readline(
        ).strip() != '1':
            time.sleep(3)
    os.popen('adb push \"{0}\" /data/local/tmp'.format(
        os.path.join(workdir, 'ramdisk.sh'))).readlines()
    os.popen('adb shell sh /data/local/tmp/ramdisk.sh').readlines()
    os.system('adb shell setprop sys.usb.config {0},adb'.format(type))
    os.system('adb wait-for-device')
    drive = None
    loop = 1
    read = 0
    write = 0
    while not drive:
        if loop > 20:
            break
        r = win32file.GetLogicalDrives()
        for d in range(26):
            if r >> d & 1 and win32file.GetDriveType(string.ascii_letters[d] +
                                                     ':\\') == 2:
                drive = string.ascii_letters[d]
                break
        time.sleep(3)
        loop += 1
    if drive:
        if fmt:
            os.system('echo y | format {0}: /fs:fat32 /q'.format(drive))

        file1 = os.path.join(workdir, 'test.zip')
        file2 = os.path.join(drive + ':' + os.sep, 'test.zip')
        if os.path.exists(file2):
            os.remove(file2)

        st = time.time()
        shell.SHFileOperation(
            (0, shellcon.FO_COPY, file1, file2, 0, None, None))
        write = round(
            os.path.getsize(file1) / 1048576.0 / (time.time() - st), 2)

        file3 = os.path.join(workdir, 'tmp.zip')
        if os.path.exists(file3):
            os.remove(file3)

        st = time.time()
        shell.SHFileOperation(
            (0, shellcon.FO_COPY, file2, file3, 0, None, None))
        read = round(
            os.path.getsize(file2) / 1048576.0 / (time.time() - st), 2)

        os.remove(file2)
        os.remove(file3)
    os.popen('adb shell rm /data/local/tmp/ramdisk.sh').readlines()
    return (read, write)
def possible(allowfixed=0):
    dr=win32file.GetLogicalDrives()
    result=0
    for d in range(3,32):
        mask=1 << d
        if dr & mask:
            ans=_maybepossible(d,allowfixed)
            if ans:
                result |= mask
    return result
Exemple #4
0
def locate_usb():
    drive_list = []
    drivebits = win32file.GetLogicalDrives()
    for d in range(1, 26):
        mask = 1 << d
        if drivebits & mask:
            drname = '%c:\\' % chr(ord('A') + d)
            t = win32file.GetDriveType(drname)
            if t == win32file.DRIVE_REMOVABLE:
                drive_list.append(drname)
    return drive_list
Exemple #5
0
def get_removable_drives():
    """ Returns a list of all connected removable drives. """
    removable_drives = []
    drivebits = win32file.GetLogicalDrives()
    for drive_number in range(1, 26):
        mask = 1 << drive_number
        if drivebits & mask:
            drive_name = '%c:\\' % chr(ord('A') + drive_number) # E.g., C:\
            drive_type = win32file.GetDriveType(drive_name)
            if drive_type == win32file.DRIVE_REMOVABLE:
                removable_drives.append(drive_name)
    return removable_drives
Exemple #6
0
def getdrives():
    drives = []
    sign = win32file.GetLogicalDrives()
    drive_all = [
        "A:\\", "B:\\", "C:\\", "D:\\", "E:\\", "F:\\", "G:\\", "H:\\", "I:\\",
        "J:\\", "K:\\", "L:\\", "M:\\", "N:\\", "O:\\", "P:\\", "Q:\\", "R:\\",
        "S:\\", "T:\\", "U:\\", "V:\\", "W:\\", "X:\\", "Y:\\", "Z:\\"
    ]
    for i in range(25):
        if (sign & 1 << i):
            if win32file.GetDriveType(drive_all[i]) == 2:
                drives.append(drive_all[i])
    return drives
Exemple #7
0
def get_drive_list():
    drive_list = []
    remote_drive_list = []
    fixed_drive_list = []
    removable_drive_list = []
    ram_drive_list = []
    cd_rom_drive_list = []

    drivebits = win32file.GetLogicalDrives()
    for d in range(1, 26):
        mask = 1 << d
        if drivebits & mask:
            # here if the drive is at least there
            drname = '%c:\\' % chr(ord('A') + d)
            t = win32file.GetDriveType(drname)
            if t == win32file.DRIVE_REMOTE:
                remote_drive_list.append(drname)
            elif t == win32file.DRIVE_FIXED:
                fixed_drive_list.append(drname)
            elif t == win32file.DRIVE_REMOVABLE:
                removable_drive_list.append(drname)
            elif t == win32file.DRIVE_RAMDISK:
                ram_drive_list.append(drname)
            elif t == win32file.DRIVE_CDROM:
                cd_rom_drive_list.append(drname)

    #Add all drives to list
    drive_list.append(remote_drive_list)
    drive_list.append(fixed_drive_list)
    drive_list.append(removable_drive_list)
    drive_list.append(ram_drive_list)
    drive_list.append(cd_rom_drive_list)

    if debug_mode_active:
        switcher = {
            0: "Remote Drive List:",
            1: "Fixed Drive List:",
            2: "Removable Drive List:",
            3: "Ram Drive List:",
            4: "Cd-rom Drive List:",
        }

        for list_item in range(0, len(drive_list)):
            if len(drive_list[list_item]) > 0:
                print switcher.get(list_item, "nothing")
            for item in range(0, len(drive_list[list_item])):
                print drive_list[list_item][item]

    return drive_list
def get_logical_drives() -> list:
    import win32file
    drivebits = win32file.GetLogicalDrives()

    drive_list = list()

    for d in range(1, 26):
        mask = 1 << d
        if drivebits & mask:
            # here if the drive is at least there
            drive_name = '%c:\\' % chr(ord('A') + d)

            drive_list.append(drive_name)

    return drive_list
Exemple #9
0
def windowsEnumTime(driveLetter):
    enumTime = 0.0

    position = ord(driveLetter) - ord(
        'A'
    )  # gets the offset or position value of the driveletter that the system is looking for
    mask = 1 << position  # creats a mask with a 1 in the position of the offset
    driveBits = win32file.GetLogicalDrives(
    )  # returns a 26 bit bitmask of all logical drives installed on the system

    startTime = time.perf_counter()  # start a system timer
    while not (
            driveBits & mask
    ):  # loop while the drive is still not visable and keep querying Windows for that drive
        driveBits = win32file.GetLogicalDrives()
        if time.perf_counter(
        ) - startTime > max_enum_time:  # if the loop has been going on for greater than the max enum time given, return the max time
            return max_enum_time

    endTime = time.perf_counter()  # set an end time after the drive was found
    enumTime = round(
        endTime - startTime,
        3)  # gets enumeration time and rounds it to 3 decimal places
    return enumTime
Exemple #10
0
    def win10_locate_usb(self):
        import win32file
        drive_list = []
        drivebits = win32file.GetLogicalDrives()

        for d in range(1, 26):
            mask = 1 << d

            if drivebits & mask:
                # here if the drive is at least there
                drname = '%c:\\' % chr(ord('A') + d)

                t = win32file.GetDriveType(drname)
                if t == win32file.DRIVE_REMOVABLE:
                    drive_list.append(drname)
        return drive_list
Exemple #11
0
def locate_usb():
    drive_list = []

    # Get all the list of Drices
    drivebits = win32file.GetLogicalDrives()

    # Go through all the drives
    for d in range(1, 26):
        mask = 1 << d
        if drivebits & mask:
            # here if the drive is at least there
            drname = '%c:\\' % chr(ord('A') + d)
            t = win32file.GetDriveType(drname)
            if t == win32file.DRIVE_REMOVABLE:
                # Append all the removable drives
                drive_list.append(drname)
    return drive_list
Exemple #12
0
def listRemovableDrivesWindows():
    """
    Return a list of "removable" drives under Windows.
    """
    l = []
    try:
        import win32file
        drivebits = win32file.GetLogicalDrives()
        for d in range(1, 26):
            mask = 1 << d
            if drivebits & mask:
                # here if the drive is at least there
                drname = '%c:\\' % chr(ord('A') + d)
                t = win32file.GetDriveType(drname)
                if t == win32file.DRIVE_REMOVABLE:
                    l.append(drname)
    except:
        lg.exc()
    return l
Exemple #13
0
    def locate_usb(self):
        """
        locate_usb()

        :return:

        Locate USB devices on a Windows machine

        """
        import win32file
        drive_list = []
        drivebits = win32file.GetLogicalDrives()
        for d in range(1, 26):
            mask = 1 << d
            if drivebits & mask:
                drname = '%c:\\' % chr(ord('A') + d)
                t = win32file.GetDriveType(drname)
                if t == win32file.DRIVE_REMOVABLE:
                    drive_list.append(drname)
        return drive_list
Exemple #14
0
def listDrive(**item_opt):
	lst_fll = []

	if platform == "linux" or platform == "linux2":
		lst_temp = []
		lst_devs = []

		proc = subprocess.Popen("df | grep ^/dev/", stdout=subprocess.PIPE, shell=True)
		(unparsed, err) = proc.communicate()

		lst_devs = unparsed.decode('utf-8').split("\n")

		for dev_inst in lst_devs:
			lst_temp = dev_inst.split()    #output should be /dev/<dev name>
			if lst_temp:
				lst_fll.append(lst_temp[0] + "   " + lst_temp[5])

	elif platform == "win32":
		try:
			import win32file
		except:
			#print("Error: There are incomplete dependencies on this computer. Pypiwin32 will be installed.") ######## DISPLAY ERROR MESSAGE @to_GUI
			try:
				subprocess.Popen("pip install pypiwin32", shell=True)
			except:
				#print("Error: Pypiwin32 cannot be installed.")
				exit(-1)

		drive_types = { "0": "Unknown", "1": "No Root Directory", "2": "Removable Disk", "3": "Local Disk",
		                "4": "Network Drive", "5": "Compact Disc", "6": "RAM Disk" }

		for c_inst in string.ascii_lowercase:
			if (win32file.GetLogicalDrives() >> (ord(c_inst.upper()) - 65) & 1) != 0:
				c_inst = c_inst.upper() + ":\\"
				drive_name = drive_types[str(win32file.GetDriveType(c_inst))]
				lst_fll.append(c_inst + "   " + drive_name)
	else:
		#print("Platform not yet supported")                             ########### DISPLAY ERROR MESSAGE @to_GUI
		exit(-1)

	return lst_fll
Exemple #15
0
def USBackup_GetLogicalDrives():
    drv_bits = win32file.GetLogicalDrives()  #Getting available logical drives
    for d in range(0, 26):  #There will be maximum 26 logical drives (A-Z).
        control = 1 << d  #    1*2^d
        drive_name = '%s:\\' % chr(ord('A') + d)  # Getting the drive's name
        try:
            if drv_bits & control == False:  #  BitWISE AND. if the drive isnt available try to delete it from the allready_plugged list. So with this way we will be blocking unlimited copying.
                allready_plugged.remove(drive_name)

        except:
            pass
        if drv_bits & control:  #Again bitwise and. if the drive is available
            drive_name = '%s:\\' % chr(ord('A') + d)  #get the drive's name
            if drive_name not in allready_plugged:  #  if the drive's name isnt in the allready_plugged list it will start copying.
                allready_plugged.append(
                    drive_name
                )  #We are adding the drive's name to allready_plugged list so if we dont it unplug and replug it it wont copy it again.
                t = win32file.GetDriveType(
                    drive_name
                )  # Getting the drive type for example if the drive type is removable drive it will return "2"
                if t == win32file.DRIVE_REMOVABLE:  #Basically if its "2"
                    return drive_name  #Start Backup progress.
Exemple #16
0
    def __init__(self,
                 parent,
                 id,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 initialDir=""):
        self.id = id
        self.wp = wpath.wpath()
        self.dirCache = dircache.DirCache()

        self.darwinRootVolume = u""

        wx.TreeCtrl.__init__(
            self, parent, id, pos, size,
            wx.TR_HAS_BUTTONS | wx.TR_MULTIPLE | wx.TR_HIDE_ROOT)

        wx.EVT_TREE_ITEM_EXPANDING(self, self.id, self.OnExpanding)

        self.root = self.AddRoot(u"-")
        if sys.platform == "win32":
            mask = win32file.GetLogicalDrives()
            for i in xrange(26):
                if mask >> i & 1:
                    drive = unicode(chr(i + ord('A'))) + u":\\"
                    self.addVolume(drive, drive)
        else:
            if sys.platform == "darwin":
                volumes = self.dirCache.getFiles("/Volumes")
                for v in volumes:
                    if not v.startswith("."):
                        vol = u"/Volumes/%s" % v
                        self.addVolume(v, vol)
                        if self.wp.islink(vol):
                            self.darwinRootVolume = unicode(vol)
            else:
                self.addVolume(u"/", u"/")

        if initialDir:
            self.showPath(initialDir)
Exemple #17
0
    def getDiskSize(self):
        import win32file

        try:

            freespace = 0
            disksize = 0

            drives=[]
            sign=win32file.GetLogicalDrives()
            drive_all=["A:\\","B:\\","C:\\","D:\\","E:\\","F:\\","G:\\","H:\\","I:\\","J:\\","K:\\","L:\\","M:\\","N:\\","O:\\","P:\\","Q:\\","R:\\","S:\\","T:\\","U:\\","V:\\","W:\\","X:\\","Y:\\","Z:\\"]
            for i in range(25):
                if (sign & 1<<i):
                    if win32file.GetDriveType(drive_all[i]) == 3:
                        space = win32file.GetDiskFreeSpace(drive_all[i])
                        #print space
                        freespace += space[0]*space[1]*space[2]
                        disksize += space[0]*space[1]*space[3]

            return (freespace,disksize)
        
        except Exception as  myException:
            self.logger.error(myException)   
            return (0,0) 
import win32file
drive_list = []
drivebits = win32file.GetLogicalDrives()
for d in range(1, 26):
    mask = 1 << d
    if drivebits & mask:
        # here if the drive is at least there
        drname = '%c:\\' % chr(ord('A') + d)
        t = win32file.GetDriveType(drname)
        if t == win32file.DRIVE_REMOVABLE:
            drive_list.append(drname)
            print(drname)
import win32com.client

wmi = win32com.client.GetObject("winmgmts:")
for usb in wmi.InstancesOf("Win32_USBHub"):
    print usb.DeviceID
Exemple #19
0
def does_drive_exist(letter):
    import win32file
    return (win32file.GetLogicalDrives() >> (ord(letter.upper()) - 65) & 1) != 0
Exemple #20
0
 def enum_removable_drives(self):
     drivebits = win32file.GetLogicalDrives()
     return [
         d for d in range(1, 26)
         if (drivebits & (1 << d)) and self.is_removable(d)
     ]
Exemple #21
0
 def process1(self):
     drivebits = win32file.GetLogicalDrives()
     drives = win32api.GetLogicalDriveStrings()
     drives = drives.split('\000')[:-1]
     print(drives)