PageRenderTime 531ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/_unsorted/core/lib/disting.py

https://bitbucket.org/ericsnowcurrently/commonlib
Python | 147 lines | 94 code | 35 blank | 18 comment | 28 complexity | 3bba205b439384db6f4c274cc6765c28 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. """project module
  2. Classes for project distribution activities.
  3. """
  4. # XXX distutils
  5. from collections import OrderedDict as ODict, namedtuple
  6. try:
  7. from core.util.version import Version
  8. except ImportError:
  9. class Version(namedtuple("V", "major minor micro release serial")):
  10. def __str__(self):
  11. outstr = self.major
  12. if self.minor is None:
  13. return outstr
  14. outstr += ".%s" % self.minor
  15. if self.micro is None:
  16. return outstr
  17. outstr += ".%s" % self.micro
  18. if self.release is None:
  19. return outstr
  20. outstr += " %s" % self.release
  21. if self.serial is None:
  22. return outstr
  23. outstr += " %s" % self.serial
  24. return oustr
  25. #################################################
  26. # project sites
  27. class ProjectSite(object):
  28. # XXX pull and push
  29. HOME = None
  30. REPO = None
  31. SOURCE = None
  32. WIKI = None
  33. DOCS = None
  34. TRACKER = None
  35. DOWNLOADS = None
  36. def __init__(self, project, name=None):
  37. self.project = project
  38. self.name = name or project.name
  39. kwargs = vars(self)
  40. self.home = self.HOME % kwargs if self.HOME else None
  41. self.repo = self.REPO % kwargs if self.REPO else None
  42. self.wiki = self.WIKI % kwargs if self.WIKI else None
  43. self.docs = self.DOCS % kwargs if self.DOCS else None
  44. self.tracker = self.TRACKER % kwargs if self.TRACKER else None
  45. self.downloads = self.DOWNLOADS % kwargs if self.DOWNLOADS else None
  46. class BitbucketSite(ProjectSite):
  47. BASE = "https://bitbucket.org/%(account)s/%(name)s"
  48. HOME = BASE
  49. REPO = "hg clone %s" % BASE
  50. SOURCE = "%s/src" % BASE
  51. WIKI = "%s/wiki" % BASE
  52. DOCS = None
  53. TRACKER = "%s/issues" % BASE
  54. DOWNLOADS = "%s/downloads" % BASE
  55. def __init__(self, project, account):
  56. self.account = account
  57. super(type(self), self).__init__(project)
  58. #################################################
  59. # packages indexes
  60. #class PackageIndex(PackageIndex):
  61. class PackageIndex(object):
  62. # XXX pull and push
  63. HOME = None
  64. def __init__(self, project, name=None):
  65. self.project = project
  66. self.name = name or project.name
  67. kwargs = vars(self)
  68. self.home = self.HOME % kwargs if self.HOME else None
  69. class PyPI(PackageIndex):
  70. BASE = "http://pypi.python.org/"
  71. HOME = BASE + "?%%3Aaction=display&name=%s"
  72. DOCS = "http://packages.python.org/%(name)s/"
  73. #################################################
  74. # docs
  75. class Docs(object):
  76. # XXX pull and push
  77. def __init__(self, project, summary, description=None, README=None):
  78. self.project = project
  79. self.summary = summary
  80. self.description = description
  81. self.README = README
  82. class DirDocs(Docs):
  83. def __init__(self, project, summary=None):
  84. super(type(self), self).__init__(project, summary)
  85. self.description = self.pull_description()
  86. def pull_desciption(self):
  87. ...
  88. def pull_README(self):
  89. ...
  90. #################################################
  91. # projects
  92. class Project(object):
  93. def __init__(self, name, version, modname=None, pypi=True):
  94. self.name = name
  95. self.version = version
  96. self.modname = modname if modname is not None else name
  97. self.license = "New BSD License"
  98. self.namespace = None
  99. self.subpackages = ()
  100. self.repo_contents = ODict()
  101. self.contents = ODict()
  102. self.site = None
  103. self.dist = PyPI(self) if pypi else None
  104. self.docs = "%s package" % name
  105. @property
  106. def qname(self):
  107. if self.namespace:
  108. return "%s.%s" % (self.namespace.qname, self.modname)
  109. else:
  110. return self.modname