Skip to content

Commit d250bc8

Browse files
committed
updates
1 parent 9cca278 commit d250bc8

File tree

7 files changed

+175
-27
lines changed

7 files changed

+175
-27
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Vanessa Sochat
3+
Copyright (c) 2016-2017 Vanessa Sochat
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

singularity/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
'''
2+
3+
The MIT License (MIT)
4+
5+
Copyright (c) 2016-2017 Vanessa Sochat
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
'''
26+
127
from singularity.version import __version__
228

329
__all__ = ['analysis', 'build', 'views', 'api',

singularity/analysis/classify.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
classify.py: part of singularity package
55
functions to tag and classify images
66
7+
The MIT License (MIT)
8+
9+
Copyright (c) 2016-2017 Vanessa Sochat
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy
12+
of this software and associated documentation files (the "Software"), to deal
13+
in the Software without restriction, including without limitation the rights
14+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the Software is
16+
furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included in all
19+
copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
SOFTWARE.
28+
729
'''
830

931
from glob import glob
@@ -66,6 +88,7 @@ def get_diff(container=None,image_package=None,sudopw=None):
6688
similar_package = "%s/docker-os/%s.img.zip" %(get_package_base(),most_similar)
6789

6890
comparison = compare_containers(image_package1=image_package,
91+
container1=container,
6992
image_package2=similar_package,
7093
by='files.txt')['files.txt']
7194

singularity/app.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
'''
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2016-2017 Vanessa Sochat
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
24+
'''
25+
26+
127
from singularity.views.trees import (
228
container_tree,
329
container_similarity,

singularity/cli.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55
66
Last updated: Singularity version 2.1
77
8+
The MIT License (MIT)
9+
10+
Copyright (c) 2016-2017 Vanessa Sochat
11+
12+
Permission is hereby granted, free of charge, to any person obtaining a copy
13+
of this software and associated documentation files (the "Software"), to deal
14+
in the Software without restriction, including without limitation the rights
15+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
copies of the Software, and to permit persons to whom the Software is
17+
furnished to do so, subject to the following conditions:
18+
19+
The above copyright notice and this permission notice shall be included in all
20+
copies or substantial portions of the Software.
21+
22+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28+
SOFTWARE.
29+
830
'''
931

1032
from singularity.utils import (

singularity/package.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
'''
44
package.py: part of singularity package
55
6+
The MIT License (MIT)
7+
8+
Copyright (c) 2016-2017 Vanessa Sochat
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.
27+
628
'''
729

830
from singularity.logman import bot
@@ -18,8 +40,8 @@
1840
from singularity.reproduce import (
1941
get_image_hash,
2042
get_image_hashes,
21-
get_memory_tar
22-
43+
get_memory_tar,
44+
extract_content
2345
)
2446
import tempfile
2547
import tarfile
@@ -146,22 +168,20 @@ def package(image_path,spec_path=None,output_folder=None,runscript=True,
146168
to_package = {"files":[image_path]}
147169

148170
# If the specfile is provided, it should also be packaged
149-
if spec_path != None:
171+
if spec_path is not None:
150172
singularity_spec = "".join(read_file(spec_path))
151173
to_package['Singularity'] = singularity_spec
152174

153-
# Package the image with an sha1, replication standard, as VERSION
175+
# Package the image with an sha1, identical standard, as VERSION
154176
hashes = get_image_hashes(image_path)
155177
to_package["VERSION"] = hashes['REPLICATE']
156178
to_package["HASHES"] = hashes
179+
157180
# Look for runscript
158181

159-
if runscript == True:
182+
if runscript is True:
160183
try:
161-
runscript_member = tar.getmember("./singularity")
162-
runscript_file = tar.extractfile("./singularity")
163-
runscript = runscript_file.read()
164-
to_package["runscript"] = runscript
184+
to_package["runscript"] = extract_content(image_path,'./singularity',cli=S)
165185
bot.logger.debug("Found runscript.")
166186
except KeyError:
167187
bot.logger.warning("No runscript found")

singularity/scripts.py

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,37 @@
44
script.py: part of singularity command line tool
55
Runtime executable, "shub"
66
7+
The MIT License (MIT)
8+
9+
Copyright (c) 2016-2017 Vanessa Sochat
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy
12+
of this software and associated documentation files (the "Software"), to deal
13+
in the Software without restriction, including without limitation the rights
14+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the Software is
16+
furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included in all
19+
copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
SOFTWARE.
28+
729
'''
830

931
from glob import glob
32+
import singularity
1033
import argparse
1134
import sys
1235
import os
1336

37+
1438
def get_parser():
1539
parser = argparse.ArgumentParser(
1640
description="Singularity Hub command line tool")
@@ -20,6 +44,10 @@ def get_parser():
2044
help="full path to singularity image (for use with --package and --tree)",
2145
type=str, default=None)
2246

47+
parser.add_argument("--version", dest='version',
48+
help="show software version",
49+
default=False, action='store_true')
50+
2351
# Two images, for similarity function
2452
parser.add_argument("--images", dest='images',
2553
help="images, separated by commas (for use with --simtree and --subtract",
@@ -106,66 +134,70 @@ def main():
106134
os.environ['SINGULARITY_HUB'] = "False"
107135

108136
# if environment logging variable not set, make silent
109-
if args.debug == False:
137+
if args.debug is False:
110138
os.environ['MESSAGELEVEL'] = "CRITICAL"
111139

140+
if args.version is True:
141+
print(singularity.__version__)
142+
sys.exit(0)
143+
112144
# Initialize the message bot, with level above
113145
from singularity.logman import bot
114146
from singularity.utils import check_install
115147
from singularity.cli import get_image
116148

117149
# Output folder will be pwd if not specified
118-
if args.outfolder == None:
150+
if args.outfolder is None:
119151
output_folder = os.getcwd()
120152
else:
121153
output_folder = args.outfolder
122154

123155
# We can only continue if singularity is installed
124-
if check_install() == True:
156+
if check_install() is True:
125157

126158
# If we are given an image, ensure full path
127-
if args.image != None:
159+
if args.image is not None:
128160

129161
image,existed = get_image(args.image,
130162
return_existed=True,
131163
size=args.size)
132164

133-
if image == None:
165+
if image is None:
134166
bot.logger.error("Cannot find image. Exiting.")
135167
sys.exit(1)
136168

137169
# the user wants to make a tree
138-
if args.tree == True:
170+
if args.tree is True:
139171
from singularity.app import make_tree
140172
make_tree(image)
141173
clean_up(image,existed)
142174

143175
# The user wants to estimate the os
144-
elif args.os == True:
176+
elif args.os is True:
145177
from singularity.analysis.classify import estimate_os
146178
estimated_os = estimate_os(container=image)
147179
print(estimated_os)
148180

149181
# The user wants to get a list of all os
150-
elif args.oscalc == True:
182+
elif args.oscalc is True:
151183
from singularity.analysis.classify import estimate_os
152184
estimated_os = estimate_os(container=image,return_top=False)
153185
print(estimated_os["SCORE"].to_dict())
154186

155187
# The user wants to get a list of tags
156-
elif args.tags == True:
188+
elif args.tags is True:
157189
from singularity.analysis.classify import get_tags
158190
tags = get_tags(container=image)
159191
print(tags)
160192

161193
# The user wants to plot image vs. the docker os
162-
elif args.osplot == True:
194+
elif args.osplot is True:
163195
from singularity.app import plot_os_sims
164196
plot_os_sims(image)
165197
clean_up(image,existed)
166198

167199
# The user wants to package the image
168-
elif args.package == True:
200+
elif args.package is True:
169201
from singularity.package import package
170202
remove_image = not args.include_image
171203
package(image_path=image,
@@ -178,7 +210,7 @@ def main():
178210
parser.print_help()
179211

180212
# If we are given two image, we probably want a similar tree
181-
elif args.images != None:
213+
elif args.images is not None:
182214

183215
image1,image2 = args.images.split(',')
184216
bot.logger.debug("Image1: %s",image1)
@@ -190,22 +222,21 @@ def main():
190222
return_existed=True,
191223
size=args.size)
192224

193-
if image1 == None or image2 == None:
225+
if image1 is None or image2 is None:
194226
bot.logger.error("Cannot find image. Exiting.")
195227
sys.exit(1)
196228

197229
# the user wants to make a similarity tree
198-
if args.simtree == True:
230+
if args.simtree is True:
199231
from singularity.app import make_sim_tree
200232
make_sim_tree(image1,image2)
201233

202234
# the user wants to make a difference tree
203-
if args.subtract == True:
235+
if args.subtract is True:
204236
from singularity.app import make_diff_tree
205237
make_diff_tree(image1,image2)
206238

207-
208-
if args.simcalc == True:
239+
if args.simcalc is True:
209240
from singularity.analysis.compare import calculate_similarity
210241
score = calculate_similarity(image1,image2,by="files.txt")
211242
print(score["files.txt"])

0 commit comments

Comments
 (0)