Permalink
Browse files

Add a few arguments to webdeploy.

  • Loading branch information...
1 parent b5d9012 commit c691ad06e7b4b32c49f187cd790c25bae4d7036a @igable committed Feb 20, 2012
Showing with 70 additions and 21 deletions.
  1. +24 −10 README.md
  2. +46 −11 webdeploy.py
View
34 README.md
@@ -1,24 +1,38 @@
+Author: Ian Gable <igable@uvic.ca>
## texwatcher
-texwatcher is a very basic tool for automatically compiling a TeX file with
-rubber when that file is changed. The tool was designed for OSX so that you can
-use any editor to edit your TeX and have the Mac Preview application pop up
-with your most recent changes contained in it.
+
+texwatcher is a basic tool for automatically compiling a TeX file with rubber
+when that file is changed. The tool was designed for OSX so that you can use
+any editor to edit your TeX and have the Mac Preview application pop up with
+your most recent changes contained in it.
### Usage
-Use the build in help by
+Use the built in help by
$texwatcher.py --help
## webdeploy.py
-webdeploy is can be used to checkout out clone a git repo and scp its
-contentents to a webserver after cleaning out the .git directories. It has
-losts of hardcoded entries.
+webdeploy is can be used to clone a git repo and scp its contentents to a
+webserver after cleaning out the .git directories. It could also be modified to
+use rsync. Using rsync is probably better then this script.
### usage
-Call it from .git/hooks/post-commit, then edit the script with the directories
-you want to deploy to.
+Call it from .git/hooks/post-commit. You can see the built in help with
+
+ $webdeploy.py --help
+
+## License
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of either:
+
+a) the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any
+later version, or
+
+b) the Apache v2 License.
View
57 webdeploy.py
@@ -12,12 +12,36 @@
import subprocess
import shutil
import re
-import shlex
+from optparse import OptionParser
def main():
- deploy_dir = "/Users/igable/code/webdeploy/"
- ssh_location = "igable@fate-2.phys.uvic.ca:~/public_html/testdeploy/."
+
+ parser = OptionParser(usage="%prog -t TEMPDIR -s SERVERDESTINATION -r REPOSITORY",version = "%prog 0.1")
+ parser.add_option("-t", "--temp-dir", dest="tempdir",
+ help="The temp directory to perform the checkout into prior to the scp",
+ metavar="TEMPDIR")
+ parser.add_option("-s","--server-destination", dest="serverdestination",
+ help="The scp string for the location of your server for example joe@server.com:/home/joe/www/",
+ metavar="SERVERDESTINATION")
+ parser.add_option("-r","--repository", dest="repository",
+ help="The location of the git repo", metavar="REPOSITORY")
+
+ (options,args) = parser.parse_args()
+
+ if not options.tempdir:
+ parser.print_help()
+ parser.error("You must specify a temp directory.")
+ if not options.serverdestination:
+ parser.print_help()
+ parser.error("You must provide a server destination.")
+ if not options.repository:
+ parser.print_help()
+ parser.error("You must provide a repository location.")
+
+ deploy_dir = options.tempdir
+ ssh_location = options.serverdestination
+ repository = options.repository
try:
os.chdir(os.path.dirname(deploy_dir))
@@ -28,17 +52,20 @@ def main():
try:
#remove the directory if it already exists
- checkout = deploy_dir + "bootstrap/"
+ checkout = deploy_dir + "cleandeploy/"
shutil.rmtree(os.path.dirname(checkout))
- except OSError:
- print "First time deploy this clearly"
+ except OSError as e:
+ print "First time you've deploy this clearly"
# need to handle an error if we can't checkout
- gitprocess = subprocess.Popen(["git","clone","/Users/igable/code/bootstrap"],stdout=open(os.devnull, 'w'))
+ gitprocess = subprocess.Popen(["git","clone",repository,"cleandeploy"],
+ stdout=open(os.devnull, 'w'))
gitprocess.wait()
# look for all the .git directories
- findprocess = subprocess.Popen(["find", deploy_dir, "-type", "d", "-name", ".git"], stdout=subprocess.PIPE)
+ # could probably replace this with a native python search
+ findprocess = subprocess.Popen(["find", deploy_dir, "-type", "d", "-name", ".git"],
+ stdout=subprocess.PIPE)
findoutput = findprocess.communicate()[0]
findprocess.wait()
@@ -47,10 +74,18 @@ def main():
for gitdir in gitdirs:
gitdirslash = gitdir + "/"
shutil.rmtree(os.path.dirname(gitdirslash))
-
+
+ try:
+ os.chdir("cleandeploy/")
+ except OSError as e:
+ print e
+ print "Something just removed the directory we checked out."
+ sys.exit()
+
+ # TODO: Check the ssh return code
# now copy the files into place with ssh
- os.chdir("bootstrap/")
- sshprocess = subprocess.Popen(["scp","-p","-r"] + os.listdir(os.path.dirname(os.getcwd()+"/")) + [ssh_location], stdout=open(os.devnull,'w'))
+ sshprocess = subprocess.Popen(["scp","-p","-r"] + os.listdir(os.path.dirname(os.getcwd()+"/"))
+ + [ssh_location], stdout=open(os.devnull,'w'))
sshprocess.wait()
main()

0 comments on commit c691ad0

Please sign in to comment.