Commit [70fa32] 42cc_1532 Maximize Restore History

Merge branch 'dev' into t50_hide_project_icon_placeholder

1 2 3 > >> (Page 1 of 3)
removed Allura/allura/tests/test_patience.py
changed Allura/allura/command/__init__.py
changed Allura/allura/config/middleware.py
changed Allura/allura/controllers/repository.py
changed Allura/allura/ext/user_profile/templates/user_index.html
changed Allura/allura/lib/app_globals.py
changed Allura/allura/lib/custom_middleware.py
changed Allura/allura/lib/exceptions.py
changed Allura/allura/lib/helpers.py
changed Allura/allura/model/notification.py
changed Allura/allura/model/project.py
changed Allura/allura/model/repository.py
changed Allura/allura/nf/allura/css/site_style.css
changed Allura/allura/public/nf/css/forge/hilite.css
changed Allura/allura/tasks/repo_tasks.py
changed Allura/allura/templates/repo/file.html
changed Allura/allura/templates/repo/fork.html
changed Allura/allura/tests/functional/test_user_profile.py
changed Allura/allura/tests/model/test_discussion.py
changed Allura/allura/tests/test_commands.py
changed Allura/setup.py
changed Allura/test.ini
changed ForgeBlog/forgeblog/model/__init__.py
copied Allura/allura/lib/patience.py -> Allura/allura/command/rssfeeds.py
Allura/allura/command/__init__.py Diff Switch to side-by-side view
Loading...
Allura/allura/config/middleware.py Diff Switch to side-by-side view
Loading...
Allura/allura/controllers/repository.py Diff Switch to side-by-side view
Loading...
Allura/allura/ext/user_profile/templates/user_index.html Diff Switch to side-by-side view
Loading...
Allura/allura/lib/app_globals.py Diff Switch to side-by-side view
Loading...
Allura/allura/lib/custom_middleware.py Diff Switch to side-by-side view
Loading...
Allura/allura/lib/exceptions.py Diff Switch to side-by-side view
Loading...
Allura/allura/lib/helpers.py Diff Switch to side-by-side view
Loading...
Allura/allura/model/notification.py Diff Switch to side-by-side view
Loading...
Allura/allura/model/project.py Diff Switch to side-by-side view
Loading...
Allura/allura/model/repository.py Diff Switch to side-by-side view
Loading...
Allura/allura/nf/allura/css/site_style.css Diff Switch to side-by-side view
Loading...
Allura/allura/public/nf/css/forge/hilite.css Diff Switch to side-by-side view
Loading...
Allura/allura/tasks/repo_tasks.py Diff Switch to side-by-side view
Loading...
Allura/allura/templates/repo/file.html Diff Switch to side-by-side view
Loading...
Allura/allura/templates/repo/fork.html Diff Switch to side-by-side view
Loading...
Allura/allura/tests/functional/test_user_profile.py Diff Switch to side-by-side view
Loading...
Allura/allura/tests/model/test_discussion.py Diff Switch to side-by-side view
Loading...
Allura/allura/tests/test_commands.py Diff Switch to side-by-side view
Loading...
Allura/setup.py Diff Switch to side-by-side view
Loading...
Allura/test.ini Diff Switch to side-by-side view
Loading...
ForgeBlog/forgeblog/model/__init__.py Diff Switch to side-by-side view
Loading...
Allura/allura/lib/patience.py to Allura/allura/command/rssfeeds.py
--- a/Allura/allura/lib/patience.py
+++ b/Allura/allura/command/rssfeeds.py
@@ -1,205 +1,84 @@
-import sys
-import difflib
-from itertools import chain
+import feedparser
+import html2text
+from bson import ObjectId
 
-class Region(object):
-    '''Simple utility class that keeps track of subsequences'''
-    __slots__=('seq', # sequence
-               'l',   # lower bound
-               'h',   # upper bound
-               )
-    def __init__(self, seq, l=0, h=None):
-        if h is None: h = len(seq)
-        self.seq, self.l, self.h = seq, l, h
+import base
 
-    def __iter__(self):
-        '''Iterates over the subsequence only'''
-        for i in xrange(self.l, self.h):
-            yield self.seq[i]
+from pylons import c
 
-    def __getitem__(self, i):
-        '''works like getitem on the subsequence.  Slices return new
-        regions.'''
-        if isinstance(i, slice):
-            start, stop, step = i.indices(len(self))
-            assert step == 1
-            return self.clone(l=self.l+start,h=self.l+stop)
-        elif i >= 0:
-            return self.seq[i+self.l]
+from allura import model as M
+from forgeblog import model as BM
+from forgeblog import version
+from forgeblog.main import ForgeBlogApp 
+from allura.lib import exceptions
+
+
+class RssFeedsCommand(base.Command):
+    summary = 'Rss feed client'
+    parser = base.Command.standard_parser(verbose=True)
+    parser.add_option('-a', '--appid', dest='appid', default='',
+                      help='application id')
+    parser.add_option('-u', '--username', dest='username', default='root',
+                      help='poster username')
+
+    def command(self):
+        self.basic_setup()
+
+        user = M.User.query.get(username=self.options.username)
+        c.user = user
+
+        self.prepare_feeds()
+        for appid in self.feed_dict:
+            for feed_url in self.feed_dict[appid]:
+                self.process_feed(appid, feed_url)
+
+    def prepare_feeds(self):
+        feed_dict = {}
+        if self.options.appid != '':
+            gl_app = BM.Globals.query.get(app_config_id=ObjectId(self.options.appid))
+            if not gl_app:
+                raise exceptions.NoSuchGlobalsError("The globals %s " \
+                     "could not be found in the database" % self.options.appid)
+            if len(gl_app.external_feeds) > 0:
+                feed_dict[gl_app.app_config_id] = gl_app.external_feeds
         else:
-            return self.seq[i+self.h]
+            for gl_app in BM.Globals.query.find().all():
+                if len(gl_app.external_feeds) > 0:
+                    feed_dict[gl_app.app_config_id] = gl_app.external_feeds
+        self.feed_dict = feed_dict
 
-    def __len__(self):
-        return self.h - self.l
+    def process_feed(self, appid, feed_url):
+        appconf = M.AppConfig.query.get(_id=appid)
+        if not appconf:
+            return
 
-    def __repr__(self):
-        if len(self) > 8:
-            srepr = '[%s,...]' % (','.join(repr(x) for x in self[:5]))
-        else:
-            srepr = repr(list(self))
-        return '<Region (%s,%s): %s>' % (self.l, self.h, srepr)
+        c.project = appconf.project
+        app = ForgeBlogApp(c.project, appconf)
+        c.app = app
 
-    def clone(self, **kw):
-        '''Return a new Region based on this one with the
-        provided kw arguments replaced in the constructor.
-        '''
-        kwargs = dict(seq=self.seq, l=self.l, h=self.h)
-        kwargs.update(kw)
-        return Region(**kwargs)
+        base.log.info("Get feed: %s" % feed_url)
+        f = feedparser.parse(feed_url)
+        if f.bozo:
+            base.log.exception("%s: %s" % (feed_url, f.bozo_exception))
+            return
+        for e in f.entries:
+            title = e.title
+            if 'content' in e:
+                content = u''
+                for ct in e.content:
+                    if ct.type != 'text/html':
+                        content = u"%s<p>%s</p>" % (content, ct.value)
+                    else:
+                        content = content + ct.value
+            else:
+                content = e.summary
 
-def region_diff(ra, rb):
-    '''generator yielding up to two matching blocks, one at the
-    beginning of the region and one at the end.  This function
-    mutates the a and b regions, removing any matched blocks.
-    '''
-    # Yield match at the beginning
-    i = 0
-    while i < len(ra) and i < len(rb) and ra[i] == rb[i]:
-        i += 1
-    if i:
-        yield ra.l, rb.l, i
-        ra.l+=i
-        rb.l+=i
-    # Yield match at the end
-    j = 0
-    while j < len(ra) and j < len(rb) and ra[-j-1]==rb[-j-1]:
-        j+=1
-    if j:
-        yield ra.h-j, rb.h-j, j
-        ra.h-=j
-        rb.h-=j
+            content = u'%s <a href="%s">link</a>' % (content, e.link)
+            content = html2text.html2text(content, e.link)
 
