Script – from google code svn to google code downloads

You may have a google code project and the project has the same layout in the google code svn repository as the target files you wish to publish in the google code download section.

Manually downloading a copy of your repo and exporting to a zip file then manually uploading to google can be a pain. The following script takes care of doing all that for you

And now to the point you can get the two files here

Once you download both files and you place them in a folder make sure both are executable and to get a list of options you can run:

./google-code-svn-to-download.sh

Usage: ./google-code-svn-to-download.sh

Required parameters

-p Google Code project name

Optional parameters

-u Your Google Code username (will ask if not provided)
-w Your Google Code password (will ask if not provided)
-s Short description of the file (Defaults to project name)
-l A list of comma-separated labels to attach to the file
-f the name of the file to upload (Defaults to project name)

And here is an example of the script running passing all parameters:

 
raul-raja-martinezs-macbook:test raul$ ./google-code-svn-to-download.sh -p raulrajatutorials -u raulraja -w your_google_code_pass -s "my file summary" -l tag1,tag2,tag3,tag4 -f myfilename
fetching raulrajatutorials from google svn repository
cleaning up local svn files
zipping raulrajatutorials to myfilename.zip
removing svn downloaded files
uploading raulrajatutorials to google code downloads area
The file was uploaded successfully.
URL: http://raulrajatutorials.googlecode.com/files/myfilename.ZIP
Removing myfilename.zip after uploaded to google

This is what the script does:

  1. Download a copy of your trunk from your google code project svn repository.
  2. Zip the download
  3. Uploads the zipped file to your google code downloads section using this handy python script provided by google

And in case you’re wondering about the script itself here it is. If you copy it from here don’t forget to grab also the google script here

 
#!/bin/bash
# checkouts your google code project and makes a zip and uploads it to the downloads section
#  -s SUMMARY, Short description of the file
#  -p PROJECT, Google Code project name
#  -u USER, Your Google Code username
#  -w PASSWORD, Your Google Code password
#  -l LABELS, An optional list of comma-separated labels to attach to the file
#  -f FILENAME, the file name to be used on the upload
 
SCRIPT_USAGE="\
\n    Usage: $0
\n
\n    Required parameters
\n
\n      -p Google Code project name
\n
\n    Optional parameters
\n
\n      -u Your Google Code username (will ask if not provided)
\n      -w Your Google Code password (will ask if not provided)
\n      -s Short description of the file (Defaults to project name)
\n      -l A list of comma-separated labels to attach to the file
\n      -f the name of the file to upload (Defaults to project name)
\n
\n"
 
 
# Iterate over the options passed to the script
while getopts "s:p:u:w:l:f:" MYOPTION;
do
	case "$MYOPTION" in
		s)   GOOGLE_CODE_SUMMARY="$OPTARG" ;;
		p)   GOOGLE_CODE_PROJECT="$OPTARG" ;;
		u)   GOOGLE_CODE_USER="$OPTARG" ;;
		w)   GOOGLE_CODE_PASSWORD="$OPTARG" ;;
		l)   GOOGLE_CODE_LABELS="$OPTARG" ;;
		f)   GOOGLE_CODE_FILENAME="$OPTARG" ;;
	esac
done
 
 
# if all the required options are there
if [ -z "${GOOGLE_CODE_PROJECT}" ];
then
    # One of the required arguments is missing
    echo -e $SCRIPT_USAGE
else
     # setup default values if necessary
    GOOGLE_CODE_FILENAME=${GOOGLE_CODE_FILENAME:="$GOOGLE_CODE_PROJECT"}
    GOOGLE_CODE_SUMMARY=${GOOGLE_CODE_SUMMARY:="latest $GOOGLE_CODE_PROJECT"}
    # fetch project from svn
    echo "fetching $GOOGLE_CODE_PROJECT from google svn repository"
    svn export -q http://$GOOGLE_CODE_PROJECT.googlecode.com/svn/trunk/ $GOOGLE_CODE_PROJECT
 
    # zip the project
    echo "zipping $GOOGLE_CODE_PROJECT to $GOOGLE_CODE_FILENAME.zip"
    zip -r -q $GOOGLE_CODE_FILENAME.zip $GOOGLE_CODE_PROJECT
 
    # remove the svn download folders
    echo "removing svn downloaded files"
    rm -rf $GOOGLE_CODE_PROJECT
 
    # upload the project to the google code downloads
    echo "uploading $GOOGLE_CODE_PROJECT to google code downloads area"
    ./googlecode_upload.py -s "$GOOGLE_CODE_SUMMARY" -p "$GOOGLE_CODE_PROJECT" -u "$GOOGLE_CODE_USER" -w "$GOOGLE_CODE_PASSWORD" -l "$GOOGLE_CODE_LABELS" $GOOGLE_CODE_FILENAME.ZIP
 
    # remove the zip file
    echo "Removing $GOOGLE_CODE_FILENAME.zip after uploaded to google"
    rm -rf $GOOGLE_CODE_FILENAME.ZIP   
fi