コード例 #1
0
ファイル: mount.py プロジェクト: hstanev/fuselage
 def get_op(me, op_klas):
     f = None
     if issubclass(op_klas, op.Op1):
         f = me.Func1(op_klas, me)
     elif issubclass(op_klas, op.Op2):
         f = me.Func2(op_klas, me)
     else:
         log("get_op unknown op_klas", op_klas)
         assert 0
     # log( 'get_op', op_klas.__name__, f.__class__.__name__)
     return f
コード例 #2
0
ファイル: mount.py プロジェクト: hstanev/fuselage
 def get_op(me, op_klas):
     f = None
     if issubclass(op_klas, op.Op1):
         f = me.Func1(op_klas, me)
     elif issubclass(op_klas, op.Op2):
         f = me.Func2(op_klas, me)
     else:
         log('get_op unknown op_klas', op_klas)
         assert 0
     #log( 'get_op', op_klas.__name__, f.__class__.__name__)
     return f
コード例 #3
0
ファイル: hardlink.py プロジェクト: hstanev/fuselage
 def _external_dispatch(me, ext):
     path2 = os.path.sep + me.q2.path_in_aspect
     op_klas = me.q2.op_klas
     if issubclass(op_klas, Operations.symlink):
         Hardlink.getattr4symlink = True
         op_klas = Operations.link
     return me.context.get_op(op_klas)(ext.path, path2)
コード例 #4
0
ファイル: mount.py プロジェクト: hstanev/fuselage
 def __call__(me, path1, path2):
     if not isinstance(path1, unicode):
         path1 = unicode(path1, "utf-8")
     if not isinstance(path2, unicode):
         path2 = unicode(path2, "utf-8")
     ctx = me.ctx
     op_klas = me.op_klas
     log("======== ", op_klas.__name__, path1, path2)
     d1 = me._from_path(path1)
     d2 = me._from_path(path2)
     if d1.malformed or d2.malformed:
         return -op_klas.malformed
     fname = d1.typ + "_" + d2.typ
     op_klas1, func1 = me._get_op_func(d1.asp, op_klas, fname)
     op_klas2, func2 = me._get_op_func(d2.asp, op_klas, fname)
     if me.use_coercion:
         func = func1 or func2
     else:
         i1 = len(ctx.aspects) if d1.asp is Aspect else ctx.aspects.index(d1.asp)
         if i1 > ctx.aspects.index(d2.asp):
             op_klas, func = op_klas2, func2
         else:
             op_klas, func = op_klas1, func1
     if not func:
         log("func:", fname + " not implemented")
         return -op_klas.not_implemented
     if me.use_coercion:
         op_klas = op_klas1 if func1 else op_klas2
         if issubclass(op_klas2, op_klas1):  # mimic python rules for coercion
             func = func2
             op_klas = op_klas2
     return me._exec(func, op_klas(ctx, d1.q, d2.q), d1.obj, d2.obj)
コード例 #5
0
ファイル: hardlink.py プロジェクト: hstanev/fuselage
 def _external_dispatch(me, ext):
     path2 = os.path.sep + me.q2.path_in_aspect
     op_klas = me.q2.op_klas
     if issubclass(op_klas, Operations.symlink):
         Hardlink.getattr4symlink = True
         op_klas = Operations.link
     return me.context.get_op(op_klas)(ext.path, path2)
コード例 #6
0
ファイル: mount.py プロジェクト: hstanev/fuselage
 def __call__(me, path1, path2):
     if not isinstance(path1, unicode): path1 = unicode(path1, 'utf-8')
     if not isinstance(path2, unicode): path2 = unicode(path2, 'utf-8')
     ctx = me.ctx
     op_klas = me.op_klas
     log('======== ', op_klas.__name__, path1, path2)
     d1 = me._from_path(path1)
     d2 = me._from_path(path2)
     if d1.malformed or d2.malformed:
         return -op_klas.malformed
     fname = d1.typ + '_' + d2.typ
     op_klas1, func1 = me._get_op_func(d1.asp, op_klas, fname)
     op_klas2, func2 = me._get_op_func(d2.asp, op_klas, fname)
     if me.use_coercion:
         func = func1 or func2
     else:
         i1 = len(
             ctx.aspects) if d1.asp is Aspect else ctx.aspects.index(
                 d1.asp)
         if i1 > ctx.aspects.index(d2.asp):
             op_klas, func = op_klas2, func2
         else:
             op_klas, func = op_klas1, func1
     if not func:
         log('func:', fname + ' not implemented')
         return -op_klas.not_implemented
     if me.use_coercion:
         op_klas = op_klas1 if func1 else op_klas2
         if issubclass(op_klas2,
                       op_klas1):  # mimic python rules for coercion
             func = func2
             op_klas = op_klas2
     return me._exec(func, op_klas(ctx, d1.q, d2.q), d1.obj, d2.obj)
コード例 #7
0
ファイル: aspect.py プロジェクト: hstanev/fuselage
 def check4alias( me):
     if not issubclass( me.op_klas, (Operations.getattr, Operations.readlink)):
         Aspect.aliases.clear()
         me.alias_path_in_use = None
         return None
     if me.full_path != Aspect.alias_path_in_use:
         Aspect.aliases.pop( Aspect.alias_path_in_use, None)
         Aspect.alias_path_in_use = me.full_path
     return Aspect.aliases.get( me.full_path, None)
コード例 #8
0
ファイル: aspect.py プロジェクト: hstanev/fuselage
 def _init( me, aspects):
     me._rexp = '^/'+me.dir_name()+'$'
     for op_name, op_klas in vars(me).iteritems():
         op_klas = getattr( me, op_name, op_klas)
         if issubclass( op_klas, (Op1,Op2)):
             class new_op_klas( op_klas):
                 aspects = aspects
             new_op_klas.__name__ = op_klas.__name__
             setattr( me, op_name, new_op_klas)
コード例 #9
0
ファイル: aspect.py プロジェクト: hstanev/fuselage
    def __init__( cls, name, bases, dct):
        if not cls.operandType or not cls.resultType:
            return
        operand = cls.operandType.__name__.lower()
        result = cls.resultType.__name__.lower()
        for op_name, op_klas in vars(QAspect).iteritems():
            op_klas = getattr( cls, op_name, op_klas)
            if issubclass( op_klas, (Op1,Op2)):
                class new_op_klas( op_klas): pass
                new_op_klas.__name__ = op_klas.__name__
                cls.rename_meth( op_klas, new_op_klas, 'operand', operand)
                cls.rename_meth( op_klas, new_op_klas, 'result', result)
                setattr( cls, op_name, new_op_klas)

        parser = cls.Parser
        parser.result = property( lambda me: getattr( me, result), lambda me, val: setattr( me, result, val))
        parser.operand = property( lambda me: getattr( me, operand), lambda me, val: setattr( me, operand, val))
コード例 #10
0
ファイル: hardlink.py プロジェクト: hstanev/fuselage
        stat_res = me._dispatch()
        #if os.path.split( me.q.path_in_aspect)[0] and isinstance( stat_res, stat_result):
        if Hardlink.getattr4symlink and isinstance(stat_res, stat_result):
            all = list(stat_res)
            log('original:', all)
            all[0] = all[0] | S_IFLNK
            log('new:', all)
            stat_res = stat_result(all)
        Hardlink.getattr4symlink = False
        return stat_res


Hardlink.getattr = getattr_

for op_name, op_klas in vars(Operations).iteritems():
    if not issubclass(op_klas, (Op1, Op2)): continue
    klas = getattr(Hardlink, op_name, op_klas)
    A = None
    if issubclass(op_klas, Op1) and not getattr(klas, 'dispatch', None):

        class A(klas):
            dispatch = Hardlink._dispatch.im_func

    if issubclass(op_klas,
                  Op2) and not getattr(klas, 'external_dispatch', None):

        class A(klas):
            external_dispatch = Hardlink._external_dispatch.im_func

    if A:
        setattr(Hardlink, op_name, A)
