Пример #1
0
    def _get_wiki(self):
        alpha = beta = external = False

        release = self.environ.get('tiddlyweb.query',
                                   {}).get('twrelease', [False])[0]
        externalize = self.environ.get('tiddlyweb.query',
                                       {}).get('external', [False])[0]
        download = self.environ.get('tiddlyweb.query',
                                    {}).get('download', [False])[0]

        if release == 'beta':
            beta = True
        if release == 'alpha':
            alpha = True
        if externalize:
            external = True

        # If somebody is downloading, don't allow them to
        # externalize.
        if download:
            external = False

        if alpha or beta or external:
            config_var = build_config_var(alpha, beta, external)
            logging.debug('looking for %s', config_var)
            file = self.environ.get('tiddlyweb.config', {}).get(config_var, '')
            if file:
                logging.debug('using %s as base_tiddlywiki', file)
                return read_utf8_file(file)
        return WikiSerialization._get_wiki(self)
Пример #2
0
    def _get_wiki(self):
        alpha = beta = external = False

        release = self.environ.get('tiddlyweb.query', {}).get(
                'twrelease', [False])[0]
        externalize = self.environ.get('tiddlyweb.query', {}).get(
                'external', [False])[0]
        download = self.environ.get('tiddlyweb.query', {}).get(
                'download', [False])[0]

        if release == 'beta':
            beta = True
        if release == 'alpha':
            alpha = True
        if externalize:
            external = True

        # If somebody is downloading, don't allow them to
        # externalize.
        if download:
            external = False

        if alpha or beta or external:
            config_var = build_config_var(alpha, beta, external)
            logging.debug('looking for %s', config_var)
            file = self.environ.get('tiddlyweb.config', {}).get(config_var, '')
            if file:
                logging.debug('using %s as base_tiddlywiki', file)
                return read_utf8_file(file)
        return WikiSerialization._get_wiki(self)
Пример #3
0
 def _get_wiki(self):
     release = self.environ.get('tiddlyweb.query', {}).get(
             'twrelease', [False])[0]
     if release == 'beta':
         return read_utf8_file(
                 self.environ['tiddlyweb.config']['base_tiddlywiki_beta'])
     else:
         return WikiSerialization._get_wiki(self)  # XXX: inelegant?
Пример #4
0
 def _read_bag_description(self, bag_path):
     """
     Read and return the description of a bag.
     """
     desc_filename = os.path.join(bag_path, 'description')
     if not os.path.exists(desc_filename):
         return ''
     desc = read_utf8_file(desc_filename)
     return desc
Пример #5
0
 def _read_tiddler_file(self, tiddler, tiddler_filename):
     """
     Read a tiddler file from the disk, returning
     a tiddler object.
     """
     tiddler_string = read_utf8_file(tiddler_filename)
     self.serializer.object = tiddler
     self.serializer.from_string(tiddler_string)
     return tiddler
Пример #6
0
 def _read_tiddler_file(self, tiddler, tiddler_filename):
     """
     Read a tiddler file from the disk, returning
     a tiddler object.
     """
     tiddler_string = read_utf8_file(tiddler_filename)
     self.serializer.object = tiddler
     tiddler = self.serializer.from_string(tiddler_string)
     return tiddler
Пример #7
0
 def _read_bag_description(self, bag_path):
     """
     Read and return the description of a bag.
     """
     desc_filename = os.path.join(bag_path, 'description')
     if not os.path.exists(desc_filename):
         return ''
     desc = read_utf8_file(desc_filename)
     return desc
Пример #8
0
 def recipe_get(self, recipe):
     """
     Read a recipe from the store.
     """
     try:
         recipe_path = self._recipe_path(recipe)
         self.serializer.object = recipe
         recipe_string = read_utf8_file(recipe_path)
     except StoreEncodingError, exc:
         raise NoRecipeError(exc)
Пример #9
0
 def recipe_get(self, recipe):
     """
     Read a recipe from the store.
     """
     try:
         recipe_path = self._recipe_path(recipe)
         self.serializer.object = recipe
         recipe_string = read_utf8_file(recipe_path)
     except StoreEncodingError, exc:
         raise NoRecipeError(exc)
Пример #10
0
 def _read_policy(self, bag_path):
     """
     Read and return a bag's policy file,
     return the Policy object.
     """
     policy_filename = os.path.join(bag_path, 'policy')
     policy = read_utf8_file(policy_filename)
     policy_data = simplejson.loads(policy)
     policy = Policy()
     for key, value in policy_data.items():
         policy.__setattr__(key, value)
     return policy
Пример #11
0
 def _read_policy(self, bag_path):
     """
     Read and return a bag's policy file,
     return the Policy object.
     """
     policy_filename = os.path.join(bag_path, 'policy')
     policy = read_utf8_file(policy_filename)
     policy_data = simplejson.loads(policy)
     policy = Policy()
     for key, value in policy_data.items():
         policy.__setattr__(key, value)
     return policy
