Esempio n. 1
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