Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 7a5afe067f
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (46 sloc) 1.322 kB
# Misc Functions for doing stuff
import re
import subprocess
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''
def shellquote(s):
return "'" + s.replace("'", "'\\''") + "'"
# This function takes Bash commands and returns them
def run_bash(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out = p.stdout.read().strip()
return out
def report(output,cmdtype="UNIX COMMAND:"):
if VERBOSE:
print("%s: %s" % (cmdtype, output))
else:
print(output)
def sort_nicely(l):
""" Sort the given list in the way that humans expect.
"""
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
l.sort( key=alphanum_key )
return l
def list_count(str, l):
""" Counts the occurrances of str in list l.
"""
counter = 0
strLen = len(str)
for x in l:
if x[0:strLen] == str:
counter += 1
return counter
Jump to Line
Something went wrong with that request. Please try again.