-
Notifications
You must be signed in to change notification settings - Fork 6
/
check
executable file
·69 lines (61 loc) · 2.23 KB
/
check
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
62
63
64
65
66
67
68
69
#!/usr/local/bin/python
from __future__ import print_function
from google_drive_concourse_resource_common import getServiceInstance
from google_drive_concourse_resource_common import listFilesinFolder
import json
import sys
"""Takes a JSON request from stdin and lists matching files on a google-drive \
folder
Args:
fID: Folder ID for the file to look for
fName: name of the file to look for (including extension)
Returns:
An Empty array for the moment till we figure out versioning
"""
fID = ''
fName = ''
cEmail = ''
pID = ''
cID = ''
pKey = ''
def main():
req = json.load(sys.stdin)
if req:
# print(json.dumps(req), file=sys.stderr)
fID = (req['source']['drive_folder_id'])
if 'version' in req and req['version'] is not None \
and 'file_name' in req['version']:
fName = (req['version']['file_name'])
elif 'file_name' in req['source']:
fName = (req['source']['file_name'])
else:
print(json.dumps([]))
sys.exit(0)
cEmail = (req['source']['drive_client_email'])
pID = (req['source']['drive_private_key_id'])
cID = (req['source']['drive_client_id'])
pKey = (req['source']['drive_private_key'])
else:
print('No suitable request received', file=sys.stderr)
sys.exit(1)
drive_service = getServiceInstance(cEmail, pID, cID, pKey)
response = listFilesinFolder(drive_service, fID, fName)
if response:
# print(response.get('description'), file=sys.stderr)
# metadata = [file.get('description')]
# print('File: {0} '.format(file.get('id')), file=sys.stderr)
if response.get('description'):
# print('Description: {0}'.format(response.get('description')), file=sys.stderr)
metadata = response.get('description')
metadata = metadata.replace('\n', ' ')
print(metadata, file=sys.stderr)
# metadata = metadata.replace(':', '')
# metadata = []
print(json.dumps([{
"file_name": response.get('title'),
"id": response.get('id')}]))
# print ('Here', file=sys.stderr)
else:
print(json.dumps([]))
if __name__ == '__main__':
main()