-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe2db.py
More file actions
executable file
·37 lines (32 loc) · 968 Bytes
/
Copy pathpipe2db.py
File metadata and controls
executable file
·37 lines (32 loc) · 968 Bytes
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
#!/usr/bin/python
import boto
import gcs_oauth2_boto_plugin
import bz2
import hashlib
import sys
from datetime import datetime
assert len(sys.argv) == 3
recipient = sys.argv[1]
sender = sys.argv[2]
assert recipient
assert sender
try:
bucket_name = "***"
data = bz2.compress(sys.stdin.read())
checksum = hashlib.md5(data).hexdigest()
recipient = recipient.lower()
sender = sender.lower()
time = datetime.now()
key_name = "%s/%s/%04d/%02d/%s-%s.txt.bz2" % (
bucket_name, recipient, time.year, time.month, time.isoformat(), checksum)
uri = boto.storage_uri(key_name, "gs")
key = uri.new_key()
key.set_metadata("time", time.isoformat())
key.set_metadata("recipient", recipient)
key.set_metadata("sender", sender)
key.set_metadata("content-encoding", "bzip2")
key.set_metadata("content-type", "text/plain")
key.set_contents_from_string(data, replace=False)
except:
print(sys.exc_info())
sys.exit(75) # postfix temporary failure