deploy_tsviz.py
def main():
    '''
    Workhorse method to execute all the of the steps described in the file header.
    '''
    
    src_dir = "./"
    dist_dir = "../bestchai.bitbucket.org/tsviz/"

    print "Deploying to: " + dist_dir
    print "from: " + src_dir

    # Confirmation message.

    if( confirm("Is it okay to remove the previous deployed version?", False) ):
        # Remove previously deployed version of tsviz.
        if (os.path.exists(dist_dir)):
            runcmd("rm -rf " + dist_dir + "*")
        else:
            print "Error: deployment dir is not where it is expected."
            sys.exit(-1)
    else:
        print "Deployment failed."
        sys.exit(-1)

    

    # Copy over the source.
    if (os.path.exists(src_dir)):
        runcmd("cp -R " + src_dir + "* " + dist_dir)
        # Remove js source code since we will be using a minified version (see below).
        runcmd("rm -rf " + dist_dir + "/js/*")
    else:
        print "Error: source dir is not where it is expected."
        sys.exit(-1)

    # Compile docs
    # if (runcmd("perl docgen.pl " + dist_dir) != 0):
    #     sys.exit(-1)

    # Find out the current revision id:
    revid = get_cmd_output('git', ['rev-parse', 'HEAD']);
    revid = revid.rstrip()

    # Find out the current branch:
    branch = get_cmd_output('git', ['branch']);
    branch = branch.rstrip();

    print "Revid is : " + revid
    print "Branch is : " + branch

    # Remove any files containing '#'
    runcmd("cd " + dist_dir + " && find . | grep '#' | xargs rm")

    # Remove any files containing '~'
    runcmd("cd " + dist_dir + " && find . | grep '~' | xargs rm")

    # Remove any files containing '~'
    runcmd("cd " + dist_dir + " && find . | grep '.orig' | xargs rm")

    # Minify the code
    print "Minifying... please wait"
    data = minify(revid, 'compiled_code')
    print "Minified size: %i" % len(data)

    if len(data) < 500:
        print "Minification failed!"
        print minify(revid, 'errors')
        return


    print "Minification successful!"
    # Add revision id to the minified code.
    data = data.replace("revision: ZZZ", "revision: %s" % revid)

    # Save the minified code into js/min.js
    minified = open(dist_dir + 'js/min.js', 'w')
    minified.write(data)
    minified.close()

    # Replace reference to js files with minified js in deployed version
    # of index.html.
    runcmd("sed -i '' -e 's/<script[^>]*><\/script>//g' " + dist_dir + "index.html")
    runcmd("sed -i '' -e 's/<\/body>/<script src=\"js\/min.js\"><\/script><\/body>/g' " + dist_dir + "index.html")

    # Add any files that are new and remove any files that no longer exist
    runcmd("cd " + dist_dir + " && hg addremove")

    # Commit the deployed dir.
    runcmd("cd " + dist_dir + " && hg commit -m 'tsviz auto-deployment'")
    
    # Push the deployed dir.
    runcmd("cd " + dist_dir + " && hg push")


    # Git version for above:
    # runcmd("cd " + dist_dir + " && git add -A")
    # runcmd("cd " + dist_dir + " && git commit -m 'shiviz auto-deployment test '")
    # runcmd("cd " + dist_dir + " && git push")

    print
    print "Done."
    return

    Workhorse method to execute all the of the steps described in the file header.
    
