示例#1
0
文件: __init__.py 项目: FND/tiddlyweb
 def addrole(args):
     """Add a role to an existing user. <username> [role] [role] [role]"""
     try:
         username = args.pop(0)
         roles = args[0:]
     except (IndexError, ValueError), exc:
         usage('you must provide a user and at least one '
             'role: %s' % exc)
示例#2
0
def imwiki(args):
    """Import a Tiddlywiki html file into a bag: <filename> <bag>"""
    store = _store()

    try:
        filename, bag_name = args[0:2]
        import_wiki_file(store, filename, bag_name)
    except IndexError, exc:
        print >> sys.stderr, "index error: %s" % exc
        usage()
示例#3
0
 def server(args):
     """Start the server using config settings. Provide <host name or IP number> <port> to override."""
     hostname = port = ''
     try:
         hostname, port = args[0:2]
     except (IndexError, ValueError), exc:
         if 0 < len(args) < 2:
             usage('you must include both a hostname or ip '
                   'number and a port if using arguments: %s' % exc)
         else:
             pass
示例#4
0
文件: __init__.py 项目: FND/tiddlyweb
 def server(args):
     """Start the server using config settings. Provide <host name or IP number> <port> to override."""
     hostname = port = ''
     try:
         hostname, port = args[0:2]
     except(IndexError, ValueError), exc:
         if 0 < len(args) < 2:
             usage('you must include both a hostname or ip '
                 'number and a port if using arguments: %s' % exc)
         else:
             pass
示例#5
0
def _parse_args(args, required, optional):
    if len(args) == optional:
        print args
        return args
    elif len(args) == required:
        args.extend([None for i in range(optional-required)])
        print args
        return args
    else:
        print >> sys.stderr, '%s args required, %s with options' % (required, optional)
        usage()
示例#6
0
文件: __init__.py 项目: FND/tiddlyweb
    def recipe(args):
        """Create or update a recipe with the recipe text on stdin: <recipe>"""
        try:
            recipe_name = args[0]
        except IndexError:
            usage('you must include a recipe name')

        from tiddlyweb.model.recipe import Recipe

        new_recipe = Recipe(recipe_name)

        content = sys.stdin.read()
        _put(new_recipe, unicode(content, 'UTF-8'), 'text')
示例#7
0
文件: __init__.py 项目: FND/tiddlyweb
    def tiddler(args):
        """Import a single tiddler into an existing bag from stdin: <bag> <tiddler>"""
        try:
            bag_name, tiddler_name = args[0:3]
        except (IndexError, ValueError):
            usage('you must include a tiddler and bag name')

        from tiddlyweb.model.tiddler import Tiddler

        new_tiddler = Tiddler(tiddler_name)
        new_tiddler.bag = bag_name

        content = sys.stdin.read()
        _put(new_tiddler, unicode(content, 'UTF-8'), 'text')
示例#8
0
文件: __init__.py 项目: FND/tiddlyweb
    def bag(args):
        """Create or update a bag with the json text on stdin: <bag>"""
        try:
            bag_name = args[0]
        except IndexError:
            usage('you must include a bag name')

        from tiddlyweb.model.bag import Bag

        new_bag = Bag(bag_name)

        content = sys.stdin.read()
        if not len(content):
            content = '{"policy":{}}'
        _put(new_bag, unicode(content, 'UTF-8'), 'json')
示例#9
0
 def manifest(args):
     """Make a new manifesto. <manifesto name> <dictionary prefix>"""
     store = get_store(config)
     try:
         recipe_name = args[0]
         bag_name = args[1] + '-dictionary'
     except IndexError:
         usage("manifesto name and dictionary prefix required")
     # add policy info later
     ensure_bag(recipe_name, store)
     ensure_bag(bag_name, store)
     recipe = Recipe(recipe_name)
     recipe.set_recipe([
         (bag_name, ''),
         (recipe_name, '')])
     recipe = store.put(recipe)
示例#10
0
文件: __init__.py 项目: FND/tiddlyweb
 def ltiddlers(args):
     """List all the tiddlers on the system. [<bag> <bag> <bag>] to limit."""
     from tiddlyweb.model.bag import Bag
     store = _store()
     bags = [Bag(name) for name in args]
     if not bags:
         bags = store.list_bags()
     try:
         for listed_bag in bags:
             listed_bag = store.get(listed_bag)
             owner = listed_bag.policy.owner or ''
             print listed_bag.name.encode('utf-8'), owner.encode('utf-8')
             tiddlers = store.list_bag_tiddlers(listed_bag)
             for listed_tiddler in tiddlers:
                 print '\t%s' % listed_tiddler.title.encode('utf-8')
     except NoBagError, exc:
         usage('unable to inspect bag %s: %s' % (listed_bag.name, exc))
