"DisplayInstalledRestriction"]
import errno
+import logging
import os
import re
from portage.util import apply_permissions, ensure_dirs, grabfile, \
- grablines, normalize_path, write_atomic
+ grablines, normalize_path, write_atomic, writemsg_level
from portage.data import portage_gid
+from portage.dep import isvalidatom
from portage.locks import lockfile, unlockfile
from portage.exception import OperationNotPermitted
if not os.path.isfile(filename):
continue
item = NewsItem(filename, itemid)
+ if not item.isValid():
+ continue
if item.isRelevant(profile=self._profile_path,
config=self.config, vardb=self.vdb):
updates.append(item)
self.path = path
self.name = name
self._parsed = False
+ self._valid = True
def isRelevant(self, vardb, config, profile):
"""
return False # No restrictions were met; thus we aren't relevant :(
+ def isValid(self):
+ if not self._parsed:
+ self.parse()
+ return self._valid
+
def parse(self):
lines = open(self.path).readlines()
self.restrictions = []
- for line in lines:
+ invalids = []
+ for i, line in enumerate(lines):
#Optimization to ignore regex matchines on lines that
#will never match
if not line.startswith('D'):
match = regex.match(line)
if match:
self.restrictions.append(restriction(match.groups()[0].strip()))
+ if not self.restrictions[-1].isValid():
+ invalids.append((i + 1, line.rstrip("\n")))
continue
+ if invalids:
+ self._valid = False
+ msg = []
+ msg.append("Invalid news item: %s" % (self.path,))
+ for lineno, line in invalids:
+ msg.append(" line %d: %s" % (lineno, line))
+ writemsg_level("".join("!!! %s\n" % x for x in msg),
+ level=logging.ERROR, noiselevel=-1)
+
self._parsed = True
def __getattr__(self, attr):
are met, then it is displayed
"""
+ def isValid(self):
+ return True
+
def checkRestriction(self, **kwargs):
raise NotImplementedError('Derived class should over-ride this method')
if the user has that item installed.
"""
- def __init__(self, cpv):
- self.cpv = cpv
+ def __init__(self, atom):
+ self.atom = atom
+
+ def isValid(self):
+ return isvalidatom(self.atom)
def checkRestriction(self, **kwargs):
vdb = kwargs['vardb']
- if vdb.match(self.cpv):
+ if vdb.match(self.atom):
return True
return False