]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/util.py
Refactor calculate_repository() and calculate_tag() to deploy.
[wizard.git] / wizard / util.py
index dddbb3451b76fbd10141205d44a429e5d679d72f..fefc4fcfe9b74d77c9ec76d4345b0abc08bb196e 100644 (file)
@@ -1,5 +1,6 @@
 import os.path
-import ldap
+import os
+import subprocess
 
 def get_exception_name(output):
     """Reads the stderr output of another Python command and grabs the
@@ -13,22 +14,12 @@ def get_exception_name(output):
         else:
             return line
 
-def get_dir_user(dir):
-    """Finds the username of the person who owns this directory, via LDAP.
-    Only works for directories under web_scripts"""
-    dir = os.path.realpath(dir)
-    homedir, _, _ = dir.partition("/web_scripts")
-    if homedir == dir: return None
-    con = ldap.initialize('ldap://scripts.mit.edu')
-    return con.search_s(
-            "ou=People,dc=scripts,dc=mit,dc=edu", # base
-            ldap.SCOPE_SUBTREE, # default
-            "homeDirectory=" + homedir, # search
-            ['uid'] # attr
-        )[0][1]["uid"][0]  # unwrap the result
+def get_dir_uid(dir):
+    """Finds the uid of the person who owns this directory."""
+    return os.stat(dir).st_uid
 
-def get_dir_url(dir):
-    """Finds the URL a path would correspond to in the filesystem"""
-    _, _, path = dir.partition("/web_scripts")
-    return "http://%s.scripts.mit.edu%s" % (get_dir_user(dir), path)
+def get_version():
+    """Returns the commit ID of the current Wizard install."""
+    wizard_git = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), ".git")
+    return subprocess.Popen(["git", "--git-dir=" + wizard_git, "rev-parse", "HEAD"]).communicate()[0]