PageRenderTime 123ms CodeModel.GetById 60ms app.highlight 8ms RepoModel.GetById 53ms app.codeStats 0ms

/src/test.sh

http://googlecl.googlecode.com/
Shell | 138 lines | 117 code | 15 blank | 6 comment | 19 complexity | dc50d3991e459fb2d25fb8bc2c43e7cc MD5 | raw file
  1#!/bin/bash
  2
  3TOUCH_PREFIX="tested_"
  4GOOGLE_SH=./google.py
  5
  6# List of commands to set by each function
  7declare -a commands
  8
  9# Commands to run for cleaning up test account
 10#declare -a cleanup_commands
 11
 12function blogger {
 13  echo 'This is my post from a file\nIt contains a few line breaks, but not much else.' > test_post.txt
 14  commands[0]='blogger post --tags delete test_post.txt'
 15  commands[1]='blogger list --fields title,author'
 16  commands[2]='blogger post -n CL_post_test "This is my post from a command line"'
 17  commands[3]='blogger tag CL_post_ delete'
 18  commands[4]='blogger delete CL_post_test test_post ^New post$ --yes'
 19}
 20
 21function calendar {
 22  commands[0]='calendar add "test event at 5pm on 10/10/10"'
 23  commands[1]='calendar add "test event at midnight on 10/10/10"'
 24  commands[2]='calendar add "test event today at 3" --reminder 1h'
 25  commands[3]='calendar today'
 26  commands[4]='calendar list --date 2010-10-10'
 27  commands[5]='calendar delete --date 10/10/10 test --yes'
 28  commands[6]='calendar delete --date today@3 test'
 29}
 30
 31function contacts {
 32  echo -e 'contacts csv1, test_csv1@eh.com\ncontacts csv2, test_csv2@eh.com' > contacts.csv
 33#  commands[0]='contacts add "contacts test1,test_email1@nowhere.com" "contacts test2,test_email2@nowhere.com"'
 34  commands[1]='contacts add contacts.csv'
 35  commands[2]='contacts add "contacts test1,test_email1@nowhere.com"'
 36  commands[3]='contacts list contacts'      # Assumes that "fields" is specified in config file
 37  commands[4]='contacts add-groups test_group'
 38  commands[5]='contacts list-groups'
 39  commands[6]='contacts delete-groups test_group --yes'
 40  commands[7]='contacts delete test[0-9]?_?'
 41}
 42
 43function docs {
 44  echo -e 'This is a document that I am about to upload.' > test_doc.txt
 45  commands[0]='docs upload test_doc.txt'
 46  commands[1]='docs get test_doc test_download.txt'
 47  commands[2]='docs list --fields title,url-direct --delimiter ": "'
 48  commands[3]='docs edit test_doc --editor vim'
 49  commands[4]='docs delete test_doc'
 50}
 51
 52function finance {
 53  commands[0]='finance create my_empty_pfl USD'
 54  commands[1]='finance create-pos my_empty_pfl NASDAQ:MSFT'
 55  commands[2]='finance create-txn my_empty_pfl NASDAQ:MSFT Sell'
 56  commands[3]='finance list'
 57  commands[4]='finance list-pos --title=.*'
 58  commands[5]='finance list-txn --title=.* --ticker=NASDAQ:MSFT'
 59  commands[6]='finance delete-txn'
 60  commands[7]='finance delete-pos'
 61  commands[8]='finance delete my_empty'
 62}
 63
 64function picasa {
 65  commands[0]='picasa create test_album --tags "test, Disney World, florida, vacation" ~/testphotos/IMG_9882.JPG'
 66  commands[1]='picasa create test_album2'
 67  commands[2]='picasa list --fields title,url-site -q test'
 68  commands[3]='picasa list-albums'
 69  commands[4]='picasa delete "nosuchalbumexists"'
 70  commands[5]='picasa get "test_album" .'
 71  commands[6]='picasa post -n "test_album" --tags "Disney World, florida, vacation" ~/testphotos/IMG_9883.JPG'
 72  commands[7]='picasa tag "nosuchalbumexists" -t tag1,tag2'
 73  commands[8]='picasa tag "test_album" -t --,tag1,tag2'
 74  commands[9]='picasa delete test_album'
 75}
 76
 77function youtube {
 78  commands[0]='youtube post ~/testclips/fighting_cats4.mp4 -n "New test cat movie" -s "More cats on youtube" Education --tags test,cats'
 79  commands[1]='youtube list'
 80  commands[2]='youtube tag cat optionless_tag'
 81  commands[3]='youtube tag -n "D_N_E" -t wontgothrough'
 82  commands[4]='youtube post ~/D_N_E -n failure -c Education'
 83  commands[5]='youtube delete New'
 84}
 85
 86function goog_help {
 87  commands[0]="help"
 88}
 89
 90prompt_quit() {
 91  echo Hit Ctrl-C again to exit, enter to skip current command
 92  read junk
 93}
 94
 95trap prompt_quit INT
 96
 97if [ ${#@} -eq 1 ] && [ $@ == all ]; then
 98  TASKS=( blogger calendar contacts docs picasa youtube )
 99else
100  TASKS=$@
101fi
102
103for task in ${TASKS[*]}
104do
105  unset commands
106  echo -e "\n"
107  echo ===$task===
108  if [ $task == blogger ]; then
109    blogger
110  fi
111  if [ $task == calendar ]; then
112    calendar
113  fi
114  if [ $task == contacts ]; then
115    contacts
116  fi
117  if [ $task == docs ]; then
118    docs
119  fi
120  if [ $task == finance ]; then
121    finance
122  fi
123  if [ $task == picasa ]; then
124    picasa
125  fi
126  if [ $task == youtube ]; then
127    youtube
128  fi
129  if [ $task == help ]; then
130    goog_help
131  fi
132  # Make note of which tasks have been run, for cleanup later
133  eval touch "$TOUCH_PREFIX$task"
134  for index in ${!commands[*]}; do
135    echo -e "\n===${commands[$index]}"
136    eval $GOOGLE_SH ${commands[$index]}
137  done
138done