| |
@@ -27,56 +27,11 @@
|
| |
|
| |
log = logging.getLogger('hubs')
|
| |
|
| |
- import fedmsg.config
|
| |
- config = fedmsg.config.load_config()
|
| |
- fmn_url = config['fmn.url']
|
| |
-
|
| |
- bazillion = 1000
|
| |
- paths = fmn.lib.load_rules(root='fmn.rules')
|
| |
-
|
| |
from hubs.widgets.chrome import panel
|
| |
chrome = panel('Live Feed')
|
| |
template = templating.environment.get_template('templates/feed.html')
|
| |
position = 'left'
|
| |
|
| |
-
|
| |
- def apply_markup(match):
|
| |
- markup = match['subtitle']
|
| |
- for username in match['usernames']:
|
| |
- args = (username, '<a href="{url}">@{username}</a>'.format(
|
| |
- url=flask.url_for('hub', name=username),
|
| |
- username=username,
|
| |
- ))
|
| |
- markup = markup.replace(*args)
|
| |
- # TODO -- have to add these to conglomerate first
|
| |
- # match['long_form'] = match['long_form'].replace(*args)
|
| |
-
|
| |
- for package in match['packages']:
|
| |
- args = (package, '<a href="{url}">{package}</a>'.format(
|
| |
- url='https://apps.fedoraproject.org/packages/' + package,
|
| |
- package=package,
|
| |
- ))
|
| |
- markup = markup.replace(*args)
|
| |
- # TODO -- have to add these to conglomerate first
|
| |
- # match['long_form'] = match['long_form'].replace(*args)
|
| |
-
|
| |
- return markup
|
| |
-
|
| |
-
|
| |
- class PythonObjectEncoder(json.JSONEncoder):
|
| |
- ''' A JSON encoder that handles python data structures in encoding'''
|
| |
- def default(self, obj):
|
| |
- if isinstance(obj, (list, dict, str, unicode, int, float, bool,
|
| |
- type(None))):
|
| |
- return json.JSONEncoder.default(self, obj)
|
| |
- if isinstance(obj, set) or isinstance(obj, tuple):
|
| |
- return list(obj)
|
| |
- if isinstance(obj, object):
|
| |
- return obj.__dict__
|
| |
- else:
|
| |
- raise TypeError
|
| |
-
|
| |
-
|
| |
@argument(name="username",
|
| |
default=None,
|
| |
validator=validators.username,
|
| |
@@ -86,122 +41,18 @@
|
| |
validator=validators.integer,
|
| |
help="Max number of feed messages to display")
|
| |
def data(session, widget, username, message_limit):
|
| |
- messages = []
|
| |
- matches = []
|
| |
# Avoid circular import
|
| |
from hubs.app import app
|
| |
feed_url = app.config['SSE_URL'] + username
|
| |
- preference = get_remote_preference(username, 'sse')
|
| |
- if preference:
|
| |
- try:
|
| |
- preference = rehydrate_preference(preference)
|
| |
- except ImportError:
|
| |
- pass
|
| |
-
|
| |
- # The smaller we make this, the faster it is.
|
| |
- delta = datetime.timedelta(days=365)
|
| |
- end = datetime.datetime.utcnow()
|
| |
-
|
| |
- # We currently only support getting the first page.
|
| |
- # The widget framework as currently written doesn't support
|
| |
- # multiple pages yet.
|
| |
- page = 1
|
| |
-
|
| |
- for filter in preference['filters']:
|
| |
- rules = filter['rules']
|
| |
- fmn_hinting = fmn.lib.hinting.gather_hinting(config, rules, paths)
|
| |
- total, pages, rows = datanommer.models.Message.grep(
|
| |
- start=end - delta,
|
| |
- end=end,
|
| |
- rows_per_page=message_limit,
|
| |
- page=page,
|
| |
- order='desc',
|
| |
- **fmn_hinting
|
| |
- )
|
| |
- messages.extend(rows)
|
| |
-
|
| |
- for message in messages:
|
| |
- original = message.__json__()
|
| |
- recipients = fmn.lib.recipients(
|
| |
- [preference], message.__json__(), paths, config)
|
| |
- if recipients:
|
| |
- matches.append(original)
|
| |
- else:
|
| |
- log.warn("You don't have any preferences.")
|
| |
-
|
| |
- # TODO - sort messages and remove duplicates
|
| |
-
|
| |
- # Smash multiple messages into single ones
|
| |
- matches = fedmsg.meta.conglomerate(matches, lexers=True, **config)
|
| |
-
|
| |
- # Apply some html markup to the subtitles for extra fanciness.
|
| |
- for match in matches:
|
| |
- match['markup'] = apply_markup(match)
|
| |
- for idx, constituent in match['msg_ids'].items():
|
| |
- constituent['markup'] = apply_markup(constituent)
|
| |
- if constituent['long_form'] != constituent['subtitle']:
|
| |
- if constituent.get('lexer'):
|
| |
- constituent['long_form'] = pygments.highlight(
|
| |
- constituent['long_form'],
|
| |
- constituent['lexer'],
|
| |
- pygments.formatters.HtmlFormatter(style='monokai'),
|
| |
- )
|
| |
- else:
|
| |
- markup = u"<h5>{long_form}</h5>".format(**constituent)
|
| |
- constituent['long_form'] = markup
|
| |
-
|
| |
- # And tack on a unique identifier for each top level entry.
|
| |
- match['dom_id'] = six.text_type(uuid.uuid4())
|
| |
- matches = json.dumps(matches, cls=PythonObjectEncoder)
|
| |
return dict(
|
| |
- matches=matches,
|
| |
+ matches=[],
|
| |
message_limit=message_limit,
|
| |
feed_url=feed_url
|
| |
)
|
| |
|
| |
-
|
| |
@hint(ubiquitous=True)
|
| |
def should_invalidate(message, session, widget):
|
| |
- username = widget.config['username']
|
| |
- fmn_context = 'sse'
|
| |
- preference = get_remote_preference(username, fmn_context)
|
| |
- if not preference:
|
| |
- return False
|
| |
- preference = rehydrate_preference(preference)
|
| |
- recipients = fmn.lib.recipients([preference], message, paths, config)
|
| |
- return bool(recipients)
|
| |
-
|
| |
-
|
| |
- # TODO -- this cache value needs its own FMN-based invalidator...
|
| |
- @cache.cache_on_arguments()
|
| |
- def get_remote_preference(username, fmn_context):
|
| |
- openid = '%s.id.fedoraproject.org' % username
|
| |
- url = '/'.join([fmn_url, 'api', openid, fmn_context])
|
| |
- log.info("Getting FMN preference from %s" % url)
|
| |
- response = requests.get(url)
|
| |
- if bool(response):
|
| |
- return response.json()
|
| |
- else:
|
| |
- # Some people have no FMN preferences, but when they do get some.. then
|
| |
- # we'll receive the fedmsg event about it and bust this cache value.
|
| |
- return None
|
| |
-
|
| |
-
|
| |
- def rehydrate_preference(preference):
|
| |
- for fltr in preference['filters']:
|
| |
- fltr['rules'] = [munch.Munch(r) for r in fltr['rules']]
|
| |
- for rule in fltr['rules']:
|
| |
- code_path = str(rule.code_path)
|
| |
- rule.fn = fedmsg.utils.load_class(code_path)
|
| |
+ pass
|
| |
|
| |
- return preference
|
| |
|
| |
|
| |
- def make_result(msg, d):
|
| |
- return {
|
| |
- 'icon': fedmsg.meta.msg2icon(d, **config),
|
| |
- 'icon2': fedmsg.meta.msg2secondary_icon(d, **config),
|
| |
- 'subtitle': fedmsg.meta.msg2subtitle(d, **config),
|
| |
- 'link': fedmsg.meta.msg2link(d, **config),
|
| |
- 'time': arrow.get(msg.timestamp).humanize(),
|
| |
- }
|
| |
The feed now uses an external SSE source so this can all be removed.