<s> import os <EOL> def clean_pyc ( directory , path ) : <EOL> """<STR_LIT>""" <EOL> for file_name in directory : <EOL> file_path = os . path . join ( path , file_name ) <EOL> if file_name [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> print '<STR_LIT>' % file_name <EOL> os . remove ( file_path ) <EOL> elif os . path . isdir ( file_path ) : <EOL> clean_pyc ( os . listdir ( file_path ) , file_path ) <EOL> def in_FontLab ( ) : <EOL> try : <EOL> import FL <EOL> in_FL = True <EOL> except : <EOL> in_FL = False <EOL> return in_FL <EOL> def in_RoboFont ( ) : <EOL> try : <EOL> import mojo <EOL> in_RF = True <EOL> except : <EOL> in_RF = False <EOL> return in_RF <EOL> def in_DrawBot ( ) : <EOL> try : <EOL> import drawBot <EOL> in_DB = True <EOL> except : <EOL> in_DB = False <EOL> return in_DB <EOL> def in_NodeBox ( ) : <EOL> try : <EOL> import _ctx <EOL> in_NB = True <EOL> except : <EOL> in_NB = False <EOL> return in_NB <EOL> def get_context ( ) : <EOL> """<STR_LIT>""" <EOL> _FL = in_FontLab ( ) <EOL> _RF = in_RoboFont ( ) <EOL> if _FL : <EOL> context = '<STR_LIT>' <EOL> elif _RF : <EOL> context = '<STR_LIT>' <EOL> else : <EOL> context = '<STR_LIT>' <EOL> return context <EOL> _ctx = get_context ( ) <EOL> if _ctx == '<STR_LIT>' : <EOL> from AppKit import NSApp , NSPanel <EOL> from mojo . extensions import getExtensionDefault , setExtensionDefault <EOL> from mojo . UI import getScriptingMenuNamingShortKey , setScriptingMenuNamingShortKey , createModifier , setScriptingMenuNamingShortKeyForPath <EOL> def clear_shortcuts ( ) : <EOL> """<STR_LIT>""" <EOL> setScriptingMenuNamingShortKey ( { } ) <EOL> def get_shortcuts ( ) : <EOL> """<STR_LIT>""" <EOL> return getScriptingMenuNamingShortKey ( ) <EOL> def print_shortcuts ( verbose = False ) : <EOL> """<STR_LIT>""" <EOL> _dict = getScriptingMenuNamingShortKey ( ) <EOL> for k in _dict : <EOL> name , key = _dict [ k ] <EOL> print _dict [ k ] [ key ] , _dict [ k ] [ name ] , <EOL> if verbose : print k , os . path . exists ( k ) , <EOL> print <EOL> print <EOL> def set_shortcuts ( shortcuts_dict ) : <EOL> """<STR_LIT>""" <EOL> for path in shortcuts_dict . keys ( ) : <EOL> preferredName = shortcuts_dict [ path ] [ '<STR_LIT>' ] <EOL> shortKey = shortcuts_dict [ path ] [ '<STR_LIT>' ] <EOL> modifier = shortcuts_dict [ path ] [ '<STR_LIT>' ] <EOL> setScriptingMenuNamingShortKeyForPath ( path , preferredName , shortKey , modifier ) <EOL> def toggle_panels ( ) : <EOL> """<STR_LIT>""" <EOL> windows = NSApp . windows ( ) <EOL> panels = [ window for window in windows if isinstance ( window , NSPanel ) ] <EOL> show_panels = getExtensionDefault ( '<STR_LIT>' , fallback = True ) <EOL> if show_panels : <EOL> for panel in panels : <EOL> panel . orderOut_ ( None ) <EOL> setExtensionDefault ( '<STR_LIT>' , False ) <EOL> if show_panels is False : <EOL> for panel in panels : <EOL> if str ( type ( panel ) ) != '<STR_LIT>' : <EOL> panel . orderBack_ ( None ) <EOL> setExtensionDefault ( '<STR_LIT>' , True ) <EOL> def build_shortcuts_dict ( path , shortcuts ) : <EOL> """<STR_LIT>""" <EOL> _shortcuts_dict = { } <EOL> for shortcut in shortcuts : <EOL> _key , _name , _file = shortcut <EOL> _file_path = os . path . join ( path , _file ) <EOL> if os . path . exists ( _file_path ) : <EOL> _shortcuts_dict [ _file_path ] = { } <EOL> _shortcuts_dict [ _file_path ] [ '<STR_LIT>' ] = _name <EOL> _shortcuts_dict [ _file_path ] [ '<STR_LIT>' ] = _key <EOL> _shortcuts_dict [ _file_path ] [ '<STR_LIT>' ] = createModifier ( command = True , shift = True ) <EOL> else : <EOL> print '<STR_LIT>' % _file_path <EOL> return _shortcuts_dict <EOL> def merge_shortcuts_dicts ( dicts_list ) : <EOL> """<STR_LIT>""" <EOL> _super_dict = { } <EOL> for _dict in dicts_list : <EOL> for k in _dict . keys ( ) : <EOL> _super_dict [ k ] = _dict [ k ] <EOL> return _super_dict <EOL> def path_split ( p , rest = [ ] ) : <EOL> h , t = os . path . split ( p ) <EOL> if len ( h ) < <NUM_LIT:1> : <EOL> return [ t ] + rest <EOL> if len ( t ) < <NUM_LIT:1> : <EOL> return [ h ] + rest <EOL> return path_split ( h , [ t ] + rest ) <EOL> def common_path ( l1 , l2 , common = [ ] ) : <EOL> if len ( l1 ) < <NUM_LIT:1> : <EOL> return ( common , l1 , l2 ) <EOL> if len ( l2 ) < <NUM_LIT:1> : <EOL> return ( common , l1 , l2 ) <EOL> if l1 [ <NUM_LIT:0> ] != l2 [ <NUM_LIT:0> ] : <EOL> return ( common , l1 , l2 ) <EOL> return common_path ( l1 [ <NUM_LIT:1> : ] , l2 [ <NUM_LIT:1> : ] , common + [ l1 [ <NUM_LIT:0> ] ] ) <EOL> def rel_path ( p1 , p2 ) : <EOL> common , l1 , l2 = common_path ( path_split ( p1 ) , path_split ( p2 ) ) <EOL> p = [ ] <EOL> if len ( l1 ) > <NUM_LIT:0> : <EOL> p = [ '<STR_LIT>' * len ( l1 ) ] <EOL> p = p + l2 <EOL> return os . path . join ( * p ) </s>
