forked from chrissimpkins/macosx-versions-cleaner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_cleaner.py
61 lines (50 loc) · 1.72 KB
/
version_cleaner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# ------------------------------------------
#
# Mac OSX Versions Cleaner
# version_cleaner.py
# Copyright 2017 Christopher Simpkins
# MIT License
#
# ------------------------------------------
import os
import sys
import subprocess
import shutil
def execute(command):
try:
response = subprocess.call(command, shell=True)
if response == 0:
return True
else:
return False
except subprocess.CalledProcessError as cpe:
try:
sys.stderr.write(cpe.output)
except TypeError:
sys.stderr.write(str(cpe.output))
versions_dir = "/.DocumentRevisions-V100"
if os.path.isdir(versions_dir):
print("Versions directory size before cleaning:")
execute_command = "du -sh " + versions_dir
execute(execute_command)
print(" ")
try:
shutil.rmtree(versions_dir)
except Exception as e:
print("Error in the attempt to remove the files. Error message: " + str(e))
sys.exit(1)
if not os.path.isdir(versions_dir):
print("The versions directory was deleted.")
if sys.version_info[0] == 2:
user_response = raw_input("Reboot to complete cleanup? (y/n): ")
else:
user_response = input("Reboot to complete cleanup? (y/n): ")
if user_response.lower() == "y":
print("Rebooting...")
execute("reboot")
else:
print("Skipping system reboot. Please reboot your system manually to begin using document versioning again.")
else:
print("Unable to locate a versions directory at the path '" + versions_dir + "'. It appears that it was already cleaned.")
print("Complete the cleanup process by rebooting your system.")