當前位置: 首頁>>代碼示例>>Python>>正文


Python Drive.reconnect方法代碼示例

本文整理匯總了Python中drive.Drive.reconnect方法的典型用法代碼示例。如果您正苦於以下問題:Python Drive.reconnect方法的具體用法?Python Drive.reconnect怎麽用?Python Drive.reconnect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在drive.Drive的用法示例。


在下文中一共展示了Drive.reconnect方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mount

# 需要導入模塊: from drive import Drive [as 別名]
# 或者: from drive.Drive import reconnect [as 別名]
    def mount(drive_name):
        '''
        Reconnects a drive as a volume.
        Any data on the drive is preserved.
        Returns the volume.
        '''
        drive = Drive.reconnect(drive_name)
        vol = Volume()

        block = drive.read_block(0).split(b'\n')
        volinfosize= int(bytes.decode(block[0]))
        volinfo =b''
        volinfo+=drive.read_block(0)
        if volinfosize!=1:
            for i in range (1,volinfosize+1):
                volinfo+=drive.read_block(i)
        vol.setSize(int(bytes.decode(block[2])))
        vol.setDrive(drive)

        bmpArr =[]
        
        bmp = bytes.decode(volinfo.split(b'\n')[3])

        for i,v in enumerate(bmp):
            if v == 'x':
                bmpArr.append(1)
            else:
                bmpArr.append(0)
        vol.setVolInfo(volinfo)
        vol.setBitmapArray(bmpArr)
        return vol
開發者ID:raouldc,項目名稱:File-System,代碼行數:33,代碼來源:filesystem.py

示例2: mount

# 需要導入模塊: from drive import Drive [as 別名]
# 或者: from drive.Drive import reconnect [as 別名]
	def mount(drive_name):
		'''
		Reconnects a drive as a volume.
		Any data on the drive is preserved.
		Returns the volume.
		'''
		drive = Drive.reconnect(drive_name)
		inputt = drive.read_block(0)
		data = inputt.splitlines()
		length = int(data[0])
		i = 1
		while i < length:
			inputt = drive.read_block(i)
			data.extend(inputt.splitlines())
			i+=1
		i = 1
		outcome = False
		
		data[len(data)-1] = data[len(data)-1].rstrip()
	
		while len(data) > (i+1):
			while len(data) > (i+1) and data[i+1].isdigit() == outcome:
				data[i] += data[i+1]
				data.pop(i+1)
			i+=1
			outcome = not outcome
		
		volume = Volume(drive, data[1])
		for i in range(len(data[3])):                #TODO Needs better fix
			if data[3][i] == 120:
				volume.bmap[i] = b'x'
		volume.import_files()

		return volume
開發者ID:Dahaden,項目名稱:370a2,代碼行數:36,代碼來源:filesystem.py

示例3: mount

