summaryrefslogtreecommitdiffstats
path: root/linhes/linhes-system/balance_storage_groups.py
diff options
context:
space:
mode:
Diffstat (limited to 'linhes/linhes-system/balance_storage_groups.py')
-rwxr-xr-xlinhes/linhes-system/balance_storage_groups.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/linhes/linhes-system/balance_storage_groups.py b/linhes/linhes-system/balance_storage_groups.py
index e525a27..d91da60 100755
--- a/linhes/linhes-system/balance_storage_groups.py
+++ b/linhes/linhes-system/balance_storage_groups.py
@@ -1,7 +1,8 @@
#!/usr/bin/python
-import argparse, glob, operator, os, random, shutil, subprocess, sys, signal
+import argparse, glob, operator, os, random, shutil, subprocess, sys, signal, time
shouldQuit = False
+movingFiles = False
def getFreeSpaceForDir(dir):
stats = os.statvfs(dir)
@@ -24,9 +25,12 @@ def sizeof_fmt(num, suffix='B'):
return "%.1f %s%s" % (num, 'Yi', suffix)
def signal_handler(signal, frame):
- print("\nWill quit when file has been moved.\nMoving File...")
- global shouldQuit
- shouldQuit = True
+ if movingFiles:
+ print("\nWill quit when file has been moved.\nMoving File...")
+ global shouldQuit
+ shouldQuit = True
+ else:
+ sys.exit(0)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
@@ -116,26 +120,33 @@ if __name__ == '__main__':
print(filePathToMove + " is too big to move to " + leastFull[0])
sys.exit()
- print("------------------------------------------------")
- print("Move File:")
- print(" " + filePathToMove)
- print(" Size: " + sizeof_fmt(os.path.getsize(filePathToMove)))
- print("To:")
- print(" " + leastFull[0])
- print(" Available: " + sizeof_fmt(getFreeSpaceForDir(leastFull[0])))
-
# Move file
if cmdargs.checkonly:
print("------------------------------------------------")
print("Check Only option was used. No files were moved.")
shouldQuit = True
else:
+ isBusy = True
+ while isBusy:
+ if shouldQuit:
+ sys.exit(0)
+ print("------------------------------------------------")
+ print("Checking System Status...")
+ if subprocess.call(["/usr/bin/python", "/usr/bin/idle.py", "-s"]):
+ print(" System is busy. The file will not be moved.")
+ print(" Waiting 5 minutes before trying again.")
+ time.sleep(300)
+ else:
+ isBusy = False
print("------------------------------------------------")
- print("Checking System Status...")
- if subprocess.call(["/usr/bin/python", "/usr/bin/idle.py", "-s"]):
- print(" System is busy. The file will not be moved.")
- sys.exit()
+ print("Move File:")
+ print(" " + filePathToMove)
+ print(" Size: " + sizeof_fmt(os.path.getsize(filePathToMove)))
+ print("To:")
+ print(" " + leastFull[0])
+ print(" Available: " + sizeof_fmt(getFreeSpaceForDir(leastFull[0])))
print("Moving File...")
+ movingFiles = True
try:
shutil.move(filePathToMove, leastFull[0])
# eg. src and dest are the same file
@@ -151,3 +162,4 @@ if __name__ == '__main__':
for p in pngFiles:
os.remove(p)
print(" " + p)
+ movingFiles = False