patch.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. #
  4. # patchtestpatch: PatchTestPatch class which abstracts a patch file
  5. #
  6. # Copyright (C) 2016 Intel Corporation
  7. #
  8. # SPDX-License-Identifier: GPL-2.0-only
  9. #
  10. import logging
  11. import utils
  12. logger = logging.getLogger('patchtest')
  13. class PatchTestPatch(object):
  14. MERGE_STATUS_INVALID = 'INVALID'
  15. MERGE_STATUS_NOT_MERGED = 'NOTMERGED'
  16. MERGE_STATUS_MERGED_SUCCESSFULL = 'PASS'
  17. MERGE_STATUS_MERGED_FAIL = 'FAIL'
  18. MERGE_STATUS = (MERGE_STATUS_INVALID,
  19. MERGE_STATUS_NOT_MERGED,
  20. MERGE_STATUS_MERGED_SUCCESSFULL,
  21. MERGE_STATUS_MERGED_FAIL)
  22. def __init__(self, path, forcereload=False):
  23. self._path = path
  24. self._forcereload = forcereload
  25. self._contents = None
  26. self._branch = None
  27. self._merge_status = PatchTestPatch.MERGE_STATUS_NOT_MERGED
  28. @property
  29. def contents(self):
  30. if self._forcereload or (not self._contents):
  31. logger.debug('Reading %s contents' % self._path)
  32. try:
  33. with open(self._path, newline='') as _f:
  34. self._contents = _f.read()
  35. except IOError:
  36. logger.warn("Reading the mbox %s failed" % self.resource)
  37. return self._contents
  38. @property
  39. def path(self):
  40. return self._path
  41. @property
  42. def branch(self):
  43. if not self._branch:
  44. self._branch = utils.get_branch(self._path)
  45. return self._branch
  46. def setmergestatus(self, status):
  47. self._merge_status = status
  48. def getmergestatus(self):
  49. return self._merge_status
  50. merge_status = property(getmergestatus, setmergestatus)