示例#11
0
    def userpass(args):
        """Change the password of an existing user. <username> <password>"""
        try:
            username, password = args[0:2]
        except (IndexError, ValueError) as exc:
            usage('you must provide both a user and a password')

        try:
            store = _store()
            user = User(username)
            user = store.get(user)
            user.set_password(password)
            store.put(user)
        except Exception as exc:
            usage('unable to set password for user: %s' % exc)

        return True
示例#12
0
def addplugin(args):
    """Add the named plugin."""
    if args:
        for plugin_name in args:
            if _is_remote(plugin_name):
                short_name = _plugin_short_name(plugin_name)
            else:
                short_name = plugin_name
            try:
                __import__(short_name)
                print ('%s already installed, attempting to activate'
                        % short_name)
            except ImportError:
                print ('%s not yet installed, attempting to install'
                        % plugin_name)
                _install(plugin_name)
            except Exception, exc:
                usage('%s is present but errored out: %s' % (plugin_name, exc))
            _activate(short_name)
示例#13
0
    def addrole(args):
        """Add a role to an existing user. <username> [role] [role] [role]"""
        try:
            username = args.pop(0)
            roles = args[0:]
        except (IndexError, ValueError) as exc:
            usage('you must provide a user and at least one '
                'role: %s' % exc)

        try:
            store = _store()
            user = User(username)
            user = store.get(user)
            for role in roles:
                user.add_role(role)
            store.put(user)
        except Exception as exc:
            usage('unable to add role to user: %s' % exc)

        return True
示例#14
0
    def server(args):
        """Start the server using config settings. Provide <host name or IP number> <port> to override."""
        hostname = port = ''
        try:
            hostname, port = args[0:2]
        except(IndexError, ValueError) as exc:
            if 0 < len(args) < 2:
                usage('you must include both a hostname or ip '
                    'number and a port if using arguments: %s' % exc)
            else:
                pass

        if hostname and port:
            config['server_host'] = {
                    'scheme': 'http',
                    'host': str(hostname),
                    'port': str(port),
            }
        server_module = config.get('wsgi_server', 'tiddlyweb.web.serve')
        imported_module = __import__(server_module, {}, {}, ['start_server'])
        imported_module.start_server(config)
示例#15
0
文件: __init__.py 项目: FND/tiddlyweb
    def adduser(args):
        """Add or update a user to the database: <username> <password> [[role] [role] ...]"""
        try:
            username, password = args[0:2]
        except (IndexError, ValueError):
            usage('you must include at least a username and password')

        try:
            roles = args[2:]
        except IndexError:
            roles = []

        # this will raise an except to be caught by the handler
        store = _store()
        user = User(username)
        user.set_password(password)
        for role in roles:
            user.add_role(role)
        store.put(user)

        return True
示例#16
0
def _reify_entities(source_bag, source_tiddler, target_bag=None, target_tiddler=None,
        source_exist=True):
    try:
        source_bag = _get_bag(source_bag)
        source_tiddler = _get_tiddler(source_bag.name, source_tiddler)
    except NoBagError:
        print >> sys.stderr, 'Bag %s does not exist. It must.' % source_bag
        usage()
    except NoTiddlerError:
        if source_exist:
            print >> sys.stderr, 'Tiddler %s does not exist. It must.' % source_tiddler
            usage()
        else:
            return Tiddler(source_tiddler, source_bag.name)

    if target_bag:
        try:
            target_bag = _get_bag(target_bag)
            if target_tiddler:
                try:
                    target_tiddler = _get_tiddler(target_bag.name, target_tiddler)
                except NoTiddlerError:
                    target_tiddler = Tiddler(target_tiddler, target_bag.name)
            else:
                target_tiddler = Tiddler(source_tiddler.title, target_bag.name)
        except NoBagError:
            print >> sys.stderr, 'Bag %s does not exist. It must.' % target_bag
            usage()

        return source_tiddler, target_tiddler
    else:
        return source_tiddler
示例#17
0
    def csvimport(args):
        """Import a csv file as tiddlers. <bagname>"""
        store = get_store(config)
        try:
            bag_name = args[0]
            store.get(Bag(bag_name))
        except IndexError:
            usage('you must include a bag name')
        except StoreError:
            usage('bag %s does not exist' % bag_name)
        tiddler_reader = DictReader(sys.stdin)
        for tiddler_data in tiddler_reader:
            try:
                title = tiddler_data['title']
                del tiddler_data['title']
            except KeyError:
                title = str(uuid4())
            tiddler = Tiddler(title, bag_name)

            for key, value in tiddler_data.iteritems():
                if key is None:
                    continue
                if key == 'tags':
                    value = string_to_tags_list(value)
                if key in CORE_TIDDLER_ATTRS:
                    setattr(tiddler, key, value)
                else:
                    tiddler.fields[key] = value
                if binary_tiddler(tiddler):
                    try:
                        tiddler.text = b64decode(tiddler.text)
                    except TypeError, exc:
                        raise TiddlerFormatError(
                                'unable to decode b64 tiddler: %s: %s'
                                % (tiddler.title, exc))
            store.put(tiddler)
