1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 __all__ = (
25 "DocumentService",
26 )
27
28 import os
29 import json
30 import sys
31 from rest.client import RestClient
32 from error import *
33
36 self.projects = projects
37
39 res, content = self.projects.restclient.request_get('/projects/p/%s/iterations/i/%s/r'%(projectid, iterationid))
40
41 if res['status'] == '200' or res['status'] == '304':
42 list = json.loads(content)
43 filelist = [file.get('name') for file in list]
44 return filelist
45
47 """
48 Push the json object to flies server
49 @param projectid: id of project
50 @param iterationid: id of iteration
51 @param resources: json object of the content that want to commit to flies server
52 @return: True
53 @raise UnAuthorizedException:
54 @raise BadRequestBodyException:
55 @raise SameNameDocumentException:
56 """
57 if projectid and iterationid:
58 try:
59 self.projects.iterations.get(projectid, iterationid)
60 except NoSuchProjectException as e:
61 print "%s :%s"%(e.expr, e.msg)
62 sys.exit()
63
64 headers = {}
65 headers['X-Auth-User'] = self.projects.username
66 headers['X-Auth-Token'] = self.projects.apikey
67
68 res, content = self.projects.restclient.request_post('/projects/p/%s/iterations/i/%s/r'%(projectid,iterationid), args=resources, headers=headers)
69
70 if res['status'] == '201':
71 return True
72 elif res['status'] == '401':
73 raise UnAuthorizedException('Error 401', 'UnAuthorized Operation')
74 elif res['status'] == '400':
75 raise BadRequestBodyException('Error 400', 'Unable to read request body.')
76 elif res['status'] == '409':
77 raise SameNameDocumentException('Error 409', 'A document with same name already exists.')
78
80 """
81 Get translation content of file from Flies server
82 @param lang: language
83 @param projectid: Id of project
84 @param iterationid: Id of iteration
85 @param file: name of document
86 @return: translation content of document
87 @raise UnAvaliableResourceException:
88 @raise UnAuthorizedException:
89 """
90 if projectid and iterationid:
91 try:
92 self.projects.iterations.get(projectid, iterationid)
93 except NoSuchProjectException as e:
94 print "%s :%s"%(e.expr, e.msg)
95
96
97 res, content = self.projects.restclient.request_get('/projects/p/%s/iterations/i/%s/r/%s/translations/%s'%(projectid, iterationid, file, lang))
98
99 if res['status'] == '200' or res['status'] == '304':
100 return content
101 elif res['status'] == '404':
102 raise UnAvaliableResourceException('Error 404', 'The requested resource is not available')
103 elif res['status'] == '401':
104 raise UnAuthorizedException('Error 401', 'UnAuthorized Operation')
105
108