Skip to content
Browse files

Fix packaging. Change getArgs() to use hand parsing for 2.x and 3.x c…

…ompat. Fallback to simplejson for < 2.6 folks
  • Loading branch information...
1 parent 52798d2 commit 2ce63dde71439a190be51e902baa1feac3ec8bfa @coopernurse coopernurse committed Feb 2, 2012
Showing with 23 additions and 18 deletions.
  1. +7 −0 iron_worker/__init__.py
  2. +15 −16 iron_worker/iron_worker.py
  3. +1 −2 setup.py
View
7 iron_worker/__init__.py
@@ -0,0 +1,7 @@
+import sys
+import os
+sys.path.insert(0, os.path.split(__file__)[0])
+import iron_worker
+IronWorker = iron_worker.IronWorker
+
+
View
31 iron_worker/iron_worker.py
@@ -1,14 +1,16 @@
# IronWorker For Python
import os
+import sys
import time
-import json
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import zipfile
-import argparse
import ConfigParser
-
+try:
+ import json
+except ImportError:
+ import simplejson as json
def file_exists(file):
"""Check if a file exists."""
@@ -183,24 +185,21 @@ def __setCommonHeaders(self):
@staticmethod
def getArgs():
- """Get the arguments that are passed to all IronWorkers."""
- parser = argparse.ArgumentParser(description="IronWorker")
- parser.add_argument("-payload", type=str, required=False,
- help="The location of a file containing a JSON payload.")
- parser.add_argument("-d", type=str, required=False,
- help="The directory that the worker is running from.")
- parser.add_argument("-e", type=str, required=False,
- help="The environment this worker is running under.")
- parser.add_argument("-id", type=str, required=False,
- help="This worker's unique identifier.")
- return parser.parse_args()
+ """Get the arguments that are passed to all IronWorkers as a dict"""
+ args = { }
+ for i in range(len(sys.argv)):
+ if sys.argv[i].startswith("-") and (i+1) < len(sys.argv):
+ key = sys.argv[i][1:]
+ i += 1
+ args[key] = sys.argv[i]
+ return args
@staticmethod
def getPayload():
"""Get the payload that was sent to a worker."""
args = IronWorker.getArgs()
- if args.payload is not None and file_exists(args.payload):
- return json.loads(open(args.payload).read())
+ if args.has_key('payload') and file_exists(args['payload']):
+ return json.loads(open(args['payload']).read())
@staticmethod
def Rfc3339(timestamp=None):
View
3 setup.py
@@ -20,6 +20,5 @@
author_email="support@iron.io",
url='http://iron.io/products/worker',
install_requires=required,
- packages=[ '' ],
- package_dir={'':'iron_worker'},
+ packages=[ 'iron_worker' ],
)

0 comments on commit 2ce63dd

Please sign in to comment.
Something went wrong with that request. Please try again.