Beispiel #1
0
    def __init__(self, page):
        """Creates a new instance of AuthorData."""
        self._page = page
        self._id   = page.get('AUTHOR')
        self._data = None

        if self._id is None:
            return

        authId = self._id.strip().replace(' ', '').lower()
        self._data = page.get(['SITE_AUTHORS', authId])
        if self._data is not None:
            self._data = ConfigsDict(self._data)
Beispiel #2
0
    def _processFolderDefinitions(self, path):
        cd        = ConfigsDict(JSON.fromFile(path))
        directory = FileUtils.getDirectoryOf(path)

        for item in os.listdir(directory):
            # Only find content source file types
            if not StringUtils.ends(item, ('.sfml', '.html')):
                continue

            # Skip files that already have a definitions file
            itemPath     = FileUtils.createPath(directory, item, isFile=True)
            itemDefsPath = itemPath.rsplit('.', 1)[0] + '.def'
            if os.path.exists(itemDefsPath):
                continue

            test = SiteProcessUtils.testFileFilter(
                itemPath,
                cd.get(('FOLDER', 'EXTENSION_FILTER')),
                cd.get(('FOLDER', 'NAME_FILTER')))
            if not test:
                continue

            JSON.toFile(itemDefsPath, dict(), pretty=True)
        return True
class ConfigsDataComponent(object):
    """A class for..."""

#===================================================================================================
#                                                                                       C L A S S

    DATA_GET_NULL = NullUtils.NULL('PAGE_DATA_GET')

#___________________________________________________________________________________________________ __init__
    def __init__(self):
        """Creates a new instance of ConfigsDataComponent."""
        self._data     = ConfigsDict()
        self._tempData = ConfigsDict()

#===================================================================================================
#                                                                                   G E T / S E T

#___________________________________________________________________________________________________ GS: dataSources
    @property
    def dataSources(self):
        return [self._tempData, self._data]

#___________________________________________________________________________________________________ GS: localDataSources
    @property
    def localDataSources(self):
        return [self._tempData, self._data]

#===================================================================================================
#                                                                                     P U B L I C

#___________________________________________________________________________________________________ has
    def has(self, key, allowFalse =True, localOnly =False):
        out     = self.get(key, self.DATA_GET_NULL, localOnly=localOnly)
        result  = out != self.DATA_GET_NULL
        if allowFalse:
            return result
        return out and result

#___________________________________________________________________________________________________ get
    def get(self, key, defaultValue =None, localOnly =False, **kwargs):
        if not key:
            return defaultValue
        sources = self.localDataSources if localOnly else self.dataSources
        for source in sources:
            out = source.get(key, defaultValue=self.DATA_GET_NULL)
            if out != self.DATA_GET_NULL:
                return out
        return defaultValue

#___________________________________________________________________________________________________ getMerged
    def getMerged(self, key, defaultValue =None, localOnly =False):
        items = []
        sources = self.localDataSources if localOnly else self.dataSources
        for source in sources:
            if source is None:
                continue

            res = source.get(key, self.DATA_GET_NULL)
            if res != self.DATA_GET_NULL:
                items.append(res)

        if len(items) == 0:
            return defaultValue

        if len(items) == 1:
            return DictUtils.clone(items[0])

        out = items.pop()
        while len(items):
            out = DictUtils.merge(out, items.pop())
        return out

#___________________________________________________________________________________________________ addItem
    def addItem(self, key, value, temp =True):
        """Doc..."""
        key = key.lower()
        if temp:
            self._tempData.add(key, value)
        else:
            self._data.add(key, value)

#___________________________________________________________________________________________________ addItems
    def addItems(self, values, temp =True):
        for name, value in values.iteritems():
            self.addItem(name, value, temp=temp)

#___________________________________________________________________________________________________ removeItem
    def removeItem(self, key, fromData =False, fromTemp =False):
        key = key.lower()
        if not fromData and not fromTemp:
            fromTemp = True

        if fromTemp:
            self._tempData.remove(key)
        if fromData:
            self._data.remove(key)

#===================================================================================================
#                                                                               P R O T E C T E D

#___________________________________________________________________________________________________ _internalMethod
    def _internalMethod(self):
        """Doc..."""
        pass

#===================================================================================================
#                                                                               I N T R I N S I C

#___________________________________________________________________________________________________ __repr__
    def __repr__(self):
        return self.__str__()

#___________________________________________________________________________________________________ __unicode__
    def __unicode__(self):
        return unicode(self.__str__())

#___________________________________________________________________________________________________ __str__
    def __str__(self):
        return '<%s>' % self.__class__.__name__
Beispiel #4
0
class AuthorData(object):
    """A class for..."""

#===================================================================================================
#                                                                                       C L A S S

#___________________________________________________________________________________________________ __init__
    def __init__(self, page):
        """Creates a new instance of AuthorData."""
        self._page = page
        self._id   = page.get('AUTHOR')
        self._data = None

        if self._id is None:
            return

        authId = self._id.strip().replace(' ', '').lower()
        self._data = page.get(['SITE_AUTHORS', authId])
        if self._data is not None:
            self._data = ConfigsDict(self._data)

#===================================================================================================
#                                                                                   G E T / S E T

#___________________________________________________________________________________________________ GS: name
    @property
    def name(self):
        if self._id is None:
            return u'Unknown'

        if self._data is None:
            return self._id

        n = self._data.get('NAME')
        if n is None:
            return self._id
        return n

#___________________________________________________________________________________________________ GS: gplusAuthorUrl
    @property
    def gplusAuthorUrl(self):
        if self._data is None:
            return None

        gplus = self._data.get('GPLUS')
        if gplus is None:
            return None

        # If the google plus profile url exists, parse it to add the rel=author query parameter,
        # which is required to prove authorship, and then return the modified url
        gplus = list(urlparse.urlsplit(gplus))
        if not gplus[0]:
            gplus[0] = u'http'

        query        = urlparse.parse_qs(gplus[3]) if gplus[3] else dict()
        query['rel'] = 'author'
        gplus[3]     = urllib.urlencode(query)

        return urlparse.urlunsplit(gplus)

#===================================================================================================
#                                                                                     P U B L I C

#___________________________________________________________________________________________________ createAuthorLink
    def createAuthorLink(self, linkContents =None):
        if self._id is None:
            return u'Unknown'

        if self._data is None:
            return self._id

        url = self.gplusAuthorUrl
        if not url:
            return self._id

        return u'<a rel="author" href="%s">%s</a>' % (
            url, self.name if linkContents is None else linkContents)

#___________________________________________________________________________________________________ exists
    def exists(self):
        return self._id is not None
 def __init__(self):
     """Creates a new instance of ConfigsDataComponent."""
     self._data     = ConfigsDict()
     self._tempData = ConfigsDict()