Workhorse method to execute all the of the steps described in the file header.
Workhorse method to execute all the of the steps described in the file header .
def main():
    src_dir = "./"
    dist_dir = "../bestchai.bitbucket.org/tsviz/"
    print "Deploying to: " + dist_dir
    print "from: " + src_dir
    if( confirm("Is it okay to remove the previous deployed version?", False) ):
        if (os.path.exists(dist_dir)):
            runcmd("rm -rf " + dist_dir + "*")
        else:
            print "Error: deployment dir is not where it is expected."
            sys.exit(-1)
    else:
        print "Deployment failed."
        sys.exit(-1)
    if (os.path.exists(src_dir)):
        runcmd("cp -R " + src_dir + "* " + dist_dir)
        runcmd("rm -rf " + dist_dir + "/js/*")
    else:
        print "Error: source dir is not where it is expected."
        sys.exit(-1)
    revid = get_cmd_output('git', ['rev-parse', 'HEAD']);
    revid = revid.rstrip()
    branch = get_cmd_output('git', ['branch']);
    branch = branch.rstrip();
    print "Revid is : " + revid
    print "Branch is : " + branch
    runcmd("cd " + dist_dir + " && find . | grep '#' | xargs rm")
    runcmd("cd " + dist_dir + " && find . | grep '~' | xargs rm")
    runcmd("cd " + dist_dir + " && find . | grep '.orig' | xargs rm")
    print "Minifying... please wait"
    data = minify(revid, 'compiled_code')
    print "Minified size: %i" % len(data)
    if len(data) < 500:
        print "Minification failed!"
        print minify(revid, 'errors')
        return
    print "Minification successful!"
    data = data.replace("revision: ZZZ", "revision: %s" % revid)
    minified = open(dist_dir + 'js/min.js', 'w')
    minified.write(data)
    minified.close()
    runcmd("sed -i '' -e 's/<script[^>]*><\/script>//g' " + dist_dir + "index.html")
    runcmd("sed -i '' -e 's/<\/body>/<script src=\"js\/min.js\"><\/script><\/body>/g' " + dist_dir + "index.html")
    runcmd("cd " + dist_dir + " && hg addremove")
    runcmd("cd " + dist_dir + " && hg commit -m 'tsviz auto-deployment'")
    runcmd("cd " + dist_dir + " && hg push")
    print
    print "Done."
    return
def main ( ) : src_dir = "./" dist_dir = "../bestchai.bitbucket.org/tsviz/" print "Deploying to: " + dist_dir print "from: " + src_dir if ( confirm ( "Is it okay to remove the previous deployed version?" , False ) ) : if ( os . path . exists ( dist_dir ) ) : runcmd ( "rm -rf " + dist_dir + "*" ) else : print "Error: deployment dir is not where it is expected." sys . exit ( - 1 ) else : print "Deployment failed." sys . exit ( - 1 ) if ( os . path . exists ( src_dir ) ) : runcmd ( "cp -R " + src_dir + "* " + dist_dir ) runcmd ( "rm -rf " + dist_dir + "/js/*" ) else : print "Error: source dir is not where it is expected." sys . exit ( - 1 ) revid = get_cmd_output ( 'git' , [ 'rev-parse' , 'HEAD' ] ) ; revid = revid . rstrip ( ) branch = get_cmd_output ( 'git' , [ 'branch' ] ) ; branch = branch . rstrip ( ) ; print "Revid is : " + revid print "Branch is : " + branch runcmd ( "cd " + dist_dir + " && find . | grep '#' | xargs rm" ) runcmd ( "cd " + dist_dir + " && find . | grep '~' | xargs rm" ) runcmd ( "cd " + dist_dir + " && find . | grep '.orig' | xargs rm" ) print "Minifying... please wait" data = minify ( revid , 'compiled_code' ) print "Minified size: %i" % len ( data ) if len ( data ) < 500 : print "Minification failed!" print minify ( revid , 'errors' ) return print "Minification successful!" data = data . replace ( "revision: ZZZ" , "revision: %s" % revid ) minified = open ( dist_dir + 'js/min.js' , 'w' ) minified . write ( data ) minified . close ( ) runcmd ( "sed -i '' -e 's/<script[^>]*><\/script>//g' " + dist_dir + "index.html" ) runcmd ( "sed -i '' -e 's/<\/body>/<script src=\"js\/min.js\"><\/script><\/body>/g' " + dist_dir + "index.html" ) runcmd ( "cd " + dist_dir + " && hg addremove" ) runcmd ( "cd " + dist_dir + " && hg commit -m 'tsviz auto-deployment'" ) runcmd ( "cd " + dist_dir + " && hg push" ) print print "Done." return
Workhorse method to execute all the of the steps described in the file header.
Workhorse method to execute all the of the steps described in the file header .
'''
    Workhorse method to execute all the of the steps described in the file header.
    ''' # Confirmation message. # Remove previously deployed version of tsviz. # Copy over the source. # Remove js source code since we will be using a minified version (see below). # Compile docs # if (runcmd("perl docgen.pl " + dist_dir) != 0): #     sys.exit(-1) # Find out the current revision id: # Find out the current branch: # Remove any files containing '#' # Remove any files containing '~' # Remove any files containing '~' # Minify the code # Add revision id to the minified code. # Save the minified code into js/min.js # Replace reference to js files with minified js in deployed version # of index.html. # Add any files that are new and remove any files that no longer exist # Commit the deployed dir. # Push the deployed dir. # Git version for above: # runcmd("cd " + dist_dir + " && git add -A") # runcmd("cd " + dist_dir + " && git commit -m 'shiviz auto-deployment test '") # runcmd("cd " + dist_dir + " && git push")