Mercurial > hg > orthanc-stone
annotate Applications/Resources/LinuxStandardBaseUic.py @ 2086:40476d5e0cfd
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 17:03:54 +0100 |
parents | 07964689cb0b |
children | c23eef785569 |
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 |
2077
07964689cb0b
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
6 # Copyright (C) 2017-2023 Osimis S.A., Belgium |
07964689cb0b
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
7 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
8 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
9 # 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
|
10 # 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
|
11 # 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
|
12 # the License, or (at your option) any later version. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
13 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
14 # 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
|
15 # WITHOUT ANY WARRANTY; without even the implied warranty of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
17 # Affero General Public License for more details. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
18 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
19 # 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
|
20 # 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
|
21 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
22 |
1041
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 import subprocess |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import sys |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 if len(sys.argv) <= 1: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 sys.stderr.write('Please provide arguments for uic\n') |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 sys.exit(-1) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 path = '' |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 pos = 1 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 while pos < len(sys.argv): |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 if sys.argv[pos].startswith('-'): |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 pos += 2 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 else: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 path = sys.argv[pos] |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 break |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 if len(path) == 0: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 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
|
41 sys.exit(-1) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 with open(path, 'r') as f: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 lines = f.read().split('\n') |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 if (len(lines) > 1 and |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 lines[0].startswith('<?')): |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 content = '\n'.join(lines[1:]) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 else: |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 content = '\n'.join(lines) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 # Remove the source file from the arguments |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 args = sys.argv[1:pos] + sys.argv[pos+1:] |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 p = subprocess.Popen([ '/opt/lsb/bin/uic' ] + args, |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 stdin = subprocess.PIPE) |
95939fa925f6
LinuxStandardBaseUic.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 p.communicate(input = content) |