-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfdelete.py
More file actions
59 lines (54 loc) · 1.92 KB
/
Copy pathcfdelete.py
File metadata and controls
59 lines (54 loc) · 1.92 KB
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
#!/usr/bin/python
import pyrax, time, sys, multiprocessing, argparse, os, __builtin__
parser = argparse.ArgumentParser(description='Remove Cloud Files Fast')
parser.add_argument('--container', nargs='?', dest='cont', required=True, help="The Cloud Contain To Remove Objects From")
parser.add_argument('--username', nargs='?', dest='username', help="Your Cloud Username")
parser.add_argument('--password', nargs='?', dest='password', help="Your Cloud API Key")
parser.add_argument('--file', nargs='?', dest='file', help="Your Cloud API Key File")
parser.add_argument('--region', nargs='?', dest='region', help="Set the Cloud File region")
args = parser.parse_args()
def authenticate(username='', passwd='', path=''):
if username or passwd:
pyrax.set_credentials(username,passwd)
elif path:
pyrax.set_credential_file(os.path.expanduser(path))
else:
print "Authentication Failed... please use username/password or file to authenticate"
sys.exit()
def worker(num):
try:
global obj
print "Deleting:", obj[num].name
obj[num].delete()
#time.sleep(1 + random.random()*5)
#print num
except:
print "Unexpected error in worker:", sys.exc_info()
raise
def pooling(length):
try:
pool = multiprocessing.Pool(processes=20)
for num in xrange(length):
pool.apply_async(worker, [num])
#pool.apply(worker,[num])
pool.apply_async(time.sleep, 5)
pool.close()
pool.join()
except:
print "Unexpected error in pooling:", sys.exc_info()[0]
raise
if __name__ == "__main__":
authenticate(username=args.username,passwd=args.password,path=args.file)
cf = pyrax.connect_to_cloudfiles(region=args.region)
limit = 10000
marker = ""
obj = cf.get_container(args.cont).get_objects(limit=limit, marker=marker)
while obj:
try:
marker = obj.pop()
length = len(obj)
pooling(length)
obj = cf.get_container(args.cont).get_objects(limit=limit, marker=marker.name)
except:
print "Unexpected error:", sys.exc_info()[0]
raise