# 需要導入模塊: from drive import Drive [as 別名]
# 或者: from drive.Drive import reconnect [as 別名]
    def mount(drive_name):
        drive = Drive.reconnect(drive_name)
        allVolumeData = drive.read_block(0).decode()
        numOfBlocksUsed = allVolumeData.split('\n',1)[0]
        if int(numOfBlocksUsed)>1:
            for i in range(1,int(numOfBlocksUsed)):
                allVolumeData+=drive.read_block(i).decode() 
                
        data = allVolumeData.split('\n')
        numOfBlocksUsed=int(data[0])
        name = data[1]
        #dont need this
        numOfBlocksInDrive = int(data[2])
        bitmap = data[3]
        rootIndex = int(data[4])
        usedDrives=[False]*numOfBlocksInDrive
        Volume.calculate_volume_data_blocks(name, drive, rootIndex)
        numOfDataBlocks = Volume.calculate_volume_data_blocks(name, drive, rootIndex )
        for i in range(numOfDataBlocks):
            usedDrives[i]=True
        usedDrives[rootIndex]=True
        volume = Volume(drive, name.encode(), rootIndex, usedDrives, numOfBlocksUsed)
        #read the rootdirectory
        rootString = drive.read_block(rootIndex).decode()
        root= rootString.split('\n')
        for i in range(len(root)):
            if root[i].isdigit():
                if int(root[i])!=0:

                    fileData =  volume.drive.read_block(int(root[i])).decode().split('\n')
                    for i in range(0,len(fileData)-1,3):
                        fileName = fileData[i]
                        fileDataLength =  fileData[i+1]
                        fileStart = fileData[i + 2]
                        #then go into the fileStart
                        fileDirectory = volume.drive.read_block(int(fileStart))
                        fileDirectory = fileDirectory.decode().split('\n')
                        dataLocations = []
                        for j in range(len(fileDirectory)):
                            if fileDirectory[j].isdigit():
                                dataLocations.append(fileDirectory[j])
                        #now that we have all the locations of the data, we can read all the locations and concatinate them
                        dataOnFile = b''
                        for k in range(len(dataLocations)):
                            dataOnFile+=volume.drive.read_block(int(dataLocations[k]))
                        #only want the first n bits
                        dataOnFile = dataOnFile[:int(fileDataLength)]    
                        file = volume.open(fileName.encode())
                        file.write(0, dataOnFile)
                        print (file.data)
                    
        #print (root)
        
        return volume
        '''
開發者ID:qisaw,項目名稱:se370_Assignment_2,代碼行數:57,代碼來源:filesystem.py

示例4: test_reconnect_drive

# 需要導入模塊: from drive import Drive [as 別名]
# 或者: from drive.Drive import reconnect [as 別名]
 def test_reconnect_drive(self):
      blocks = 10
      drive_name = 'driveC.txt'
      drive = Drive.format(drive_name, blocks)
      drive.disconnect()
      with self.assertRaises(IOError):
          Drive.reconnect('badname')
      drive = Drive.reconnect(drive_name)
      self.assertEqual(blocks * Drive.BLK_SIZE, drive.num_bytes())
      name = b'reconnect volume'
      volume = Volume.format(drive, name)
      volume.unmount()
      with self.assertRaises(IOError):
          Volume.mount('driveZ')
      volume = Volume.mount(drive_name)
      self.assertEqual(1, volume.volume_data_blocks())
      self.assertEqual(name, volume.name())
      self.assertEqual(blocks, volume.size())
      self.assertEqual(b'x--------x', volume.bitmap())
      self.assertEqual(9, volume.root_index())
      volume.unmount()
開發者ID:raouldc,項目名稱:File-System,代碼行數:23,代碼來源:filesystemtest.py

示例5: mount

# 需要導入模塊: from drive import Drive [as 別名]
# 或者: from drive.Drive import reconnect [as 別名]
    def mount(drive_name):
        '''
        Reconnects a drive as a volume.
        Any data on the drive is preserved.
        Returns the volume.
        '''
        print("mounting volume: " + str(drive_name))

        volume = Volume()
        volume.drive = Drive.reconnect(drive_name)
        # volume.drive_name = drive.name
        # int
        volume.block_info_occupied_blocks_num = int(volume.drive.read_block(0).split()[0].decode())
        # int
        volume.BLK_SIZE = volume.drive.BLK_SIZE
        # print("mounting: " + str(volume.drive.read_block(0)))
        volumeInfoByte = volume.read_block_info()
        volumeInfoStr = volumeInfoByte.decode().split('\n')

        # volume.volumeName = volumeInfoStr[1].encode()
        # volume.numberOfBlocks = int(volumeInfoStr[2])
        # volume.bitmapStr = volumeInfoStr[3]
        # volume.rootDirIndex = int(volumeInfoStr[4])
        # volume.rootFileList = volume.getRootFileList()
        # volume.openingFiles = []
        print("volumeInfoStr: " + str(volumeInfoStr))
        # byte
        volume.volume_name = volumeInfoStr[1].encode()
        # int
        volume.total_num_of_blocks = int(volumeInfoStr[2])
        # str
        volume.bitmapStr = volumeInfoStr[3]
        print("mounting volume with bitmap: " + volume.bitmapStr)
        # int int(volumeInfoStr[4]) [s.strip() for s in content_byte.decode().split("\n") if s.strip() != ""]
        volume.root_files_block_index = [int(i) for i in volumeInfoStr[4].split() if i.strip() != "" and i.isdigit()]
        print("root_files_block_index: " + str(volume.root_files_block_index))
        # array
        volume.rootFileList = volume.get_root_file_list()
        volume.openingFiles = []
        return volume
開發者ID:1and1get2,項目名稱:cs340ass2,代碼行數:42,代碼來源:filesystem.py


注:本文中的drive.Drive.reconnect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。