Skip to content

Commit 4c3e9ab

Browse files
authored
Merge pull request #12 from sbsos/main
Added more hard-drive capturing, Fixing memo length, and replotting bug
2 parents a1496ae + 558a39f commit 4c3e9ab

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

hotplotterclient/hard_drive_controller.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import shutil
22
import psutil
33
import os
4+
import subprocess
5+
import re
46

57
class hard_drive(object):
68
total = 0
@@ -18,7 +20,7 @@ def __init__(self, total, free, drive_name):
1820

1921
class hard_drive_controller(object):
2022
available_drive_letters = ["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:/"]
21-
supported_hard_drive_formats = ['vfat','ext4', 'ext3', 'ext2', 'fat32', 'ntfs', 'fuseblk']
23+
supported_hard_drive_formats = ['vfat','ext4', 'ext3', 'ext2', 'fat32', 'ntfs', 'fuseblk', 'tmpfs']
2224

2325
def get_hard_drives_linux(self):
2426
hard_drives = []
@@ -34,13 +36,28 @@ def get_hard_drives_linux(self):
3436

3537
def get_hard_drives_windows(self):
3638
hard_drives = []
37-
for available_drive in self.available_drive_letters:
39+
mountvol_hds = []
40+
result = subprocess.run(['mountvol'], capture_output=True, text=True)
41+
parsed_hard_drives = re.findall('[A-Z]:\\\.*', result.stdout)
42+
43+
for hd in parsed_hard_drives:
44+
try:
45+
formatted_hd = hd.replace("\\","/")
46+
mountvol_hds.append(formatted_hd)
47+
hd_object = self.get_hard_disk_space(formatted_hd)
48+
hard_drives.append(hd_object)
49+
except Exception:
50+
continue
51+
52+
#network drives don't show up in mountvol. manually iterate to see if they have any network storage
53+
not_checked_drives = [i for i in self.available_drive_letters if i not in mountvol_hds]
54+
for hd in not_checked_drives:
3855
try:
39-
hd = self.get_hard_disk_space(available_drive)
40-
hard_drives.append(hd)
41-
56+
hd_object = self.get_hard_disk_space(hd)
57+
hard_drives.append(hd_object)
4258
except Exception:
4359
continue
60+
4461
return hard_drives
4562

4663
def get_hard_drives(self):
@@ -65,3 +82,4 @@ def get_hard_disk_space(self, drive):
6582

6683
if __name__ == '__main__':
6784
controller = hard_drive_controller()
85+
hds = controller.get_hard_drives_windows()

hotplotterclient/replotting.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class drivePlots(object):
55
driveName = ""
66
plots = []
77
plotTypes = ""
8-
offset = 58
8+
formatLengthOffset = 52
99
def __init__(self, driveName, plotTypes):
1010
self.driveName = driveName
1111
self.populatePlots(PlotTypes.OgPlots)
@@ -14,6 +14,10 @@ def filterPlotsInDirectory(self, files):
1414
plots = filter(lambda c: 'plot' in c, files)
1515
return plots
1616

17+
def getLength(self, byteArray):
18+
length = byteArray[1] >> byteArray[0]
19+
return length
20+
1721
def populatePlots(self, filterPlotType):
1822
files = os.listdir(self.driveName)
1923
plots = self.filterPlotsInDirectory(files)
@@ -25,13 +29,15 @@ def populatePlots(self, filterPlotType):
2529
plotWithFullPath = self.driveName + plot
2630

2731
with open(plotWithFullPath, "rb") as plotFile:
28-
plotFile.read(self.offset)
32+
plotFile.read(self.formatLengthOffset)
2933
res = plotFile.read(2)
34+
formatLength = self.getLength(res)
35+
plotFile.read(formatLength)
3036

31-
#Two Byte to int, w/ big to achieve their Utility.TwoByteToInt
32-
length = res[1] >> res[0]
37+
memo = plotFile.read(2)
38+
memoLength = self.getLength(memo)
3339

34-
plotType = self.getPlotType(length)
40+
plotType = self.getPlotType(memoLength)
3541
if plotType == filterPlotType:
3642
self.plots.append(plotWithFullPath)
3743

@@ -46,8 +52,10 @@ def getPlotType(self, memoLength):
4652
return None
4753

4854
def getPlot(self):
49-
plotName = self.plots.pop()
50-
return plotName
55+
if len(self.plots) > 0:
56+
plotName = self.plots.pop()
57+
return plotName
58+
return None
5159

5260

5361
class replotting(object):
@@ -89,5 +97,3 @@ class PlotTypes(object):
8997
if __name__ == '__main__':
9098
replotting = replotting()
9199
replotting.addDrivePlots('A:/Plots', '1', True)
92-
plotName = replotting.deletePlot('A:/Plots', '1')
93-
print(plotName)

0 commit comments

Comments
 (0)