summaryrefslogtreecommitdiff
path: root/buildscripts/utils.py
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2010-08-11 12:38:57 +0200
committerAntonin Kral <a.kral@bobek.cz>2010-08-11 12:38:57 +0200
commit7645618fd3914cb8a20561625913c20d49504a49 (patch)
tree8370f846f58f6d71165b7a0e2eda04648584ec76 /buildscripts/utils.py
parent68c73c3c7608b4c87f07440dc3232801720b1168 (diff)
downloadmongodb-7645618fd3914cb8a20561625913c20d49504a49.tar.gz
Imported Upstream version 1.6.0
Diffstat (limited to 'buildscripts/utils.py')
-rw-r--r--buildscripts/utils.py80
1 files changed, 77 insertions, 3 deletions
diff --git a/buildscripts/utils.py b/buildscripts/utils.py
index 41d6767..1ca2fdd 100644
--- a/buildscripts/utils.py
+++ b/buildscripts/utils.py
@@ -2,9 +2,50 @@
import re
import socket
import time
-
+import os
# various utilities that are handy
+def getGitBranch():
+ if not os.path.exists( ".git" ):
+ return None
+
+ version = open( ".git/HEAD" ,'r' ).read().strip()
+ if not version.startswith( "ref: " ):
+ return version
+ version = version.split( "/" )
+ version = version[len(version)-1]
+ return version
+
+def getGitBranchString( prefix="" , postfix="" ):
+ t = re.compile( '[/\\\]' ).split( os.getcwd() )
+ if len(t) > 2 and t[len(t)-1] == "mongo":
+ par = t[len(t)-2]
+ m = re.compile( ".*_([vV]\d+\.\d+)$" ).match( par )
+ if m is not None:
+ return prefix + m.group(1).lower() + postfix
+ if par.find("Nightly") > 0:
+ return ""
+
+
+ b = getGitBranch()
+ if b == None or b == "master":
+ return ""
+ return prefix + b + postfix
+
+def getGitVersion():
+ if not os.path.exists( ".git" ):
+ return "nogitversion"
+
+ version = open( ".git/HEAD" ,'r' ).read().strip()
+ if not version.startswith( "ref: " ):
+ return version
+ version = version[5:]
+ f = ".git/" + version
+ if not os.path.exists( f ):
+ return version
+ return open( f , 'r' ).read().strip()
+
+
def execsys( args ):
import subprocess
if isinstance( args , str ):
@@ -24,6 +65,40 @@ def getprocesslist():
r = re.compile( "[\r\n]+" )
return r.split( raw )
+
+def removeIfInList( lst , thing ):
+ if thing in lst:
+ lst.remove( thing )
+
+def findVersion( root , choices ):
+ for c in choices:
+ if ( os.path.exists( root + c ) ):
+ return root + c
+ raise "can't find a version of [" + root + "] choices: " + choices
+
+def choosePathExist( choices , default=None):
+ for c in choices:
+ if c != None and os.path.exists( c ):
+ return c
+ return default
+
+def filterExists(paths):
+ return filter(os.path.exists, paths)
+
+def ensureDir( name ):
+ d = os.path.dirname( name )
+ if not os.path.exists( d ):
+ print( "Creating dir: " + name );
+ os.makedirs( d )
+ if not os.path.exists( d ):
+ raise "Failed to create dir: " + name
+
+
+def distinctAsString( arr ):
+ s = set()
+ for x in arr:
+ s.add( str(x) )
+ return list(s)
def checkMongoPort( port=27017 ):
sock = socket.socket()
@@ -32,6 +107,7 @@ def checkMongoPort( port=27017 ):
sock.connect(("localhost", port))
sock.close()
+
def didMongodStart( port=27017 , timeout=20 ):
while timeout > 0:
time.sleep( 1 )
@@ -41,7 +117,5 @@ def didMongodStart( port=27017 , timeout=20 ):
except Exception,e:
print( e )
timeout = timeout - 1
-
return False
-