PythonからElixir Reportのレポートサーバーにアクセスするサンプルコード
修訂 | d3b1da552d30f2c903820f7ebbd8bccf486b63f8 (tree) |
---|---|
時間 | 2014-12-03 01:19:27 |
作者 | Hiromichi Matsushima <hylom@Hiro...> |
Commiter | Hiromichi Matsushima |
code cleaning
@@ -17,6 +17,7 @@ class ReportServer: | ||
17 | 17 | self.opener = None |
18 | 18 | |
19 | 19 | def open_path(self, path, param=None): |
20 | + "指定したパスにリクエストを投げる" | |
20 | 21 | if self.opener == None: |
21 | 22 | self.login() |
22 | 23 |
@@ -28,6 +29,7 @@ class ReportServer: | ||
28 | 29 | return resp |
29 | 30 | |
30 | 31 | def repository(self): |
32 | + "リポジトリ一覧を取得する" | |
31 | 33 | path = '/repository?mode=xml' |
32 | 34 | resp = self.open_path(path) |
33 | 35 | if resp.code == 200: |
@@ -36,6 +38,7 @@ class ReportServer: | ||
36 | 38 | return None |
37 | 39 | |
38 | 40 | def data(self, path, params={}): |
41 | + "データソースからデータをXML形式で取得する" | |
39 | 42 | param = params.copy() |
40 | 43 | param["mime-type"] = "text/xml" |
41 | 44 | resp = self.open_path(path, param) |
@@ -45,6 +48,7 @@ class ReportServer: | ||
45 | 48 | return None |
46 | 49 | |
47 | 50 | def login(self): |
51 | + "ログイン処理を行う" | |
48 | 52 | # 初めにCookieを取得する |
49 | 53 | if self.opener == None: |
50 | 54 | path = '/' |
@@ -55,21 +59,20 @@ class ReportServer: | ||
55 | 59 | cookies.extract_cookies(resp, req) |
56 | 60 | self.cookies = cookies |
57 | 61 | |
58 | - # set to use cookies | |
62 | + # 取得したCookieを使用する | |
59 | 63 | self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookies)) |
60 | 64 | |
61 | - # request with session cookie | |
65 | + # ログインリクエストを投げる | |
62 | 66 | path = '/login.html' |
63 | 67 | param = { |
64 | 68 | "username": self.user, |
65 | 69 | "password": self.password |
66 | 70 | } |
67 | - # url = self.path_to_url(path) | |
68 | - # resp = self.opener.open(url, urllib.urlencode(param)) | |
69 | 71 | resp = self.open_path(path, param) |
70 | 72 | return resp.code |
71 | 73 | |
72 | 74 | def logout(self): |
75 | + "ログアウト処理を行う" | |
73 | 76 | if self.opener == None: |
74 | 77 | return 200 |
75 | 78 |
@@ -78,6 +81,7 @@ class ReportServer: | ||
78 | 81 | return resp.code |
79 | 82 | |
80 | 83 | def path_to_url(self, path): |
84 | + "パスをURLに変換する" | |
81 | 85 | t = (self.scheme, |
82 | 86 | '{0}:{1}'.format(self.host, self.port), |
83 | 87 | path, |