Getting shovel to work in windows so python methods can be run like individual executables


/ Published in: Python
Save to your folder(s)

I had hear about a method to run a method like an executable, with the arguments being passed in from the commandline. Apparently, Ruby has this with the Rake project. Well, Python has it with [Shovel](http://devblog.seomoz.org/2012/03/shovel-rake-for-python). Only the instructions didn't work for me on windows, so I had to create a batch script to call `shovel` correctly.

So here's my setup. I installed shovel using `easy_install shovel`, which placed it in my python scripts folder (C:\Python27\Scripts, which is in my PATH). I created 'shovel.bat' (see source) in the same folder. So now I can call `shovel` from anywhere and it will call my batch file, passing the parameters into shovel.

For completeness, here is my working directory structure (note the subfolder called shovel):

D:.
│ song log.log
│ Untitled_10.mp3
│ Untitled_11.mp3
│ Untitled_2.mp3
│ Untitled_3.mp3
│ Untitled_4.mp3
│ Untitled_5.mp3
│ Untitled_6.mp3
│ Untitled_7.mp3
│ Untitled_8.mp3
│ Untitled_9.mp3
│
└───shovel
tasks.py

My python script is incomplete but can be run by shovel using `shovel tasks.extractSongInfo "log file name.log"` from the directory above the 'shovel' directory. Here's the script:


from shovel import task

@task
def extractSongInfo(logFile):
"""Given a log file with lines like
"{date} INFO Currently playing - Song: {songName} - Artist: {artist} - Length: {numSeconds}"
return a collection of extracted info."""
opId = "Extracting song info" # operation ID
print opId
print 'Done: ' + opId


Copy this code and paste it in your HTML
  1. :: @echo off
  2. :: This file can be called from anywhere, so we need to give the full path to the shovel file (which is in the same directory as this script)
  3. @setlocal
  4. @set directory=%~dp0
  5. @python %directory%shovel %*
  6. :: Turns out the above works, so no need to inline the contents of 'shovel' as done below. Note, the shovel python file needs to be in a subdirectory called 'shovel'
  7. :: python -c "__requires__ = 'shovel==0.1.9'; import pkg_resources; pkg_resources.run_script('shovel==0.1.9', 'shovel')" %*

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.