Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # The default PyroScope configuration script
  2. #
  3. # For details, see https://pyrocore.readthedocs.io/en/latest/setup.html
  4. # and https://pyrocore.readthedocs.io/en/latest/custom.html#defining-custom-fields
  5. #
  6.  
  7. def _custom_fields():
  8. """ Yield custom field definitions.
  9. """
  10. # Import some commonly needed modules
  11. import os
  12. from pyrocore.torrent import engine, matching
  13. from pyrocore.util import fmt
  14.  
  15. # PUT CUSTOM FIELD CODE HERE
  16.  
  17. # Disk space check (as an example)
  18. # see https://pyrocore.readthedocs.io/en/latest/custom.html#has-room
  19. def has_room(obj):
  20. "Check disk space."
  21. pathname = obj.path
  22. if pathname and not os.path.exists(pathname):
  23. pathname = os.path.dirname(pathname)
  24. if pathname and os.path.exists(pathname):
  25. stats = os.statvfs(pathname)
  26. return (stats.f_bavail * stats.f_frsize - int(diskspace_threshold_mb) * 1024**2
  27. > obj.size * (1.0 - obj.done / 100.0))
  28. else:
  29. return None
  30.  
  31. yield engine.DynamicField(engine.untyped, "has_room",
  32. "check whether the download will fit on its target device",
  33. matcher=matching.BoolFilter, accessor=has_room,
  34. formatter=lambda val: "OK" if val else "??" if val is None else "NO")
  35. globals().setdefault("diskspace_threshold_mb", "500")
  36.  
  37.  
  38. # Register our factory with the system
  39. custom_field_factories.append(_custom_fields)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement