allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [01/14] allura git commit: [#7878] ticket:771 Add __future__ imports
Date Wed, 20 May 2015 11:14:04 GMT
Repository: allura
Updated Branches:
  refs/heads/ib/7878 [created] bffdd182b


http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/perf/call_count.py
----------------------------------------------------------------------
diff --git a/scripts/perf/call_count.py b/scripts/perf/call_count.py
index 671e6f2..f67be7a 100755
--- a/scripts/perf/call_count.py
+++ b/scripts/perf/call_count.py
@@ -17,6 +17,10 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 import argparse
 import json
 import logging
@@ -68,7 +72,7 @@ def main(args):
 
     counts = count_page(test, url, verbose=args.verbose,
                         debug_html=args.debug_html)
-    print json.dumps(counts)
+    print(json.dumps(counts))
     write_csv(counts, args.id, args.data_file)
     test.tearDown()
 
@@ -116,17 +120,17 @@ def count_page(test, url, verbose=False, debug_html=False):
 
     with LogCapture('stats') as stats, LogCapture('timermiddleware') as calls:
         resp = test.app.get(url, extra_environ=dict(username='*anonymous'))
-        print url, resp.status
+        print(url, resp.status)
         if debug_html:
             debug_filename = 'call-{}.html'.format(''.join([random.choice(string.ascii_letters
+ string.digits)
                                                    for n in xrange(10)]))
             with open(debug_filename, 'w') as out:
                 out.write(resp.body)
-            print debug_filename
+            print(debug_filename)
 
     if verbose:
         for r in calls.records:
-            print r.getMessage()
+            print(r.getMessage())
 
     assert len(stats.records) == 1
     timings = json.loads(stats.records[0].getMessage())

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/perf/generate-projects.py
----------------------------------------------------------------------
diff --git a/scripts/perf/generate-projects.py b/scripts/perf/generate-projects.py
index 0374969..16fa5ea 100644
--- a/scripts/perf/generate-projects.py
+++ b/scripts/perf/generate-projects.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -28,10 +32,10 @@ def main(start, cnt):
         name = 'gen-proj-{}'.format(i)
         project = n.register_project(name, admin)
         if (i-start) > 0 and (i-start) % 100 == 0:
-            print 'Created {} projects'.format(i-start)
-    print 'Flushing...'
+            print('Created {} projects'.format(i-start))
+    print('Flushing...')
     ThreadLocalORMSession.flush_all()
-    print 'Done'
+    print('Done')
 
 if __name__ == '__main__':
     import sys

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/perf/md_perf.py
----------------------------------------------------------------------
diff --git a/scripts/perf/md_perf.py b/scripts/perf/md_perf.py
index e8d0f70..d92af2b 100644
--- a/scripts/perf/md_perf.py
+++ b/scripts/perf/md_perf.py
@@ -44,6 +44,10 @@ user    0m12.749s
 sys     0m1.112s
 
 """
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 
 import argparse
 import cProfile
@@ -85,24 +89,24 @@ def main(opts):
 
 def render(artifact, md, opts):
     start = begin = time.time()
-    print "%4s %20s %10s %s" % ('', 'Conversion Time (s)', 'Text Size', 'Post._id')
+    print("%4s %20s %10s %s" % ('', 'Conversion Time (s)', 'Text Size', 'Post._id'))
     for i, p in enumerate(artifact.discussion_thread.posts):
         text = DUMMYTEXT or p.text
         if opts.n and i + 1 not in opts.n:
-            print 'Skipping post %s' % str(i + 1)
+            print('Skipping post %s' % str(i + 1))
             continue
         if opts.profile:
-            print 'Profiling post %s' % str(i + 1)
+            print('Profiling post %s' % str(i + 1))
             cProfile.runctx('output = md.convert(text)', globals(), locals())
         else:
             output = md.convert(text)
         elapsed = time.time() - start
-        print "%4s %1.18f %10s %s" % (i + 1, elapsed, len(text), p._id)
+        print("%4s %1.18f %10s %s" % (i + 1, elapsed, len(text), p._id))
         if opts.output:
-            print 'Input:', text[:min(300, len(text))]
-            print 'Output:', output[:min(MAX_OUTPUT, len(output))]
+            print('Input:', text[:min(300, len(text))])
+            print('Output:', output[:min(MAX_OUTPUT, len(output))])
         start = time.time()
-    print "Total time:", start - begin
+    print("Total time:", start - begin)
     return output
 
 
@@ -128,4 +132,4 @@ if __name__ == '__main__':
     if opts.compare:
         opts.re2 = not opts.re2
         out2 = main(opts)
-        print 're/re2 outputs match: ', out1 == out2
+        print('re/re2 outputs match: ', out1 == out2)

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/perf/sstress.py
----------------------------------------------------------------------
diff --git a/scripts/perf/sstress.py b/scripts/perf/sstress.py
index 3f1a1b1..26bcbce 100644
--- a/scripts/perf/sstress.py
+++ b/scripts/perf/sstress.py
@@ -20,6 +20,10 @@
 '''
 sstress - an SMTP stress testing tool
 '''
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 
 import smtplib
 import threading
@@ -43,8 +47,8 @@ def main():
         t.join()
     end = time.time()
     elapsed = end - begin
-    print '%d requests completed in %f seconds' % (N, elapsed)
-    print '%f requests/second' % (N / elapsed)
+    print('%d requests completed in %f seconds' % (N, elapsed))
+    print('%f requests/second' % (N / elapsed))
 
 
 def stress():

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/perf/test_git_lcd.py
----------------------------------------------------------------------
diff --git a/scripts/perf/test_git_lcd.py b/scripts/perf/test_git_lcd.py
index 8d75e54..01a1831 100644
--- a/scripts/perf/test_git_lcd.py
+++ b/scripts/perf/test_git_lcd.py
@@ -17,6 +17,10 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 import sys
 import os
 from glob import glob
@@ -42,11 +46,11 @@ def main(repo_dir, sub_dir='', commit=None):
     commit = Mock(_id=commit or git.head)
     paths = glob(os.path.join(repo_dir, sub_dir, '*'))
     paths = [path.replace(repo_dir + '/', '', 1) for path in paths]
-    print "Timing LCDs for %s at %s" % (paths, commit._id)
+    print("Timing LCDs for %s at %s" % (paths, commit._id))
     with benchmark() as timer:
         result = git.last_commit_ids(commit, paths)
     pprint(result)
-    print "Took %f seconds" % timer['result']
+    print("Took %f seconds" % timer['result'])
 
 if __name__ == '__main__':
     main(*sys.argv[1:])

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/prep-scm-sandbox.py
----------------------------------------------------------------------
diff --git a/scripts/prep-scm-sandbox.py b/scripts/prep-scm-sandbox.py
index 414280f..883d4a9 100644
--- a/scripts/prep-scm-sandbox.py
+++ b/scripts/prep-scm-sandbox.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -41,26 +45,26 @@ def main():
             sb_host=sb_host,
             sb=sb,
             veid='%d0%.2d' % (sb_host, sb))
-        for sb_host in 5, 6, 7, 9
+        for sb_host in (5, 6, 7, 9)
         for sb in range(99)]
     new_lines = '\n'.join(new_lines)
     found_star = False
     with open(SSH_CONFIG, 'w') as fp:
         for line in lines:
             if not found_star and line.startswith('Host *'):
-                print >> fp, new_lines
+                print(new_lines, file=fp)
                 found_star = True
-            print >> fp, line.rstrip()
+            print(line.rstrip(), file=fp)
         if not found_star:
-            print >> fp, new_lines
+            print(new_lines, file=fp)
     os.system("ssh-keygen -t rsa -b 2048 -N '' -f %s" % KEYFILE)
 
     # Generate ldif
     pubkey = open(KEYFILE + '.pub').read()
     with open(LDIF_FILE, 'w') as fp:
         for user in USERS:
-            print >> fp, LDIF_TMPL.substitute(
-                user=user, pubkey=pubkey)
+            print(LDIF_TMPL.substitute(
+                user=user, pubkey=pubkey), file=fp)
 
     # Update LDAP
     assert 0 == os.system('/usr/local/sbin/ldaptool modify -v -f %s' %

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/prepare-allura-tickets-for-import.py
----------------------------------------------------------------------
diff --git a/scripts/prepare-allura-tickets-for-import.py b/scripts/prepare-allura-tickets-for-import.py
index dc6a695..743277b 100644
--- a/scripts/prepare-allura-tickets-for-import.py
+++ b/scripts/prepare-allura-tickets-for-import.py
@@ -16,6 +16,10 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 from itertools import tee, izip, chain
 import json
 import git

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/project-import.py
----------------------------------------------------------------------
diff --git a/scripts/project-import.py b/scripts/project-import.py
index b42a6fd..ecde35c 100644
--- a/scripts/project-import.py
+++ b/scripts/project-import.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -229,7 +233,7 @@ def create_project(p, nbhd, user, options):
                                                 p.admin,
                                                 project_name=p.name.name,
                                                 private_project=p.private)
-        except Exception, e:
+        except Exception as e:
             log.exception('[%s] %s' % (worker_name, str(e)))
             return 0
     else:
@@ -325,7 +329,7 @@ def main(options):
 
     for j in jobs:
         j.join()
-        if j.exitcode <> 0:
+        if j.exitcode != 0:
             return j.exitcode
     return 0
 

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/publicize-neighborhood.py
----------------------------------------------------------------------
diff --git a/scripts/publicize-neighborhood.py b/scripts/publicize-neighborhood.py
index c32d384..1a62aa1 100644
--- a/scripts/publicize-neighborhood.py
+++ b/scripts/publicize-neighborhood.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/recover-user-databases.py
----------------------------------------------------------------------
diff --git a/scripts/recover-user-databases.py b/scripts/recover-user-databases.py
index 5abf6f3..f3d61c6 100644
--- a/scripts/recover-user-databases.py
+++ b/scripts/recover-user-databases.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/rethumb.py
----------------------------------------------------------------------
diff --git a/scripts/rethumb.py b/scripts/rethumb.py
index fa27f32..59ce311 100644
--- a/scripts/rethumb.py
+++ b/scripts/rethumb.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -117,7 +121,7 @@ class RethumbCommand(base.Command):
 
                 # Otherwise, we'll take attachment classes belonging to app's
                 # package
-                ep = iter_entry_points('allura', app.tool_name).next()
+                ep = next(iter_entry_points('allura', app.tool_name))
                 app_package = ep.module_name.split('.', 1)[0]
                 if app_package == 'allura':
                     # Apps in allura known to not define own attachment types

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/scrub-allura-data.py
----------------------------------------------------------------------
diff --git a/scripts/scrub-allura-data.py b/scripts/scrub-allura-data.py
index c0e0828..e569710 100644
--- a/scripts/scrub-allura-data.py
+++ b/scripts/scrub-allura-data.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/setup-scm-server.py
----------------------------------------------------------------------
diff --git a/scripts/setup-scm-server.py b/scripts/setup-scm-server.py
index 050122c..77c3bce 100644
--- a/scripts/setup-scm-server.py
+++ b/scripts/setup-scm-server.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/teamforge-import.py
----------------------------------------------------------------------
diff --git a/scripts/teamforge-import.py b/scripts/teamforge-import.py
index 9f601a0..e06b90d 100644
--- a/scripts/teamforge-import.py
+++ b/scripts/teamforge-import.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -132,7 +136,7 @@ def main():
         project_ids = [p.id for p in projects.dataRows]
 
     if options.list_project_ids:
-        print ' '.join(project_ids)
+        print(' '.join(project_ids))
         return
 
     if not os.path.exists(options.output_dir):

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/test-branches-against-tickets.py
----------------------------------------------------------------------
diff --git a/scripts/test-branches-against-tickets.py b/scripts/test-branches-against-tickets.py
index a742f03..1391251 100755
--- a/scripts/test-branches-against-tickets.py
+++ b/scripts/test-branches-against-tickets.py
@@ -1,3 +1,7 @@
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/trac_export.py
----------------------------------------------------------------------
diff --git a/scripts/trac_export.py b/scripts/trac_export.py
index ac90b17..2a3b7cd 100755
--- a/scripts/trac_export.py
+++ b/scripts/trac_export.py
@@ -17,6 +17,10 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 if __name__ == '__main__':
     from allura.scripts.trac_export import main
     main()

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/wiki-copy.py
----------------------------------------------------------------------
diff --git a/scripts/wiki-copy.py b/scripts/wiki-copy.py
index 0692852..52e274f 100644
--- a/scripts/wiki-copy.py
+++ b/scripts/wiki-copy.py
@@ -17,6 +17,10 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 import os
 import sys
 import urllib
@@ -51,17 +55,17 @@ def main():
             page_data = urllib.urlopen(from_url).read()
             page_json = json.loads(page_data)
             if options.debug:
-                print page_json['text']
+                print(page_json['text'])
                 break
             resp = oauth_client.request(
                 to_url, 'POST', body=urllib.urlencode(dict(text=page_json['text'].encode('utf-8'))))
             if resp[0]['status'] == '200':
-                print "Posted {0} to {1}".format(page_json['title'], to_url)
+                print("Posted {0} to {1}".format(page_json['title'], to_url))
             else:
-                print "Error posting {0} to {1}: {2} (project may not exist)".format(page_json['title'],
to_url, resp[0]['status'])
+                print("Error posting {0} to {1}: {2} (project may not exist)".format(page_json['title'],
to_url, resp[0]['status']))
                 break
         except:
-            print "Error processing " + p
+            print("Error processing " + p)
             raise
 
 
@@ -114,8 +118,8 @@ def make_oauth_client(base_url):
 
     # save oauth token for later use
     cp.write(open(config_file, 'w'))
-    print 'Saving oauth tokens in {} for later re-use'.format(config_file)
-    print
+    print('Saving oauth tokens in {} for later re-use'.format(config_file))
+    print()
 
     access_token = oauth.Token(oauth_token, oauth_token_secret)
     oauth_client = oauth.Client(consumer, access_token)

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/wiki-export.py
----------------------------------------------------------------------
diff --git a/scripts/wiki-export.py b/scripts/wiki-export.py
index 025d3ca..0f8e776 100755
--- a/scripts/wiki-export.py
+++ b/scripts/wiki-export.py
@@ -17,6 +17,10 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 import sys
 from optparse import OptionParser
 

http://git-wip-us.apache.org/repos/asf/allura/blob/3640d5f6/scripts/wiki-post.py
----------------------------------------------------------------------
diff --git a/scripts/wiki-post.py b/scripts/wiki-post.py
index 7e16bb1..1151f81 100755
--- a/scripts/wiki-post.py
+++ b/scripts/wiki-post.py
@@ -17,6 +17,10 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
 import types
 from sys import stdout
 import os
@@ -35,7 +39,7 @@ def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'):
 
     This function was borrowed from Django
     """
-    if strings_only and isinstance(s, (types.NoneType, int)):
+    if strings_only and isinstance(s, (type(None), int)):
         return s
     elif not isinstance(s, basestring):
         try:
@@ -117,7 +121,7 @@ def main():
     url = options.url or config.get('wiki', 'url')
     if pagename_given:
         url = urljoin(url, urllib.quote(pagename))
-    print url
+    print(url)
 
     sign = Signer(token)
     params = [('text', markdown)] if method == 'PUT' else []
@@ -128,7 +132,7 @@ def main():
         else:
             result = urlopen(url + '?' + urlencode(params))
         stdout.write(result.read())
-    except HTTPError, e:
+    except HTTPError as e:
         stdout.write(e.read())
 
 if __name__ == '__main__':


Mime
View raw message