]> jfr.im git - z_archive/twitter.git/commitdiff
Re-organized and updated api_updater script.
authorHatem Nassrat <redacted>
Mon, 2 Mar 2009 12:45:00 +0000 (08:45 -0400)
committerHatem Nassrat <redacted>
Mon, 2 Mar 2009 12:56:46 +0000 (08:56 -0400)
    Moved Script out of the python egg
    Renamed _POST_ACTIONS to POST_ACTIONS

twitter/api.py
twitter/twitter_globals.py
utils/update.py [moved from twitter/update.py with 77% similarity, mode: 0755]

index 118d4fb8cf9653e1855e96a11a369992a2395eb7..b6bafe786b2ba56aa38de2885aefea603379fa17 100644 (file)
@@ -6,7 +6,7 @@ import urllib2
 
 from exceptions import Exception
 
-from twitter.twitter_globals import _POST_ACTIONS
+from twitter.twitter_globals import POST_ACTIONS
 
 def _py26OrGreater():
     import sys
@@ -43,13 +43,13 @@ class TwitterCall(object):
     def __call__(self, **kwargs):
         uri = self.uri
         method = "GET"
-        for action in _POST_ACTIONS:
+        for action in POST_ACTIONS:
             if self.uri.endswith(action):
                 method = "POST"
                 if (self.agent):
                     kwargs["source"] = self.agent
                 break
-        
+
         id = kwargs.pop('id', None)
         if id:
             uri += "/%s" %(id)
index 46e10055155f2498baf8aca1e5a65b11afe52560..680ccfcfa61d3886316729e7e2dee677028c6ced 100644 (file)
@@ -3,10 +3,10 @@
 
     ..data::
 
-        `_POST_ACTIONS`: Methods that require the use of POST
+        `POST_ACTIONS`: Methods that require the use of POST
 '''
 
-_POST_ACTIONS = [
+POST_ACTIONS = [
 
     # Status Methods
     'update', 
old mode 100644 (file)
new mode 100755 (executable)
similarity index 77%
rename from twitter/update.py
rename to utils/update.py
index 9ad8374..348e993
@@ -1,16 +1,18 @@
+#!/usr/bin/env python
+
 '''
 This is a development script, intended for office use only.
 
-This script generates output the _POST_ACTIONS variable
+This script generates the POST_ACTIONS variable
 for placement in the twitter_globals.py
 
-Example Util:
+Example Usage:
 
-    python update.py >twitter_globals.py
+    %prog >twitter/twitter_globals.py
 
 Dependencies:
 
-    (easy_install) BeautifulSoup
+    (easy_install) BeautifulSoup
 '''
 
 import sys
@@ -22,8 +24,8 @@ def uni2html(u):
     '''
     Convert unicode to html.
 
-    Basically leaves ascii chars as is, and attempts to encode unicode chars as
-    HTML entities. If the conversion fails the character is skipped.
+    Basically leaves ascii chars as is, and attempts to encode unicode chars
+    as HTML entities. If the conversion fails the character is skipped.
     '''
     htmlentities = list()
     for c in u:
@@ -66,8 +68,7 @@ def print_fw(iterable, joins=', ', prefix='', indent=0, width=79, trail=False):
         linew += len(sentry)
     sys.stdout.write('\n')
 
-
-def main():
+def main_with_options(options, files):
     '''
     Main function the prints twitter's _POST_ACTIONS to stdout
 
@@ -108,7 +109,7 @@ def main():
                     POST_ACTION_HASH[method_name] = (method_type,)
 
     # Reverse the POST_ACTION_HASH
-    # this is really only done to generate comment strings
+    # this is done to allow generation of nice comment strings
     POST_ACTION_HASH_R = {}
     for method, method_types in POST_ACTION_HASH.items():
         try:
@@ -116,21 +117,41 @@ def main():
         except KeyError:
             POST_ACTION_HASH_R[method_types] = [method]
 
-    ## Print the _POST_ACTIONS to stdout as a Python List
+    ## Print the POST_ACTIONS to stdout as a Python List
     print """'''
     This module is automatically generated using `update.py`
 
     ..data::
 
-        `_POST_ACTIONS`: Methods that require the use of POST
+        `POST_ACTIONS`: Methods that require the use of POST
 '''
 """
-    print '_POST_ACTIONS = [\n'
+    print 'POST_ACTIONS = [\n'
     for method_types, methods in POST_ACTION_HASH_R.items():
         print_fw(method_types, prefix='# ', indent=1)
         print_fw([repr(str(x)) for x in methods], indent=1, trail=True)
         print ""
     print ']'
 
+def main():
+    import optparse
+
+    class CustomFormatter(optparse.IndentedHelpFormatter):
+        """formatter that overrides description reformatting."""
+        def format_description(self, description):
+            ''' indents each line in the description '''
+            return "\n".join([
+                "%s%s" %(" "*((self.level+1)*self.indent_increment), line)
+                for line in description.splitlines()
+            ]) + "\n"
+
+    parser = optparse.OptionParser(
+            formatter=CustomFormatter(),
+            description=__doc__
+        )
+    (options, files) = parser.parse_args()
+    main_with_options(options, files)
+
+
 if __name__ == "__main__":
     main()