Skip to content

Commit 4820e3d

Browse files
committed
modified: analysis/reproduce/utils.py
modified: package/utils.py modified: tests/test_client.py
1 parent 8a142e1 commit 4820e3d

3 files changed

Lines changed: 30 additions & 28 deletions

File tree

singularity/analysis/reproduce/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
'''
2828

2929
from singularity.cli import Singularity
30-
from .criteria import assess_content, include_file
30+
from .criteria import (
31+
assess_content,
32+
include_file,
33+
is_root_owned
34+
)
3135
from singularity.logger import bot
3236
import hashlib
3337
import tarfile

singularity/package/utils.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,31 @@ def zip_up(file_list,zip_name,output_folder=None):
7575
content = [content]
7676
for copyfile in content:
7777
zf.write(copyfile,os.path.basename(copyfile))
78+
os.remove(copyfile)
7879

79-
# If it's a list, write to new file, and save
80-
elif isinstance(content,list):
81-
filey = write_file("%s/%s" %(tmpdir,filename),"\n".join(content))
82-
zf.write(filey,filename)
83-
os.remove(filey)
84-
85-
# If it's a dict, save to json
86-
elif isinstance(content,dict):
87-
filey = write_json(content,"%s/%s" %(tmpdir,filename))
88-
zf.write(filey,filename)
89-
os.remove(filey)
90-
91-
# If it's a string, do the same
92-
elif isinstance(content,str) or filename.endswith('json'):
93-
filey = write_file("%s/%s" %(tmpdir,filename),content)
94-
zf.write(filey,filename)
95-
os.remove(filey)
96-
97-
# Otherwise, just write the content into a new archive
98-
elif isinstance(content,bytes):
99-
filey = write_file("%s/%s" %(tmpdir,filename),content.decode('utf-8'))
100-
zf.write(filey,filename)
101-
os.remove(filey)
102-
103-
else:
104-
zf.write(content,filename)
80+
else:
81+
82+
output_file = "%s/%s" %(tmpdir, filename)
83+
84+
# If it's a list, write to new file, and save
85+
if isinstance(content,list):
86+
write_file(output_file,"\n".join(content))
87+
88+
# If it's a dict, save to json
89+
elif isinstance(content,dict):
90+
write_json(content,output_file)
91+
92+
# If bytes, need to decode
93+
elif isinstance(content,bytes):
94+
write_file(output_file,content.decode('utf-8'))
95+
96+
# String or other
97+
else:
98+
output_file = write_file(output_file,content)
99+
100+
if os.path.exists(output_file):
101+
zf.write(output_file,filename)
102+
os.remove(output_file)
105103

106104
# Close the zip file
107105
zf.close()

singularity/tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_commands(self):
6060
container = "%s/container.img" %(self.tmpdir)
6161
created_container = self.cli.create(container)
6262
self.assertEqual(created_container,container)
63-
self.assertTrue(os.path.exists(container))
63+
self.assertTrue(os.path.exists(created_container))
6464
os.remove(container)
6565

6666
print("Testing client.pull command")

0 commit comments

Comments
 (0)