import os
import Utils
import samba_utils
-import sys
-
-def bzr_version_summary(path):
- try:
- import bzrlib
- except ImportError:
- return ("BZR-UNKNOWN", {})
-
- import bzrlib.ui
- bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
- sys.stdin, sys.stdout, sys.stderr)
- from bzrlib import branch, osutils, workingtree
- from bzrlib.plugin import load_plugins
- load_plugins()
-
- b = branch.Branch.open(path)
- (revno, revid) = b.last_revision_info()
- rev = b.repository.get_revision(revid)
-
- fields = {
- "BZR_REVISION_ID": revid,
- "BZR_REVNO": revno,
- "COMMIT_DATE": osutils.format_date_with_offset_in_original_timezone(rev.timestamp,
- rev.timezone or 0),
- "COMMIT_TIME": int(rev.timestamp),
- "BZR_BRANCH": rev.properties.get("branch-nick", ""),
- }
-
- # If possible, retrieve the git sha
- try:
- from bzrlib.plugins.git.object_store import get_object_store
- except ImportError:
- # No git plugin
- ret = "BZR-%d" % revno
- else:
- store = get_object_store(b.repository)
- store.lock_read()
- try:
- full_rev = store._lookup_revision_sha1(revid)
- finally:
- store.unlock()
- fields["GIT_COMMIT_ABBREV"] = full_rev[:7]
- fields["GIT_COMMIT_FULLREV"] = full_rev
- ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
-
- if workingtree.WorkingTree.open(path).has_changes():
- fields["COMMIT_IS_CLEAN"] = 0
- ret += "+"
- else:
- fields["COMMIT_IS_CLEAN"] = 1
- return (ret, fields)
-
+from samba_git import find_git
def git_version_summary(path, env=None):
- # Get version from GIT
- if not 'GIT' in env and os.path.exists("/usr/bin/git"):
- # this is useful when doing make dist without configuring
- env.GIT = "/usr/bin/git"
+ git = find_git(env)
- if not 'GIT' in env:
+ if git is None:
return ("GIT-UNKNOWN", {})
+ env.GIT = git
+
environ = dict(os.environ)
environ["GIT_DIR"] = '%s/.git' % path
environ["GIT_WORK_TREE"] = path
return (ret, fields)
+def distversion_version_summary(path):
+ #get version from .distversion file
+ suffix = None
+ fields = {}
+
+ for line in Utils.readf(path + '/.distversion').splitlines():
+ if line == '':
+ continue
+ if line.startswith("#"):
+ continue
+ try:
+ split_line = line.split("=")
+ if split_line[1] != "":
+ key = split_line[0]
+ value = split_line[1]
+ if key == "SUFFIX":
+ suffix = value
+ continue
+ fields[key] = value
+ except:
+ print("Failed to parse line %s from .distversion file." % (line))
+ raise
+
+ if "COMMIT_TIME" in fields:
+ fields["COMMIT_TIME"] = int(fields["COMMIT_TIME"])
+
+ if suffix is None:
+ return ("UNKNOWN", fields)
+
+ return (suffix, fields)
+
+
class SambaVersion(object):
def __init__(self, version_dict, path, env=None, is_install=True):
'''Determine the version number of samba
-See VERSION for the format. Entries on that file are
+See VERSION for the format. Entries on that file are
also accepted as dictionary entries here
'''
self.VENDOR_SUFFIX=None
self.VENDOR_PATCH=None
- for a, b in version_dict.iteritems():
+ for a, b in version_dict.items():
if a.startswith("SAMBA_VERSION_"):
setattr(self, a[14:], b)
else:
self.vcs_fields = {}
elif os.path.exists(os.path.join(path, ".git")):
suffix, self.vcs_fields = git_version_summary(path, env=env)
- elif os.path.exists(os.path.join(path, ".bzr")):
- suffix, self.vcs_fields = bzr_version_summary(path)
+ elif os.path.exists(os.path.join(path, ".distversion")):
+ suffix, self.vcs_fields = distversion_version_summary(path)
else:
suffix = "UNKNOWN"
self.vcs_fields = {}
+ self.vcs_fields["SUFFIX"] = suffix
SAMBA_VERSION_STRING += "-" + suffix
else:
self.vcs_fields = {}