-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
/
Copy pathput.py
43 lines (35 loc) · 1.03 KB
/
put.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import re
import os
import time
import json
import base64
from hashlib import sha1
from iron_cache import *
key='KEY.%s.%s' %(os.environ.get('TRAVIS_REPO_SLUG','unk'),
os.environ.get('JOB_NAME','unk'))
if sys.version_info[0] > 2:
key = sha1(bytes(key,encoding='utf8')).hexdigest()[:8]+'.'
else:
key = sha1(key).hexdigest()[:8]+'.'
os.chdir(os.environ.get('HOME'))
cache = IronCache()
i=0
for i, fname in enumerate(sorted([x for x in os.listdir('.') if re.match("ccache.\d+$",x)])):
print("Putting %s" % key+str(i))
with open(fname,"rb") as f:
s= f.read()
value=base64.b64encode(s)
if isinstance(value, bytes):
value = value.decode('ascii')
item = cache.put(cache="travis", key=key+str(i), value=value,options=dict(expires_in=24*60*60))
# print("foo")
for i in range(i+1,20):
try:
item = cache.delete(key+str(i),cache='travis')
print("Deleted %s" % key+str(i))
except:
break
pass