Skip to content

Commit 9b87ea9

Browse files
committed
The mfn is part of the upload loop,
... so it makes sense to log it as part of the progress. Previously we'd report 10/10 (or whatever), but still be working on the manifest upload. Also a version bump.
1 parent 1799149 commit 9b87ea9

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

pog/pog.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def save_manifest(self, mfn, filename=None):
247247
full_manifest_bytes = dumps(mfn).encode('utf-8')
248248
self._write(f, _compress(full_manifest_bytes, self.compresslevel))
249249
self.blob_store.save(filename, temp_path)
250+
return filename
250251

251252
def encrypt_single_file(self, filename):
252253
cctx = zstd.ZstdCompressor(level=self.compresslevel)
@@ -267,7 +268,7 @@ def encrypt(self, *inputs):
267268
mfn = dict()
268269
all_inputs = local_file_list(*inputs)
269270
for count, filename in enumerate(all_inputs):
270-
_print_progress(count+1, len(all_inputs), filename)
271+
_print_progress(count+1, len(all_inputs)+1, filename)
271272
outputs = []
272273
for temp_path in self.encrypt_single_file(filename):
273274
blob_name = path.basename(temp_path)
@@ -280,7 +281,8 @@ def encrypt(self, *inputs):
280281
'atime': path.getatime(filename),
281282
'mtime': path.getmtime(filename),
282283
}
283-
self.save_manifest(mfn)
284+
mfn_filename = self.save_manifest(mfn)
285+
_print_progress(len(all_inputs)+1, len(all_inputs)+1, mfn_filename)
284286

285287

286288
class Decryptor():
@@ -378,7 +380,7 @@ def decrypt(self, *inputs):
378380

379381

380382
def main():
381-
args = docopt(__doc__, version='Pog 0.1.2')
383+
args = docopt(__doc__, version='Pog 0.1.3')
382384
chunk_size = parse_size(args.get('--chunk-size', '100MB'))
383385
compresslevel = int(args.get('--compresslevel', '3'))
384386
store_absolute_paths = args.get('--store-absolute-paths')

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
name='pogcli',
1111
license='MIT',
1212
url='https://github.com/sz3/pog',
13-
version='0.1.2',
13+
version='0.1.3',
1414

