show_all_jobs.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Dump lots of info about BITS jobs.
  2. from win32com.bits import bits
  3. import pythoncom
  4. states = dict([(val, (name[13:]))
  5. for name, val in vars(bits).iteritems()
  6. if name.startswith('BG_JOB_STATE_')])
  7. job_types = dict([(val, (name[12:]))
  8. for name, val in vars(bits).iteritems()
  9. if name.startswith('BG_JOB_TYPE_')])
  10. bcm = pythoncom.CoCreateInstance(bits.CLSID_BackgroundCopyManager,
  11. None,
  12. pythoncom.CLSCTX_LOCAL_SERVER,
  13. bits.IID_IBackgroundCopyManager)
  14. try:
  15. enum = bcm.EnumJobs(bits.BG_JOB_ENUM_ALL_USERS)
  16. except pythoncom.error:
  17. print "Failed to get jobs for all users - trying for current user"
  18. enum = bcm.EnumJobs(0)
  19. for job in enum:
  20. print "Job:", job.GetDisplayName()
  21. print "Description:", job.GetDescription()
  22. print "Id:", job.GetId()
  23. print "State:", states.get(job.GetState())
  24. print "Type:", job_types.get(job.GetType())
  25. print "Owner:", job.GetOwner()
  26. print "Errors:", job.GetErrorCount()
  27. print "Created/Modified/Finished times:", [str(t) for t in job.GetTimes()]
  28. bytes_tot, bytes_xf, files_tot, files_xf = job.GetProgress()
  29. print "Bytes: %d complete of %d total" % (bytes_xf, bytes_tot)
  30. print "Files: %d complete of %d total" % (files_xf, files_tot)
  31. for f in job.EnumFiles():
  32. bytes, total, done = f.GetProgress()
  33. print " Remote:", f.GetRemoteName()
  34. print " Local:", f.GetLocalName()
  35. print " Progress: %d of %d bytes - completed=%s)" % (bytes, total, done)
  36. print
  37. print