コード例 #1
0
ファイル: db_type.py プロジェクト: reolyze/Mogu
 def _import(self, db, data, flags):
     # clrln()
     # sys.stdout.write("writing node %s" % self.node)
     if self.node_type is str:
         f = bytemaps.StrStorage
         method = todb.import_string
     elif self.node_type is list:
         f = bytemaps.ListStorage
         method = todb.import_list
     elif self.node_type is dict:
         f = bytemaps.DictStorage
         for key in data:
             data[key] = self.wrap(key, data[key])
         method = todb.import_dict
     elif self.node_type is Set:
         f = bytemaps.ListStorage
         method = todb.import_set
     else:
         raise NodeTypeError(self)
     merge = bytemaps.is_set(flags, f.is_merge)
     assume_yes = bytemaps.is_set(flags, f.assume_yes)
     node_exists = self.exists(db)
     verbose = bytemaps.is_set(flags, f.verbose)
     if not merge and node_exists:
         if assume_yes and not verbose:
             c = True
         else:
             c = confirm("%s already exists. It will be DELETED before writing new data." % self.node, assume_yes)
         if not c:
             return
         else:
             db.delete(self.node)
     method(db, self.node, data, flags)
コード例 #2
0
ファイル: mimport.py プロジェクト: reolyze/Mogu
def import_dict (db, node, data, flags):
    """
    @param db the redis database connection
    @param prefix everything up to the specific dictionary being
        imported (widgets.numero_uno.events)
    @name The specific name of this particular dictionary
        (1) -> widgets.numero_uno.events.1
    @data the dictionary
    @flags a bit-masked integral type that will determine certain 
        specifics (merge/replace, etc.)
    There is no return type for this function.
    """
    testing = b.is_set(flags, b.DictStorage.is_test)
    if testing:
        b.set_bit(flags, b.DictStorage.assume_yes)
    for entry in data:
        entry_exists = db.hexists(node, entry)
        if entry_exists and not b.is_set(flags, b.DictStorage.is_merge):
            __continue = confirm(
                    "%s:%s already exists in your node and will be overwritten." % (node, entry),
                    (b.is_set(flags, b.DictStorage.assume_yes)))
            if not __continue:
                continue
            data[entry] = clean_string(data[entry])
        if not testing:
            db.hset(node, entry, data[entry])
コード例 #3
0
ファイル: importdb.py プロジェクト: reolyze/Mogu
def flush(args, db):
    if args.flushdb:
        message = warn(
                "WARNING: This will overwrite all data in datbase number %d  of your Redis instance at %s:%d" % (
                    args.redis_db, args.redis_host, args.redis_port))
        if confirm(message,args.yes):
            db.flushdb()
        else:            
            print("No problem. If you're nervous, you can always remove the --redis-flush argument from your command")
            sys.exit()
コード例 #4
0
ファイル: init.py プロジェクト: tomthorogood/Mogu
def init(args,db):
    # First, check to make sure there isn't a Mogu application
    # already configured in the database
    if len(db.keys("*")) is not 0:
        if not confirm(
                warn("It appears that there is already information in the currently selected database. Initializing a project here may overwrite data already present. It is recommended that you select a different database (with --redis-select) instead."),
                    args.yes):
            print(ok("No changes were made."))
            sys.exit()
    db.hset("widgets.wrapper","type","{container}")
    print(ok("Mogu project has been initialized! Go Mogu!"))
コード例 #5
0
ファイル: mimport.py プロジェクト: reolyze/Mogu
def import_string(db, node, data, flags):
    data = clean_string(data)
    testing = b.is_set(flags, b.StrStorage.is_test) 
    merge = b.is_set(flags, b.StrStorage.is_merge) #unimplemented
    yes = b.is_set(flags, b.StrStorage.assume_yes)

    entry_exists = db.exists(node)
    if entry_exists and not merge:
        __continue = confirm(
                "%s already exists in the database and will be overwritten." %node,
                (b.is_set(flags, b.DictStorage.assume_yes)))
        if not __continue:
            return
    if not testing:
        db.set(node, data)
コード例 #6
0
ファイル: importdb.py プロジェクト: reolyze/Mogu
def m_import (args, db):
    if not args.filename:
        message = "You have told me that you want to import a file, but have not given me\
                a file to import."
        raise MissingArgumentError("--filename", message)

    if args.flushdb:
        message = warn(
                "WARNING: This will overwite ALL data in database %d \
                        of the Redis instance at %s:%d" % (
                    args.redis_db, args.redis_host, args.redis_port))
        if not confirm(message, args.yes):
            print( ok("No changes were made."))
            sys.exit()
    
    package = importdb.evaluate_file(args.filename)
    
    add_widget_set (db, package, args.testing, args.flushdb, args.merge)
    add_global_events (db, package.global_events, arge.testing, args.merge)
    add_meta_values (db, package.meta, args.testing, args.merge)
    add_perspectives(db, package.perspectives, args.testing, args.merge)
    add_policies(db, package.policies, args.testing)