コード例 #11
0
ファイル: aspect.py プロジェクト: hstanev/fuselage
        def _parse( me):
            qgram = me.context.query_grammar
            me.tree = []
            me.complete = False
            tokens = [ t for t in me.path_in_aspect.split( os.path.sep) if t ]
            log('tokens', tokens)
            ands = []
            me.last_token = None
            me.pending_logic = None
            have_negative = False
            for i, token in enumerate(tokens):
                me.last_token = token
                if token == qgram.eval_:
                    if ands:
                        me.tree.append( ands)
                        me.complete = True
                        opath_tokens = tokens[ i+1:] # skip '='
                        if opath_tokens:
                            path_tail = os.path.join( *opath_tokens)
                            me.setup_result( path_tail)
                            if not me.result.id:
                                me.error = me.unknownResult( path_tail)
                    else:
                        me.error = me.unknownOperand( token)
                    break
                elif token == qgram.or_:
                    if not ands or have_negative or me.pending_logic:
                        me.error = me.unknownOperand( token)
                        break
                    me.tree.append( ands)
                    ands = []
                    me.pending_logic = token
                elif token == qgram.and_:
                    if have_negative or me.pending_logic:
                        me.error = me.unknownOperand( token)
                        break
                    me.pending_logic = token
                elif token == qgram.not_:
                    if have_negative:
                        me.error = me.unknownOperand( token)
                        break
                    have_negative = True
                    me.pending_logic = token
                #elif token == qgram.root:
                #    log('ERROR: unexpected symbol for root')
                #    assert 0
                else:
                    logic = me.pending_logic
                    if logic:
                        me.pending_logic = None
                    op = me.token2operand( token)
                    if logic == qgram.not_:
                        op = QAspect.Negative( op)
                    me.operand = op
                    if not op.id:
                        if logic:
                            me.error = me.unknownOperand( token)
                            break
                        if (ands
                                and issubclass( me.op_klas, (Op2, Operations.getattr))
                                and i == len(tokens)-1):
                            me.tree.append( ands)
                            me.setup_result( token)
                            if not me.result.id:
                                me.error = me.unknownResult( token)
                        else:
                            me.error = me.unknownOperand( token) # XXX is it needed?
                        break

                    positive = getattr( op, 'operand', op) # if negative
                    if ands and positive in ands:
                        me.error = me.unknownOperand( token)
                        break
                    if logic in (qgram.not_, qgram.or_) and [ positive ] in me.tree:
                        me.error = me.unknownOperand( token)
                        break
                    ands.append( op)
            else:
                if ands:
                    me.tree.append( ands)

            if me.result.id or getattr( me.error, 'expected_type', None) == me.result.__class__:
                return me.result
            if me.last_token and me.last_token not in qgram.values():# and me.tree:
                return me.operand
            # path ends with something from query_grammar
            return 'query'
コード例 #12
0
ファイル: aspect.py プロジェクト: hstanev/fuselage
 def is_external( me):
     return (me.path_in_aspect is None
         and issubclass( me.op_klas, Op2)
         and not me.full_path.startswith( me.context.mountpoint))
コード例 #13
0
ファイル: hardlink.py プロジェクト: hstanev/fuselage
        stat_res = me._dispatch()
        # if os.path.split( me.q.path_in_aspect)[0] and isinstance( stat_res, stat_result):
        if Hardlink.getattr4symlink and isinstance(stat_res, stat_result):
            all = list(stat_res)
            log("original:", all)
            all[0] = all[0] | S_IFLNK
            log("new:", all)
            stat_res = stat_result(all)
        Hardlink.getattr4symlink = False
        return stat_res


Hardlink.getattr = getattr_

for op_name, op_klas in vars(Operations).iteritems():
    if not issubclass(op_klas, (Op1, Op2)):
        continue
    klas = getattr(Hardlink, op_name, op_klas)
    A = None
    if issubclass(op_klas, Op1) and not getattr(klas, "dispatch", None):

        class A(klas):
            dispatch = Hardlink._dispatch.im_func

    if issubclass(op_klas, Op2) and not getattr(klas, "external_dispatch", None):

        class A(klas):
            external_dispatch = Hardlink._external_dispatch.im_func

    if A:
        setattr(Hardlink, op_name, A)