示例#18
0
def _activate(plugin_name):
    print 'activating %s' % plugin_name
    plugins = get_plugins(twanager_config)
    if plugin_name in plugins:
        usage('%s already activated' % plugin_name)
    else:
        try:
            plugin = __import__(plugin_name)
            getattr(plugin, 'init')
        except ImportError, exc:
            usage('%s will not import, not activating: %s' % (plugin_name, exc))
        except AttributeError, exc:
            usage('%s has no init, not a plugin, not activating' % plugin_name)
示例#19
0
    @make_command()
    def userpass(args):
        """Change the password of an existing user. <username> <password>"""
        try:
            username, password = args[0:2]
        except (IndexError, ValueError), exc:
            usage('you must provide both a user and a password')

        try:
            store = _store()
            user = User(username)
            user = store.get(user)
            user.set_password(password)
            store.put(user)
        except Exception, exc:
            usage('unable to set password for user: %s' % exc)

        return True

    @make_command()
    def addrole(args):
        """Add a role to an existing user. <username> [role] [role] [role]"""
        try:
            username = args.pop(0)
            roles = args[0:]
        except (IndexError, ValueError), exc:
            usage('you must provide a user and at least one ' 'role: %s' % exc)

        try:
            store = _store()
            user = User(username)
示例#20
0
 def userpass(args):
     """Change the password of an existing user. <username> <password>"""
     try:
         username, password = args[0:2]
     except (IndexError, ValueError), exc:
         usage('you must provide both a user and a password')
示例#21
0
文件: __init__.py 项目: FND/tiddlyweb
 def userpass(args):
     """Change the password of an existing user. <username> <password>"""
     try:
         username, password = args[0:2]
     except (IndexError, ValueError), exc:
         usage('you must provide both a user and a password')
示例#22
0
from tiddlyweb.instancer import instance, _make_bag, _make_recipe

@make_command()
def imwiki(args):
    """Import a Tiddlywiki html file into a bag: <filename> <bag>"""
    store = _store()

    try:
        filename, bag_name = args[0:2]
        import_wiki_file(store, filename, bag_name)
    except IndexError, exc:
        print >> sys.stderr, "index error: %s" % exc
        usage()
    except ValueError, exc:
        print >> sys.stderr, "value error: %s" % exc
        usage()


@make_command()
def twinstance(args):
    """Create a tiddlyweb instance with default plugins in the named directory: <dir>"""
    instance(args)
    _make_bag('common')
    _make_recipe('default', bag_names + ['common'])


def _store():
    """Get our Store from config."""
    return Store(config['server_store'][0],
            environ={'tiddlyweb.config': config})
示例#23
0
                short_name = _plugin_short_name(plugin_name)
            else:
                short_name = plugin_name
            try:
                __import__(short_name)
                print ('%s already installed, attempting to activate'
                        % short_name)
            except ImportError:
                print ('%s not yet installed, attempting to install'
                        % plugin_name)
                _install(plugin_name)
            except Exception, exc:
                usage('%s is present but errored out: %s' % (plugin_name, exc))
            _activate(short_name)
    else:
        usage('you need to name at least one plugin')


def _plugin_short_name(plugin_name):
    short_name = os.path.basename(urlparse.urlparse(plugin_name)[2])
    short_name = short_name[0:short_name.rindex('.py')]
    return short_name


def _is_remote(plugin_name):
    return (plugin_name.endswith('.py') and
            (plugin_name.startswith('http:') or
            plugin_name.startswith('https:')))


def _install(plugin_name):
示例#24
0
def _install_package(plugin_name):
    usage('THIS FUNCTIONALITY IS NOT YET IMPLEMENTED')
示例#25
0
文件: __init__.py 项目: FND/tiddlyweb
    @make_command()
    def userpass(args):
        """Change the password of an existing user. <username> <password>"""
        try:
            username, password = args[0:2]
        except (IndexError, ValueError), exc:
            usage('you must provide both a user and a password')

        try:
            store = _store()
            user = User(username)
            user = store.get(user)
            user.set_password(password)
            store.put(user)
        except Exception, exc:
            usage('unable to set password for user: %s' % exc)

        return True

    @make_command()
    def addrole(args):
        """Add a role to an existing user. <username> [role] [role] [role]"""
        try:
            username = args.pop(0)
            roles = args[0:]
        except (IndexError, ValueError), exc:
            usage('you must provide a user and at least one '
                'role: %s' % exc)

        try:
            store = _store()