44script.py: part of singularity command line tool
55Runtime 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
931from glob import glob
32+ import singularity
1033import argparse
1134import sys
1235import os
1336
37+
1438def 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