Skip to content

Commit 9a0edfd

Browse files
committed
Merge pull request #1 from cfin-tools/distribute
Distribute
2 parents 3444277 + 32169ad commit 9a0edfd

File tree

3 files changed

+70
-20
lines changed

3 files changed

+70
-20
lines changed

setup.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
from setuptools import setup, Command
3+
4+
# Utility function to read the README file.
5+
# Used for the long_description. It's nice, because now 1) we have a top level
6+
# README file and 2) it's easier to type in the README file than to put a raw
7+
# string in below ...
8+
def read(fname):
9+
return open(os.path.join(os.path.dirname(__file__), fname)).read()
10+
11+
class CleanCommand(Command):
12+
"""Custom clean command to tidy up the project root."""
13+
user_options = []
14+
def initialize_options(self):
15+
pass
16+
def finalize_options(self):
17+
pass
18+
def run(self):
19+
os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info')
20+
21+
setup(
22+
name = "stormdb",
23+
version = "0.1",
24+
author = "Christopher Bailey",
25+
author_email = "cjb@cfin.au.dk",
26+
description = ("Access to StormDb @ CFIN"),
27+
license = "BSD",
28+
keywords = "code",
29+
url = "https://github.com/cfin-tools/stormdb.git",
30+
packages=['stormdb'],
31+
long_description=read('README.md'),
32+
classifiers=[
33+
"Development Status :: 3 - Alpha",
34+
"Topic :: Utilities",
35+
"License :: OSI Approved :: BSD License",
36+
],
37+
cmdclass={
38+
'clean': CleanCommand,
39+
}
40+
41+
)
42+
File renamed without changes.

access.py renamed to stormdb/access.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def __init__(self, proj_code, stormdblogin='~/.stormdblogin', username=None, ver
2828
print 'ERROR: Bad project code?'
2929
sysexit(-1)
3030

31+
self.proj_code = proj_code
32+
self._server = 'http://hyades00.pet.auh.dk/modules/StormDb/extract/'
33+
self._wget_cmd = 'wget -qO - test ' + self._server
34+
3135
try:
3236
with open(os.path.expanduser(stormdblogin)):
3337
if verbose:
@@ -56,10 +60,6 @@ def __init__(self, proj_code, stormdblogin='~/.stormdblogin', username=None, ver
5660
fout.close()
5761
os.chmod(os.path.expanduser(stormdblogin), 0400)
5862

59-
self.proj_code = proj_code
60-
self._server = 'http://hyades00.pet.auh.dk/modules/StormDb/extract/'
61-
self._wget_cmd = 'wget -qO - test ' + self._server
62-
6363
@staticmethod
6464
def _wget_error_handling(stdout):
6565
if 'error' in stdout:
@@ -120,32 +120,40 @@ def get_studies(self, subj_id, modality=None, unique=True, verbose=False):
120120
stud_list = [x for x in stud_list if x]
121121

122122
if modality:
123-
for study in stud_list:
123+
for ii,study in enumerate(stud_list):
124124
url = 'modalities?' + self._login_code + '\\&projectCode=' + self.proj_code + '\\&subjectNo=' + \
125125
subj_id + '\\&study=' + study
126126
output = self._wget_system_call(url).split('\n')
127127
#print output, '==', modality
128128

129-
for entry in output:
130-
if entry == modality:
131-
if unique:
132-
return study
133-
### NB!! This only matches first hit! If subject contains several studies
134-
### with this modality,
135-
### only first one is returned... Fix me!
136-
else:
137-
# must re-write code a bit to accommodate the existence of
138-
# several studies containing the desired modality...
139-
print "Error: non-unique modalities not implemented yet!"
140-
sysexit(-1)
129+
if modality in output:
130+
if unique:
131+
return study # NB: returns string! Should change to [study] to return list...
132+
else:
133+
stud_list[ii] = None
134+
135+
stud_list = filter(None, stud_list)
136+
# for entry in output:
137+
# if entry == modality:
138+
# if unique:
139+
# return study
140+
# ### NB!! This only matches first hit! If subject contains several studies
141+
# ### with this modality,
142+
# ### only first one is returned... Fix me!
143+
# else:
144+
# stud_list = [x for x in stud_list if x
145+
# else:
146+
# # must re-write code a bit to accommodate the existence of
147+
# # several studies containing the desired modality...
148+
# print "Error: non-unique modalities not implemented yet!"
149+
# sysexit(-1)
141150

142151
# If we get this far, no studies found with the desired modality
143152
if verbose:
144153
print "No studies found with the desired modality"
145-
return None
154+
return None
146155

147-
else:
148-
return stud_list
156+
return stud_list
149157

150158
def get_series(self, subj_id, study, modality, verbose=False):
151159

0 commit comments

Comments
 (0)