upload.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. from threading import Lock
  4. import logging
  5. class Handle:
  6. def __init__(self):
  7. self.lock = Lock()
  8. self.Q = []
  9. self.max_item_length = 1000
  10. def add_task(self, content):
  11. if not isinstance(content, dict):
  12. logging.warning('[HANDLE] add task content: %s but type is not dict', content)
  13. return
  14. self.lock.acquire()
  15. content = self.content_format(content)
  16. self.Q.append(content)
  17. self.lock.release()
  18. @staticmethod
  19. def content_format(content):
  20. if not content.__contains__('dev_ip'):
  21. content['dev_ip'] = ''
  22. if not content.__contains__('expr'):
  23. content['expr'] = 1
  24. if not content.__contains__('dev_id'):
  25. content['dev_id'] = ''
  26. if not content.__contains__('port'):
  27. content['port'] = ''
  28. if not content.__contains__('type'):
  29. content['type'] = ''
  30. if not content.__contains__('schema'):
  31. content['schema'] = ''
  32. if not content.__contains__('login_name'):
  33. content['login_name'] = ''
  34. if not content.__contains__('pwd'):
  35. content['pwd'] = ''
  36. if not content.__contains__('kpi'):
  37. content['kpi'] = {}
  38. return content
  39. def to_file(self):
  40. pass
  41. def to_temp_file(self):
  42. pass
  43. def ftp_upload(self):
  44. pass