Mercurial > hg > orthanc-wsi
comparison Resources/OrthancWSIClearCache.py @ 73:a8c90aa32ca6
LRU caching of pyramids, OrthancWSIClearCache script
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 28 Nov 2016 16:51:19 +0100 |
parents | |
children | ff0ef01c332c |
comparison
equal
deleted
inserted
replaced
72:ea6309f70f1f | 73:a8c90aa32ca6 |
---|---|
1 #!/usr/bin/python | |
2 | |
3 # Orthanc - A Lightweight, RESTful DICOM Store | |
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
5 # Department, University Hospital of Liege, Belgium | |
6 # | |
7 # This program is free software: you can redistribute it and/or | |
8 # modify it under the terms of the GNU Affero General Public License | |
9 # as published by the Free Software Foundation, either version 3 of | |
10 # the License, or (at your option) any later version. | |
11 # | |
12 # This program is distributed in the hope that it will be useful, but | |
13 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 # Affero General Public License for more details. | |
16 # | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 import base64 | |
22 import httplib2 | |
23 import json | |
24 import os | |
25 import sys | |
26 | |
27 if len(sys.argv) != 3 and len(sys.argv) != 5: | |
28 print(""" | |
29 Script to reinitialize the cache of the whole-slide imaging plugin for | |
30 Orthanc. Please make sure that Orthanc is running before starting this | |
31 script. | |
32 | |
33 Usage: %s [hostname] [HTTP port] | |
34 Usage: %s [hostname] [HTTP port] [username] [password] | |
35 For instance: %s 127.0.0.1 8042 | |
36 """ % (sys.argv[0], sys.argv[0], sys.argv[0])) | |
37 exit(-1) | |
38 | |
39 | |
40 METADATA=4200 | |
41 | |
42 | |
43 def RunHttpRequest(uri, method, body = None): | |
44 http = httplib2.Http() | |
45 headers = { } | |
46 | |
47 if len(sys.argv) == 5: | |
48 username = sys.argv[4] | |
49 password = sys.argv[5] | |
50 | |
51 # h.add_credentials(username, password) | |
52 | |
53 # This is a custom reimplementation of the | |
54 # "Http.add_credentials()" method for Basic HTTP Access | |
55 # Authentication (for some weird reason, this method does not | |
56 # always work) | |
57 # http://en.wikipedia.org/wiki/Basic_access_authentication | |
58 headers['authorization'] = 'Basic ' + base64.b64encode(username + ':' + password) | |
59 | |
60 url = 'http://%s:%d/%s' % (sys.argv[1], int(sys.argv[2]), uri) | |
61 resp, content = http.request(url, method, | |
62 body = body, | |
63 headers = headers) | |
64 | |
65 if resp.status != 200: | |
66 raise Exception('Cannot %s on URL %s, HTTP status %d ' | |
67 '(Is Orthanc running? Is there a password?)' % | |
68 (method, url, resp.status)) | |
69 else: | |
70 return content.decode('utf8') | |
71 | |
72 | |
73 for instance in json.loads(RunHttpRequest('/instances', 'GET')): | |
74 print('Clearing cache for instance %s' % instance) | |
75 RunHttpRequest('/instances/%s/metadata/%s' % (instance, METADATA), 'DELETE') | |
76 | |
77 print('The WSI cache was successfully cleared') |