-def unique(a):
-    '''generator yielding unique lines of a sequence and their positions'''
-    count = {}
-    for aa in a:
-        count[aa] = count.get(aa, 0) + 1
-    for i, aa in enumerate(a):
-        if count[aa] == 1: yield aa, i
-
-def common_unique(a, b):
-    '''generator yielding pairs i,j where
-    a[i] == b[j] and a[i] and b[j] are unique within a and b,
-    in increasing j order.'''
-    uq_a = dict(unique(a))
-    for bb, j in unique(b):
-        try:
-            yield uq_a[bb], j
-        except KeyError, ke:
-            continue
-
-def patience(seq):
-    stacks = []
-    for i, j in seq:
-        last_top = None
-        for stack in stacks:
-            top_i, top_j, top_back = stack[-1]
-            if top_i > i:
-                stack.append((i, j, last_top))
-                break
-            last_top = len(stack)-1
-        else:
-            stacks.append([(i, j, last_top)])
-    if not stacks: return []
-    prev = len(stacks[-1])-1
-    seq = []
-    for stack in reversed(stacks):
-        top_i, top_j, top_back = stack[prev]
-        seq.append((top_i, top_j))
-        prev = top_back
-    return reversed(seq)
-
-def match_core(a, b):
-    '''Returns blocks that match between sequences a and b as
-    (index_a, index_b, size)
-    '''
-    ra = Region(a)
-    rb = Region(b)
-    # beginning/end match
-    for block in region_diff(ra,rb): yield block
-    # patience core
-    last_i = last_j = None
-    for i, j in chain(
-        patience(common_unique(ra, rb)),
-        [(ra.h, rb.h)]):
-        if last_i is not None:
-            for block in region_diff(ra[last_i:i], rb[last_j:j]):
-                yield block
-        last_i = i
-        last_j = j
-
-def diff_gen(a, b, opcode_gen):
-    '''Convert a sequence of SequenceMatcher opcodes to
-    unified diff-like output
-    '''
-    def _iter():
-        for op, i1, i2, j1, j2 in opcode_gen:
-            if op == 'equal':
-                yield '  ', Region(a, i1, i2)
-            if op in ('delete', 'replace'):
-                yield '- ', Region(a, i1, i2)
-            if op in ('replace', 'insert'):
-                yield '+ ', Region(b, j1, j2)
-    for prefix, rgn in _iter():
-        for line in rgn:
-            yield prefix, line
-
-def unified_diff(
-    a, b, fromfile='', tofile='', fromfiledate='',
-    tofiledate='', n=3, lineterm='\n'):
-    started = False
-    for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):
-        if not started:
-            yield '--- %s %s%s' % (fromfile, fromfiledate, lineterm)
-            yield '+++ %s %s%s' % (tofile, tofiledate, lineterm)
-            started = True
-        i1, i2, j1, j2 = group[0][1], group[-1][2], group[0][3], group[-1][4]
-        yield "@@ -%d,%d +%d,%d @@%s" % (i1+1, i2-i1, j1+1, j2-j1, lineterm)
-        for tag, i1, i2, j1, j2 in group:
-            if tag == 'equal':
-                for line in a[i1:i2]:
-                    yield ' ' + line
-                continue
-            if tag == 'replace' or tag == 'delete':
-                for line in a[i1:i2]:
-                    yield '-' + line
-            if tag == 'replace' or tag == 'insert':
-                for line in b[j1:j2]:
-                    yield '+' + line
-
-class SequenceMatcher(difflib.SequenceMatcher):
-
-    def get_matching_blocks(self):
-        '''Uses patience diff algorithm to find matching blocks.'''
-        if self.matching_blocks is not None:
-            return self.matching_blocks
-        matching_blocks = list(match_core(self.a, self.b))
-        matching_blocks.append((len(self.a), len(self.b), 0))
-        self.matching_blocks = sorted(matching_blocks)
-        return self.matching_blocks
-
-def test(): # pragma no cover
-    if len(sys.argv) == 3:
-        fn_a = sys.argv[1]
-        fn_b = sys.argv[2]
-    else:
-        fn_a = 'a.c'
-        fn_b = 'b.c'
-    a = open(fn_a).readlines()
-    b = open(fn_b).readlines()
-    # print '====', fn_a
-    # sys.stdout.write(''.join(a))
-    # print '====', fn_b
-    # sys.stdout.write(''.join(b))
-    sm = SequenceMatcher(None, a, b)
-    # print 'Patience opcodes:', sm.get_opcodes()
-    print ''.join(unified_diff(a, b)) #pragma:printok
-    # for prefix, line in diff_gen(a, b, sm.get_opcodes()):
-    #     sys.stdout.write(''.join((prefix, line)))
-    # sm = difflib.SequenceMatcher(None, a, b)
-    # print 'Difflib opcodes:', sm.get_opcodes()
-    # for prefix, line in diff_gen(a, b, sm.get_opcodes()):
-    #     sys.stdout.write(''.join((prefix, line)))
-
-if __name__ == '__main__': # pragma no cover
-    test()
+            post = BM.BlogPost(title=title, text=content, app_config_id=appid,
+                               tool_version={'blog': version.__version__},
+                               state='draft')
+            post.neighborhood_id=c.project.neighborhood_id
+            post.make_slug()
+            post.commit()
1 2 3 > >> (Page 1 of 3)