fake_converter.py 699 B

123456789101112131415161718192021222324252627282930313233
  1. import time
  2. import sys
  3. import os
  4. import json
  5. filename, output = sys.argv[1:3]
  6. if 'error' in filename:
  7. print(json.dumps({'finished': True, 'error': 'test error'}))
  8. sys.exit(1)
  9. if os.path.exists(output):
  10. print(json.dumps({
  11. 'finished': True,
  12. 'error': '%r existed when we started' % (output,)}))
  13. sys.exit(1)
  14. time.sleep(0.5)
  15. RANGE = 5
  16. for i in range(RANGE):
  17. print(json.dumps({
  18. 'filename': filename,
  19. 'output': output,
  20. 'duration': RANGE,
  21. 'progress': i,
  22. 'eta': RANGE - i
  23. }))
  24. time.sleep(0.1)
  25. file = open(output, 'w')
  26. with file as f:
  27. f.write('blank')
  28. print(json.dumps({'finished': True}))