1515
entry_points={
1616
'console_scripts': [

tests/test_pog.py

+36-22
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ class KeyfileTest(TestDirMixin, TestCase):
5252
def test_round_trip(self):
5353
# encrypt our sample files
5454
enc = self.run_command(self.encryption_flag, self.tiny_sample, self.another_sample)
55+
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
56+
5557
# ordered lexicographically by filename
5658
self.assertEqual(enc, [
57-
f'*** 1/2: {self.another_sample}',
59+
f'*** 1/3: {self.another_sample}',
5860
self.another_sample_blobname,
59-
f'*** 2/2: {self.tiny_sample}',
60-
self.tiny_sample_blobname
61+
f'*** 2/3: {self.tiny_sample}',
62+
self.tiny_sample_blobname,
63+
'*** 3/3: {}'.format(path.basename(manifest_name)),
6164
])
6265
blobs = [l for l in enc if not l.startswith('***')]
6366

6467
# check that the manifest looks good
65-
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
6668
show_mfn = self.run_command(self.decryption_flag, '--dump-manifest', manifest_name)
6769
self.assertEqual(
6870
show_mfn, ['* another_sample.txt:', blobs[0], '* tiny_sample.txt:', blobs[1]]
@@ -167,15 +169,17 @@ def test_absolute_paths(self):
167169
enc = self.run_command(
168170
self.encryption_flag, self.tiny_sample, self.another_sample, '--store-absolute-paths'
169171
)
172+
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
173+
170174
self.assertEqual(enc, [
171-
f'*** 1/2: {self.another_sample}',
175+
f'*** 1/3: {self.another_sample}',
172176
self.another_sample_blobname,
173-
f'*** 2/2: {self.tiny_sample}',
174-
self.tiny_sample_blobname
177+
f'*** 2/3: {self.tiny_sample}',
178+
self.tiny_sample_blobname,
179+
'*** 3/3: {}'.format(path.basename(manifest_name)),
175180
])
176181

177182
# check that the manifest looks good
178-
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
179183
show_mfn = self.run_command(self.decryption_flag, '--dump-manifest', manifest_name)
180184
self.assertEqual(
181185
show_mfn, [
@@ -211,15 +215,17 @@ def test_glob_input_directory(self):
211215
enc = self.run_command(
212216
self.encryption_flag, self.input_dir.name, '--store-absolute-paths'
213217
)
218+
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
219+
214220
self.assertEqual(enc, [
215-
f'*** 1/2: {self.another_sample}',
221+
f'*** 1/3: {self.another_sample}',
216222
self.another_sample_blobname,
217-
f'*** 2/2: {self.tiny_sample}',
218-
self.tiny_sample_blobname
223+
f'*** 2/3: {self.tiny_sample}',
224+
self.tiny_sample_blobname,
225+
'*** 3/3: {}'.format(path.basename(manifest_name)),
219226
])
220227

221228
# check that the manifest looks good
222-
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
223229
show_mfn = self.run_command(self.decryption_flag, '--dump-manifest', manifest_name)
224230
self.assertEqual(
225231
show_mfn, [
@@ -245,16 +251,18 @@ def test_manifest_index_ordering(self):
245251
'''
246252
# encrypt our sample files
247253
enc = self.run_command(self.encryption_flag, self.tiny_sample, self.another_sample)
254+
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
255+
248256
self.assertEqual(enc, [
249-
f'*** 1/2: {self.another_sample}',
257+
f'*** 1/3: {self.another_sample}',
250258
self.another_sample_blobname,
251-
f'*** 2/2: {self.tiny_sample}',
252-
self.tiny_sample_blobname
259+
f'*** 2/3: {self.tiny_sample}',
260+
self.tiny_sample_blobname,
261+
'*** 3/3: {}'.format(path.basename(manifest_name)),
253262
])
254263
blobs = [l for l in enc if not l.startswith('***')]
255264

256265
# check that the manifest index looks good
257-
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
258266
show_mfn = self.run_command(self.decryption_flag, '--dump-manifest-index', manifest_name)
259267
# manifest index sorted by blobname
260268
self.assertEqual(show_mfn, sorted(blobs))
@@ -276,15 +284,17 @@ def tearDownClass(cls):
276284
def test_with_keyfile(self):
277285
# encrypt our sample file
278286
enc = self.run_command(f'--keyfile={POG_ROOT}/tests/samples/only_for_testing.encrypt', BigFileTest.big_sample)
287+
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
288+
279289
self.assertEqual(enc, [
280-
f'*** 1/1: {self.big_sample}',
290+
f'*** 1/2: {self.big_sample}',
281291
'xyQWj-UXXZpwWXPF2c5_MsBm3cTfZFXayUVLLMlkt4Y=',
282292
'HXBJ_N4EM2rywLdOWT02hccp4c_oLk0QyD2lc3vUttw=',
293+
'*** 2/2: {}'.format(path.basename(manifest_name)),
283294
])
284295
blobs = [l for l in enc if not l.startswith('***')]
285296

286297
# check that the manifest looks good
287-
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
288298
show_mfn = self.run_command(f'--keyfile={POG_ROOT}/tests/samples/only_for_testing.encrypt', '--dump-manifest',
289299
manifest_name)
290300
self.assertEqual(show_mfn, ['* big_sample.bin:'] + blobs)
@@ -307,15 +317,17 @@ def test_with_asymmetric(self):
307317
# encrypt our sample file
308318
enc = self.run_command(f'--encryption-keyfile={POG_ROOT}/tests/samples/only_for_testing.encrypt',
309319
BigFileTest.big_sample)
320+
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
321+
310322
self.assertEqual(enc, [
311-
f'*** 1/1: {self.big_sample}',
323+
f'*** 1/2: {self.big_sample}',
312324
'RiOpsEQbQpxrBvXL1s047hq54EhFXxWqwag-vMuiRfc=',
313325
'YdK86P4e2191CxVBhZwvvPtwOLU6Ve1NzMhwLjxVXqg=',
326+
'*** 2/2: {}'.format(path.basename(manifest_name)),
314327
])
315328
blobs = [l for l in enc if not l.startswith('***')]
316329

317330
# check that the manifest looks good
318-
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
319331
show_mfn = self.run_command(f'--decryption-keyfile={POG_ROOT}/tests/samples/only_for_testing.decrypt',
320332
'--dump-manifest', manifest_name)
321333
self.assertEqual(show_mfn, ['* big_sample.bin:'] + blobs)
@@ -345,16 +357,18 @@ def test_smaller_chunk_size(self):
345357
f'--encryption-keyfile={POG_ROOT}/tests/samples/only_for_testing.encrypt', BigFileTest.big_sample,
346358
'--chunk-size=50MB'
347359
)
360+
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
361+
348362
self.assertEqual(enc, [
349-
f'*** 1/1: {self.big_sample}',
363+
f'*** 1/2: {self.big_sample}',
350364
'PURfe1ei1aqpPRarpAfKkcKPRSHdo5hPH-bvfYND2KM=',
351365
'nnL4ta-BChpb36CIFeZUG4lJLiz8l0YVv94IaABcgyU=',
352366
'YdK86P4e2191CxVBhZwvvPtwOLU6Ve1NzMhwLjxVXqg=',
367+
'*** 2/2: {}'.format(path.basename(manifest_name)),
353368
])
354369
blobs = [l for l in enc if not l.startswith('***')]
355370

356371
# check that the manifest looks good
357-
manifest_name = glob(path.join(self.working_dir.name, '*.mfn'))[0]
358372
show_mfn = self.run_command(f'--decryption-keyfile={POG_ROOT}/tests/samples/only_for_testing.decrypt',
359373
'--dump-manifest', manifest_name)
360374
self.assertEqual(show_mfn, ['* big_sample.bin:'] + blobs)

0 commit comments

Comments
 (0)