Mercurial > hg > orthanc-stone
annotate Applications/Resources/LinuxStandardBaseUic.py @ 1830:fa38043b14b0
todo
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 29 May 2021 11:14:20 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
1041
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
3 # Stone of Orthanc |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
7 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
8 # This program is free software: you can redistribute it and/or |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
9 # modify it under the terms of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
10 # as published by the Free Software Foundation, either version 3 of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
11 # the License, or (at your option) any later version. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
12 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, but |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
14 # WITHOUT ANY WARRANTY; without even the implied warranty of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
16 # Affero General Public License for more details. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
17 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
18 # You should have received a copy of the GNU Affero General Public License |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
20 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
21 |
1041
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 import subprocess |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 import sys |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 if len(sys.argv) <= 1: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 sys.stderr.write('Please provide arguments for uic\n') |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 sys.exit(-1) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 path = '' |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 pos = 1 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 while pos < len(sys.argv): |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 if sys.argv[pos].startswith('-'): |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 pos += 2 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 else: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 path = sys.argv[pos] |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 break |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 if len(path) == 0: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 sys.stderr.write('Unable to find the input file in the arguments to uic\n') |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 sys.exit(-1) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 with open(path, 'r') as f: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 lines = f.read().split('\n') |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 if (len(lines) > 1 and |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 lines[0].startswith('<?')): |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 content = '\n'.join(lines[1:]) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 else: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 content = '\n'.join(lines) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 # Remove the source file from the arguments |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 args = sys.argv[1:pos] + sys.argv[pos+1:] |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 p = subprocess.Popen([ '/opt/lsb/bin/uic' ] + args, |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 stdin = subprocess.PIPE) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 p.communicate(input = content) |