Skip to content

Instantly share code, notes, and snippets.

@shreeshga
Created August 8, 2012 18:02
Show Gist options
  • Save shreeshga/3297111 to your computer and use it in GitHub Desktop.
Save shreeshga/3297111 to your computer and use it in GitHub Desktop.
Pretty printing ANT build
from clint.textui import puts, colored, indent, progress
from progressbar import ProgressBar,Percentage,Bar
import pbs
import time
from string import lower
import sys
import argparse
def isError(line):
if 'error:' in line: # script errors
print_error(line)
return -1
elif 'Failure' in line: # script errors
print_warning(line)
return -1
elif 'location:' in line: # print compilation errors
print_error(line)
return -2
return 1
def print_info(line):
print_indent(line,color = 'green',start='',end='')
def print_warning(line):
print_indent(line,color = 'yellow',start='',end='')
def print_error(line):
print_indent(line,color = 'red',start='',end='')
def print_indent(line,tab=4,color='blue',start='[',end =']'):
line = line.strip()
with indent(tab,quote=colored.blue('#')):
if(color == "blue"):
puts(colored.blue(start+ line +end))
elif(color == "red"):
puts(colored.red(start+ line +end))
elif(color == "green"):
puts(colored.green(start+ line +end))
class AntBuilder:
def __init__(self):
self.i = 0
self.pbar = None
self.verbose=False
self.buildfile = None
self.target = ""
def parse_args(self):
parser = argparse.ArgumentParser(description='')
parser.add_argument('buildfile',action="store",default="build.xml",help="name of the ant build file")
parser.add_argument('clean',action="store",default=True,help="True: clean build, False: No clean build")
parser.add_argument('target',action="store",default="checkfelix_google",help="checkfelix_google,swoodoo_google,google or amazon")
results = parser.parse_args()
self.buildfile = results.buildfile
self.target = results.target
self.clean = results.clean
def process_out(self,line,stdin,process):
self.i = self.i+1
self.pbar.update(self.i+1)
if isError(line)< 0:
self.verbose = True
return False # print all errors
elif(self.verbose == True):
print_error(line)
def build(self,target):
self.pbar = ProgressBar(widgets=[Percentage(), Bar()], maxval=10000).start()
print_indent("Starting build "+target)
p = None
try:
p = pbs.ant(target,f=self.buildfile,_out=self.process_out);
except Exception as e:
pass
p.wait()
self.pbar.finish()
def deploy(self,binary="./bin/-release.apk"):
self.remove_app()
print_indent("Installing the Application")
pbs.adb('install',binary,_err=sys.stdout)
print_indent("Launching App")
pbs.adb('shell','am start -n com.kayak.android/.Splash',_err=sys.stdout)
print_indent("Done")
def remove_app(self):
print_indent("Removing Application")
pbs.adb('uninstall','com.kayak.android',_err=sys.stdout)
print_indent("App removed from Device")
def main(self):
self.parse_args()
if(self.clean):
self.build('clean')
self.build(self.target)
self.deploy(binary = './selective/bin/-release.apk')
if __name__ == "__main__":
builder = AntBuilder()
builder.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment