#!/usr/bin/env python

import os
import sys
import getopt

import distutils.dir_util

generate = False
publish = False

try:
	opts, remaining_args = getopt.getopt(sys.argv[1:], "", [ "generate", "publish" ])
	for option, value in opts:
		if option == "--generate":
			 generate = True
		if option == "--publish":
			 publish = True

	(BUNDLE,) = remaining_args

except: 

        print ""
        print "Usage: ./upload-prod [--generate] [--publish] <BUNDLE>"
        print "  --generate will copy to staging, and generate repos and html"
        print "  --publish will rsync staging to destination. "
        print "     Without --publish, a test rsync run will be performed"
        print ""
        print " General idea is to generate and then to a test publish to see if anything"
        print "  needs to be pruned.  And once we find no files to delete, we can publish"
        print "  without generating again"
        print ""
        print "Synopsis:"
        print ""
        print " # Build stage, and generate stage html/repos"
        print " ./upload-prod --generate RELEASE"
        print " # test publish.  If you need to clean up, do so and start from the generate step"
        print " ./upload-prod            RELEASE"
        print " # actual publish"
        print " ./upload-prod --publish  RELEASE"
        print ""

        sys.exit(1)

def do(command): 
	print command
	ret = os.system(command)
	if ret:
		print "Exiting..."
		sys.exit(1)


# Can't use '--delete' to build up the staging area... otherwise we remove stuff we just copied
rsync_opts = "-avz"

STAGE_DIR = os.getcwd() + "/stage/release"

## go-mono.com
#TARGET_USER="mono-web"
#TARGET_HOST="go-mono.com"
#TARGET_DIR="~/go-mono/"
#TARGET_URL="''"

# ftp.novell.com
#  TODO: Maybe before we change people's repo urls, we should make our repos look more like the
#   the build service repos?  So that when we start using obs' generated repos... ?
TARGET_USER = "ajorgensen"
TARGET_HOST = "ftp.novell.com"
TARGET_DIR = "/srv/ftp/pub/mono"
TARGET_URL = "/pub/mono"

if not os.path.exists("bundles/" + BUNDLE):
	print "Bundle %s does not exist" % BUNDLE
	sys.exit(1)

final_rsync_opts=""
if not publish:
	final_rsync_opts="n"
	print "Doing dry run..."

distutils.dir_util.mkpath(STAGE_DIR)


# We can call delete on so that stuff that gets deleted in the source will be deleted from the stage
#os.chdir('packages')
# Exclude moon packages because they are built against ffmpeg
#do("rsync %s --delete --exclude '*/moon/' . %s/download" % (rsync_opts, STAGE_DIR))

#os.chdir("../external_packages")
#do("rsync %s --delete . %s/external_packages" % (rsync_opts, STAGE_DIR))

#os.chdir("../sources")
#do("rsync %s --delete . %s/sources" % (rsync_opts, STAGE_DIR))
#os.chdir("..")

current_dir = os.getcwd()

os.chdir("../website")
do("./sync-bundle.py --skip_missing %s %s" % (BUNDLE, STAGE_DIR))
os.chdir(current_dir)

# Push the installers
# If these need to be cleaned up, you need to clean from source and stage (ugh)
#os.chdir("../windows-installer/Output")
#do("rsync %s . %s/archive" % (rsync_opts, STAGE_DIR))
#os.chdir(current_dir)

#os.chdir("../sunos/output")
#do("rsync %s . %s/archive" % (rsync_opts, STAGE_DIR))
#os.chdir(current_dir)

#os.chdir("../macosx/output")
#do("rsync %s . %s/archive" % (rsync_opts, STAGE_DIR))
#os.chdir(current_dir)

os.chdir("../website")

if generate:
	do("cp -fp packaging.css " + STAGE_DIR)
	do("cp -fp zip-icon.png  " + STAGE_DIR)

	do("./mk-sources-index.py	%s %s %s/sources" % 		(BUNDLE, STAGE_DIR, STAGE_DIR))
	do("./mk-archive-index.py --skip_packages %s %s" % 		(BUNDLE, STAGE_DIR))

# Publish stage
if publish:
	do('ssh %s@%s "mkdir -p %s"' % (TARGET_USER, TARGET_HOST, TARGET_DIR))
	os.chdir(STAGE_DIR)
	do('chmod -R ug+rwX .')
	# Can't use --delete here either... because we don't want to remove release notes or generated html from previous releases
	do('rsync %s%s -H . %s@%s:%s' % (rsync_opts, final_rsync_opts, TARGET_USER, TARGET_HOST, TARGET_DIR))
	do('ssh %s@%s "chgrp -R mono %s"' % (TARGET_USER, TARGET_HOST, TARGET_DIR))

d64799a1b18119c7c277752f58cf264cf531de91
#!/usr/bin/env python

import os
import sys
import getopt

import distutils.dir_util

generate = False
publish = False

try:
	opts, remaining_args = getopt.getopt(sys.argv[1:], "", [ "generate", "publish" ])
	for option, value in opts:
		if option == "--generate":
			 generate = True
		if option == "--publish":
			 publish = True

	(BUNDLE,) = remaining_args

except: 

        print ""
        print "Usage: ./upload-prod [--generate] [--publish] <BUNDLE>"
        print "  --generate will copy to staging, and generate repos and html"
        print "  --publish will rsync staging to destination. "
        print "     Without --publish, a test rsync run will be performed"
        print ""
        print " General idea is to generate and then to a test publish to see if anything"
        print "  needs to be pruned.  And once we find no files to delete, we can publish"
        print "  without generating again"
        print ""
        print "Synopsis:"
        print ""
        print " # Build stage, and generate stage html/repos"
        print " ./upload-prod --generate RELEASE"
        print " # test publish.  If you need to clean up, do so and start from the generate step"
        print " ./upload-prod            RELEASE"
        print " # actual publish"
        print " ./upload-prod --publish  RELEASE"
        print ""

        sys.exit(1)

def do(command): 
	print command
	ret = os.system(command)
	if ret:
		print "Exiting..."
		sys.exit(1)


# Can't use '--delete' to build up the staging area... otherwise we remove stuff we just copied
rsync_opts = "-avz"

STAGE_DIR = os.getcwd() + "/stage/release"

## go-mono.com
#TARGET_USER="mono-web"
#TARGET_HOST="go-mono.com"
#TARGET_DIR="~/go-mono/"
#TARGET_URL="''"

# ftp.novell.com
#  TODO: Maybe before we change people's repo urls, we should make our repos look more like the
#   the build service repos?  So that when we start using obs' generated repos... ?
TARGET_USER = "ajorgensen"
TARGET_HOST = "ftp.novell.com"
TARGET_DIR = "/srv/ftp/pub/mono"
TARGET_URL = "/pub/mono"

if not os.path.exists("bundles/" + BUNDLE):
	print "Bundle %s does not exist" % BUNDLE
	sys.exit(1)

final_rsync_opts=""
if not publish:
	final_rsync_opts="n"
	print "Doing dry run..."

distutils.dir_util.mkpath(STAGE_DIR)


# We can call delete on so that stuff that gets deleted in the source will be deleted from the stage
#os.chdir('packages')
# Exclude moon packages because they are built against ffmpeg
#do("rsync %s --delete --exclude '*/moon/' . %s/download" % (rsync_opts, STAGE_DIR))

#os.chdir("../external_packages")
#do("rsync %s --delete . %s/external_packages" % (rsync_opts, STAGE_DIR))

#os.chdir("../sources")
#do("rsync %s --delete . %s/sources" % (rsync_opts, STAGE_DIR))
#os.chdir("..")

current_dir = os.getcwd()

os.chdir("../website")
do("./sync-bundle.py --skip_missing %s %s" % (BUNDLE, STAGE_DIR))
os.chdir(current_dir)

# Push the installers
# If these need to be cleaned up, you need to clean from source and stage (ugh)
#os.chdir("../windows-installer/Output")
#do("rsync %s . %s/archive" % (rsync_opts, STAGE_DIR))
#os.chdir(current_dir)

#os.chdir("../sunos/output")
#do("rsync %s . %s/archive" % (rsync_opts, STAGE_DIR))
#os.chdir(current_dir)

#os.chdir("../macosx/output")
#do("rsync %s . %s/archive" % (rsync_opts, STAGE_DIR))
#os.chdir(current_dir)

os.chdir("../website")

if generate:
	do("cp -fp packaging.css " + STAGE_DIR)
	do("cp -fp zip-icon.png  " + STAGE_DIR)

	do("./mk-sources-index.py	%s %s %s/sources" % 		(BUNDLE, STAGE_DIR, STAGE_DIR))
	do("./mk-archive-index.py --skip_packages %s %s" % 		(BUNDLE, STAGE_DIR))

# Publish stage
if publish:
	do('ssh %s@%s "mkdir -p %s"' % (TARGET_USER, TARGET_HOST, TARGET_DIR))
	os.chdir(STAGE_DIR)
	do('chmod -R ug+rwX .')
	# Can't use --delete here either... because we don't want to remove release notes or generated html from previous releases
	do('rsync %s%s -H . %s@%s:%s' % (rsync_opts, final_rsync_opts, TARGET_USER, TARGET_HOST, TARGET_DIR))
	do('ssh %s@%s "chgrp -R mono %s"' % (TARGET_USER, TARGET_HOST, TARGET_DIR))
