Example #1
0
 def rebuild_database(self):
     """Build our read-only test database from scratch, using data from the ShotgunTestDatabase
     @return a new instance of our type"""
     sqlite_path = self._sqlite_rodb_path()
     if sqlite_path.isfile():
         sqlite_path.remove()
     #end clear previous database
     
     fac = TestShotgunTypeFactory(sample_name=self._sample_name)
     fetcher = ShotgunTestDatabase().records
     
     return type(self)(SQLProxyShotgunConnection.init_database(self._sqlite_rodb_url(), fac, fetcher)._meta)
Example #2
0
    def validate_args(self, args):
        """Inserts 'fetcher' function and 'type_names' list into the args namespace
        @throws InputError if something is wrong with our argument logic
{

    // Word wrapping - follow PEP 8 recommendations
    "rulers": [ 112, 120 ],
    "word_wrap": true,
    "wrap_width": 120,

    // Whitespace - no tabs, trimming, end files with \n
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "ensure_newline_at_eof_on_save": true,
    
}        @return possibly changed args"""
        dsname = "UNSET"
        if args.operation != self.OP_BUILD:
            args.scrambling_disabled = True
        else:
            dsname = getattr(args, "db-name")
            sgtdb = ShotgunTestDatabase(sample_name=dsname)
            if sgtdb.exists():
                raise InputError("Dataset named '%s' did already exist - please choose a different one" % dsname)
            # end
        # end never scramble outside of build mode

        # SETUP SCRAMBLER
        if args.scrambling_disabled:
            scrambler = lambda r, tn: r
        else:
            scrambler = scramble_nested_strings
        # end scrambler

        # FIGURE OUT SOURCE AND SETUP TYPES
        # get rid of list
        args.source = args.source and args.source[0] or list()
        if not args.source:
            # SHOTGUN
            #########
            conn = ProxyShotgunConnection()
            fac = WriterShotgunTypeFactory(TestShotgunTypeFactory.schema_tree(dsname))

            # update schema from DB
            if args.operation == self.OP_BUILD:
                fac.update_schema(conn)
            # end don't wrote in query mode

            args.fetcher = lambda tn: scrambler(conn.find(tn, list(), fac.schema_by_name(tn).keys()), fac.type_names())
            args.type_names = fac.type_names()
        else:
            if is_sqlalchemy_url(args.source):
                # SQLALCHEMY
                ############
                db = SQLProxyShotgunConnection(db_url=args.source)

                # type-names are lower case for sql tables, so we have to transform the value for comparison
                args.fetcher = lambda tn: scrambler(
                    db.find(tn, [], ["id"]), db.type_names(), transformer=lambda v: v.lower()
                )
                args.type_names = db.type_names()
            else:
                # JSONZ
                #######
                fac = TestShotgunTypeFactory(sample_name=args.source)
                db = ShotgunTestDatabase(sample_name=args.source)

                args.fetcher = lambda tn: scrambler(db.records(tn), fac.type_names())
                args.type_names = fac.type_names()
            # end handle value
        # end handle source

        return args