incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [2/3] git commit: [#6480] TracExport bug fixes
Date Tue, 06 Aug 2013 19:06:49 GMT
[#6480] TracExport bug fixes

- Pass in options explicitly instead of attempting to read from a
  non-existent global object.
- Improve logging.
- Fix infinite loop bug.

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/ec8deca5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ec8deca5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ec8deca5

Branch: refs/heads/tv/6480
Commit: ec8deca5f787193ac0ffc40a91cb085aeac62f39
Parents: eb38fed
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Tue Aug 6 18:50:46 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue Aug 6 18:50:46 2013 +0000

----------------------------------------------------------------------
 Allura/allura/scripts/trac_export.py | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ec8deca5/Allura/allura/scripts/trac_export.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/trac_export.py b/Allura/allura/scripts/trac_export.py
index aeb14ea..bce548e 100644
--- a/Allura/allura/scripts/trac_export.py
+++ b/Allura/allura/scripts/trac_export.py
@@ -17,7 +17,7 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-
+import logging
 import sys
 import csv
 import urlparse
@@ -35,6 +35,8 @@ from BeautifulSoup import BeautifulSoup, NavigableString
 import dateutil.parser
 import pytz
 
+log = logging.getLogger(__name__)
+
 
 def parse_options():
     optparser = OptionParser(usage=''' %prog <Trac URL>
@@ -66,7 +68,7 @@ class TracExport(object):
         'owner': 'assigned_to',
     }
 
-    def __init__(self, base_url, start_id=1):
+    def __init__(self, base_url, start_id=1, verbose=False, do_attachments=True):
         """start_id - start with at least that ticket number (actual returned
                       ticket may have higher id if we don't have access to exact
                       one).
@@ -78,6 +80,9 @@ class TracExport(object):
         self.ticket_map = {}
         self.start_id = start_id
         self.page = (start_id - 1) / self.PAGE_SIZE + 1
+        self.verbose = verbose
+        self.do_attachments = do_attachments
+        self.exhausted = False
         self.ticket_queue = self.next_ticket_ids()
 
     def remap_fields(self, dict):
@@ -98,9 +103,9 @@ class TracExport(object):
         glue = '&' if '?' in suburl else '?'
         return  url + glue + 'format=' + type
 
-    @staticmethod
-    def log_url(url):
-        if options.verbose:
+    def log_url(self, url):
+        log.info(url)
+        if self.verbose:
             print >>sys.stderr, url
 
     @classmethod
@@ -198,7 +203,7 @@ class TracExport(object):
         '''
         t = self.parse_ticket_body(id)
         t['comments'] = self.parse_ticket_comments(id)
-        if options.do_attachments:
+        if self.do_attachments:
             atts = self.parse_ticket_attachments(id)
             if atts:
                 t['attachments'] = atts
@@ -230,6 +235,9 @@ class TracExport(object):
                 res.append((id, extra))
         self.page += 1
 
+        if len(res) < self.PAGE_SIZE:
+            self.exhausted = True
+
         return res
 
     def __iter__(self):
@@ -238,7 +246,7 @@ class TracExport(object):
     def next(self):
         while True:
             # queue empty, try to fetch more
-            if len(self.ticket_queue) == 0:
+            if len(self.ticket_queue) == 0 and not self.exhausted:
                 self.ticket_queue = self.next_ticket_ids()
             # there aren't any more, we're really done
             if len(self.ticket_queue) == 0:
@@ -258,7 +266,8 @@ class DateJSONEncoder(json.JSONEncoder):
 
 def main():
     options, args = parse_options()
-    ex = TracExport(args[0], start_id=options.start_id)
+    ex = TracExport(args[0], start_id=options.start_id,
+            verbose=options.verbose, do_attachments=options.do_attachments)
     # Implement iterator sequence limiting using islice()
     doc = [t for t in islice(ex, options.limit)]
 


Mime
View raw message