policy.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # vim: set fileencoding=utf-8 :
  2. #
  3. # (C) 2012 Intel Corporation <markus.lehtonen@linux.intel.com>
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, please see
  16. # <http://www.gnu.org/licenses/>
  17. """Default packaging policy for RPM"""
  18. import re
  19. from gbp.pkg import PkgPolicy, parse_archive_filename
  20. class RpmPkgPolicy(PkgPolicy):
  21. """Packaging policy for RPM"""
  22. # Special rpmlib python module for GBP (only)
  23. python_rpmlib_module_name = "rpm"
  24. alnum = 'a-zA-Z0-9'
  25. # Valid characters for RPM pkg name
  26. name_whitelist_chars = '._+%{}\-'
  27. # Valid characters for RPM pkg version
  28. version_whitelist_chars = '._+%{}~'
  29. # Regexp for checking the validity of package name
  30. packagename_re = re.compile("^[%s][%s%s]+$" %
  31. (alnum, alnum, name_whitelist_chars))
  32. packagename_msg = ("Package names must be at least two characters long, "
  33. "start with an alphanumeric and can only contain "
  34. "alphanumerics or characters in %s" %
  35. list(name_whitelist_chars))
  36. # Regexp for checking the validity of package (upstream) version
  37. upstreamversion_re = re.compile("^[0-9][%s%s]*$" %
  38. (alnum, version_whitelist_chars))
  39. upstreamversion_msg = ("Upstream version numbers must start with a digit "
  40. "and can only containg alphanumerics or characters "
  41. "in %s" % list(version_whitelist_chars))
  42. @classmethod
  43. def is_valid_orig_archive(cls, filename):
  44. """
  45. Is this a valid orig source archive
  46. @param filename: upstream source archive filename
  47. @type filename: C{str}
  48. @return: true if valid upstream source archive filename
  49. @rtype: C{bool}
  50. >>> RpmPkgPolicy.is_valid_orig_archive("foo/bar_baz.tar.gz")
  51. True
  52. >>> RpmPkgPolicy.is_valid_orig_archive("foo.bar.tar")
  53. True
  54. >>> RpmPkgPolicy.is_valid_orig_archive("foo.bar")
  55. False
  56. >>> RpmPkgPolicy.is_valid_orig_archive("foo.gz")
  57. False
  58. """
  59. _base, arch_fmt, _compression = parse_archive_filename(filename)
  60. if arch_fmt:
  61. return True
  62. return False