ó ˯t_c@sÄddlZddlmZmZddlTddd„ƒYZddd„ƒYZd efd „ƒYZd efd „ƒYZd efd„ƒYZ defd„ƒYZ defd„ƒYZ dS(iÿÿÿÿN(tGiotGediti(t*t FileLookupcBs eZdZd„Zd„ZRS(sÐ This class is responsible for looking up files given a part or the whole path of a real file. The lookup is delegated to providers wich use different methods of trying to find the real file. cCsog|_|jjtƒƒ|jjt|ƒƒ|jjtƒƒ|jjtƒƒ|jjtƒƒdS(N(t providerstappendtAbsoluteFileLookupProvidertBrowserRootFileLookupProvidertCwdFileLookupProvidert%OpenDocumentRelPathFileLookupProvidertOpenDocumentFileLookupProvider(tselftwindow((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyt__init__s  cCs=d}x0|jD]%}|j|ƒ}|dk rPqqW|S(sñ Tries to find a file specified by the path parameter. It delegates to different lookup providers and the first match is returned. If no file was found then None is returned. path -- the path to find N(tNoneRtlookup(R tpatht found_filetprovider((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyR's  (t__name__t __module__t__doc__R R(((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyRs tFileLookupProvidercBseZdZd„ZRS(s6 The base class of all file lookup providers. cCstdƒ‚dS(sà This method must be implemented by subclasses. Implementors will be given a path and will try to find a matching file. If no file is found then None is returned. s!need to implement a lookup methodN(tNotImplementedError(R R((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyR=s(RRRR(((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyR8sRcBseZdZd„ZRS(so This file tries to see if the path given is an absolute path and that the path references a file. cCs9tjj|ƒr1tjj|ƒr1tj|ƒSdSdS(N(tosRtisabstisfileRtfile_new_for_pathR(R R((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyRLs$ (RRRR(((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyRFsRcBs eZdZd„Zd„ZRS(sp This lookup provider tries to find a file specified by the path relative to the file browser root. cCs ||_dS(N(R (R R ((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyR XscCsPt|jƒ}|rLtjj||ƒ}tjj|ƒrLtj|ƒSndS(N( tfile_browser_rootR RRtjoinRRRR(R Rtroott real_path((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyR[s (RRRR R(((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyRSs RcBseZdZd„ZRS(sx This lookup provider tries to find a file specified by the path relative to the current working directory. cCsoytjƒ}Wn tk r2tjdƒ}nXtjj||ƒ}tjj|ƒrgtj|ƒSdSdS(NtHOME( RtgetcwdtOSErrortgetenvRRRRRR(R RtcwdR((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyRks  (RRRR(((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyResR cBseZdZd„ZRS(s Tries to see if the path is relative to any directories where the currently open documents reside in. Example: If you have a document opened '/tmp/Makefile' and a lookup is made for 'src/test2.c' then this class will try to find '/tmp/src/test2.c'. cCs­|jdƒrdSx“tjjƒjƒD]|}|jƒjƒr)|jƒjƒ}|r¥|j ƒj ƒ}t j j ||ƒ}t j j|ƒr¢tj|ƒSq¥q)q)WdS(Nt/(t startswithRRt Applicationt get_defaultt get_documentstget_filetis_localt get_locationt get_parenttget_pathRRRRR(R Rtdoctlocationtrel_patht joined_path((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyRs(RRRR(((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyR ysR cBseZdZd„ZRS(sp Makes a guess that the if the path that was looked for matches the end of the path of a currently open document then that document is the one that is looked for. Example: If a document is opened called '/tmp/t.c' and a lookup is made for 't.c' or 'tmp/t.c' then both will match since the open document ends with the path that is searched for. cCs}|jdƒrdSxctjjƒjƒD]L}|jƒjƒr)|jƒjƒ}|ru|j ƒj |ƒru|Sq)q)WdS(NR%( R&RRR'R(R)R*R+R,tget_uritendswith(R RR/R0((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyRšs (RRRR(((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyR ‘s((( Rt gi.repositoryRRt functionsRRRRRR R (((s4/usr/lib64/gedit/plugins/externaltools/filelookup.pyts