#!/usr/bin/env python
import sys
import os
import subprocess
from optparse import OptionParser

parser = OptionParser()
parser.usage = parser.usage + "\n\nCopies frostwire-style.css and structure.css into a single '/versions/frostwire.<version>.css' file"
parser.add_option("-v", type="int", dest="version", help="The new version number for the css file")

if __name__ =='__main__':
    (options, args) = parser.parse_args()

    if options.version is None:
        parser.print_help()
        print ""
        sys.exit(1)

    if not os.path.isfile("./frostwire-style.css") or not os.path.isfile("./structure.css"):
        print "\nPlease make sure you are on the right folder, make sure you have frostwire-style.css and structure.css inside %s.\n" % (os.getcwd())
        parser.print_help()
        print ""
        sys.exit(1)

    commands = []
    commands.append("cat frostwire-style.css structure.css | cleancss -o versions/frostwire.%d.css" % (options.version))
    #commands.append("gzip -9 versions/frostwire.%d.css" % (options.version))
    #commands.append("mv versions/frostwire.%d.css.gz versions/frostwire.%d.css" % (options.version, options.version))
    #commands.append("s3cmd put -P --mime-type=text/css --add-header='Cache-Control:max-age=31536000' --add-header='Content-Encoding:gzip' versions/frostwire.%d.css s3://static.frostwire.com/vink/css/versions/" % (options.version))
    commands.append("git status .")

    for cmd in commands:
        print '>',cmd
        print "".join(os.popen(cmd).readlines())

    #print "\nversions/frostwire.%d.css uploaded to s3://static.frostwire.com/vink/css/versions/ - You should still add it to git and push it when you're ready\n"
    