Пример #12
0
    def recipe_get(self, recipe):
        """
        Fill :py:class:`recipe <tiddlyweb.model.recipe.Recipe>` with
        data in the store.
        """
        try:
            recipe_path = self._recipe_path(recipe)
            self.serializer.object = recipe
            recipe_string = read_utf8_file(recipe_path)
        except StoreEncodingError as exc:
            raise NoRecipeError(exc)
        except IOError as exc:
            raise NoRecipeError('unable to get recipe %s: %s' %
                    (recipe.name, exc))

        return self.serializer.from_string(recipe_string)
Пример #13
0
    def recipe_get(self, recipe):
        """
        Fill :py:class:`recipe <tiddlyweb.model.recipe.Recipe>` with
        data in the store.
        """
        try:
            recipe_path = self._recipe_path(recipe)
            self.serializer.object = recipe
            recipe_string = read_utf8_file(recipe_path)
        except StoreEncodingError as exc:
            raise NoRecipeError(exc)
        except IOError as exc:
            raise NoRecipeError('unable to get recipe %s: %s' %
                    (recipe.name, exc))

        return self.serializer.from_string(recipe_string)
Пример #14
0
 def user_get(self, user):
     """
     Read a user from the store.
     """
     try:
         user_path = self._user_path(user)
         user_info = read_utf8_file(user_path)
         user_data = simplejson.loads(user_info)
         for key, value in user_data.items():
             if key == 'roles':
                 user.roles = set(value)
                 continue
             if key == 'password':
                 key = '_password'
             user.__setattr__(key, value)
         return user
     except IOError, exc:
         raise NoUserError('unable to get user %s: %s' %
                           (user.usersign, exc))
Пример #15
0
 def user_get(self, user):
     """
     Read a user from the store.
     """
     try:
         user_path = self._user_path(user)
         user_info = read_utf8_file(user_path)
         user_data = simplejson.loads(user_info)
         for key, value in user_data.items():
             if key == 'roles':
                 user.roles = set(value)
                 continue
             if key == 'password':
                 key = '_password'
             user.__setattr__(key, value)
         return user
     except IOError, exc:
         raise NoUserError('unable to get user %s: %s' %
                 (user.usersign, exc))
Пример #16
0
    def _get_wiki(self):
        alpha = beta = external = False

        release = self.environ.get('tiddlyweb.query',
                                   {}).get('twrelease', [False])[0]
        externalize = self.environ.get('tiddlyweb.query',
                                       {}).get('external', [False])[0]
        download = self.environ.get('tiddlyweb.query',
                                    {}).get('download', [False])[0]

        if release == 'beta':
            beta = True
        if release == 'alpha':
            alpha = True
        if externalize:
            external = True

        # If somebody is downloading, don't allow them to
        # externalize.
        if download:
            external = False

        wiki = None
        if alpha or beta or external:
            config_var = build_config_var(alpha, beta, external)
            logging.debug('looking for %s', config_var)
            file = self.environ.get('tiddlyweb.config', {}).get(config_var, '')
            if file:
                logging.debug('using %s as base_tiddlywiki', file)
                wiki = read_utf8_file(file)
        if not wiki:
            wiki = WikiSerialization._get_wiki(self)
        tag = "<!--POST-SCRIPT-START-->"
        wiki = wiki.replace(
            tag, '''\
<script type="text/javascript" src="/bags/common/tiddlers/backstage.js"></script>
%s''' % tag)
        return wiki
Пример #17
0
    def _get_wiki(self):
        alpha = beta = external = False

        release = self.environ.get('tiddlyweb.query', {}).get(
                'twrelease', [False])[0]
        externalize = self.environ.get('tiddlyweb.query', {}).get(
                'external', [False])[0]
        download = self.environ.get('tiddlyweb.query', {}).get(
                'download', [False])[0]

        if release == 'beta':
            beta = True
        if release == 'alpha':
            alpha = True
        if externalize:
            external = True

        # If somebody is downloading, don't allow them to
        # externalize.
        if download:
            external = False

        wiki = None
        if alpha or beta or external:
            config_var = build_config_var(alpha, beta, external)
            LOGGER.debug('looking for %s', config_var)
            base_wiki_file = self.environ.get('tiddlyweb.config',
                    {}).get(config_var, '')
            if base_wiki_file:
                LOGGER.debug('using %s as base_tiddlywiki', base_wiki_file)
                wiki = read_utf8_file(base_wiki_file)
        if not wiki:
            wiki = WikiSerialization._get_wiki(self)
        tag = "<!--POST-SCRIPT-START-->"
        if not download:
            wiki = wiki.replace(tag, '<script type="text/javascript" '
                'src="/bags/common/tiddlers/backstage.js"></script> %s' % tag)
        return wiki
Пример #18
0
def _read_file(uri):
	if uri.startswith("file://"): # XXX: hack; use twimport's _get_url_handle!?
		uri = uri[7:]
	return read_utf8_file(uri)