<s> import sys <EOL> sys . path . append ( "<STR_LIT>" ) <EOL> import os <EOL> import model <EOL> import editor <EOL> import ntpath <EOL> global shadowList <EOL> global createConfig <EOL> createConfig = { } <EOL> global context <EOL> def createModule ( newContext , newCreateConfig ) : <EOL> global context <EOL> global createConfig <EOL> global shadowList <EOL> context = newContext <EOL> createConfig = newCreateConfig <EOL> if createConfig [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> packages = context . getScriptPackages ( ) <EOL> elif createConfig [ "<STR_LIT:type>" ] == "<STR_LIT:text>" : <EOL> packages = context . getTextPackages ( ) <EOL> context . window . show_quick_panel ( packages , onPackageSelected , <NUM_LIT:0> ) <EOL> shadowList = packages <EOL> def onPackageSelected ( selectionIndex ) : <EOL> global createConfig <EOL> global shadowList <EOL> moduleSuggestiong = shadowList [ selectionIndex ] <EOL> if selectionIndex == - <NUM_LIT:1> : <EOL> return <EOL> if selectionIndex == <NUM_LIT:0> : <EOL> moduleSuggestiong = "<STR_LIT>" <EOL> if createConfig [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> packagePath = context . getBaseDir ( ) + context . settings [ "<STR_LIT>" ] + "<STR_LIT:/>" + moduleSuggestiong <EOL> if os . path . exists ( packagePath ) == True : <EOL> createConfig [ "<STR_LIT>" ] = context . settings [ "<STR_LIT>" ] <EOL> elif createConfig [ "<STR_LIT:type>" ] == "<STR_LIT:text>" : <EOL> packagePath = context . getBaseDir ( ) + context . settings [ "<STR_LIT>" ] + "<STR_LIT:/>" + moduleSuggestiong <EOL> if os . path . exists ( packagePath ) == True : <EOL> createConfig [ "<STR_LIT>" ] = context . settings [ "<STR_LIT>" ] <EOL> context . window . show_input_panel ( "<STR_LIT>" , moduleSuggestiong + createConfig [ "<STR_LIT:name>" ] , onNameDone , onNameChange , onNamceCancle ) <EOL> def onNameDone ( inputString ) : <EOL> global createConfig <EOL> global context <EOL> global shadowList <EOL> moduleFile = context . getBaseDir ( ) + createConfig [ "<STR_LIT>" ] + "<STR_LIT:/>" + inputString <EOL> createConfig [ "<STR_LIT>" ] = moduleFile <EOL> print moduleFile <EOL> name = moduleFile [ moduleFile . rfind ( "<STR_LIT:/>" ) : ] <EOL> if not "<STR_LIT:.>" in name : <EOL> if createConfig [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> ext = "<STR_LIT>" <EOL> name += ext <EOL> elif createConfig [ "<STR_LIT:type>" ] == "<STR_LIT:text>" : <EOL> ext = "<STR_LIT>" <EOL> name += ext <EOL> else : <EOL> ext = name [ name . rfind ( "<STR_LIT:.>" ) : ] <EOL> moduleDir = moduleFile [ <NUM_LIT:0> : moduleFile . rfind ( "<STR_LIT:/>" ) ] <EOL> moduleFile = moduleDir + name <EOL> createConfig [ "<STR_LIT>" ] = moduleFile <EOL> if os . path . exists ( moduleDir ) == False : <EOL> os . makedirs ( moduleDir ) <EOL> if len ( context . settings [ "<STR_LIT>" ] ) > <NUM_LIT:0> : <EOL> snippetsDir = context . getBaseDir ( ) + context . settings [ "<STR_LIT>" ] <EOL> snippets = [ ] <EOL> shadowList = [ ] <EOL> snippets . append ( "<STR_LIT>" ) <EOL> shadowList . append ( "<STR_LIT>" ) <EOL> for file in os . listdir ( snippetsDir ) : <EOL> dirfile = os . path . join ( snippetsDir , file ) <EOL> if os . path . isfile ( dirfile ) : <EOL> print "<STR_LIT>" + str ( ntpath . basename ( file ) [ <NUM_LIT:0> : <NUM_LIT:1> ] ) , str ( ntpath . basename ( file ) [ <NUM_LIT:0> : <NUM_LIT:1> ] ) is "<STR_LIT:.>" <EOL> if "<STR_LIT>" not in ntpath . basename ( file ) : <EOL> snippets . append ( ntpath . basename ( file ) ) <EOL> shadowList . append ( dirfile ) <EOL> context . window . show_quick_panel ( snippets , onSnippetSelected , <NUM_LIT:0> ) <EOL> else : <EOL> finish ( "<STR_LIT>" ) <EOL> def onSnippetSelected ( selectionIndex ) : <EOL> global shadowList <EOL> if selectionIndex == <NUM_LIT:0> : <EOL> finish ( "<STR_LIT>" ) <EOL> else : <EOL> moduleName = createConfig [ "<STR_LIT>" ] [ createConfig [ "<STR_LIT>" ] . rfind ( "<STR_LIT:/>" ) + <NUM_LIT:1> : createConfig [ "<STR_LIT>" ] . rfind ( "<STR_LIT:.>" ) ] <EOL> f = open ( shadowList [ selectionIndex ] , "<STR_LIT:r>" ) <EOL> data = f . read ( ) <EOL> snippet = data <EOL> snippet = snippet . replace ( "<STR_LIT>" , moduleName ) <EOL> f . close ( ) <EOL> finish ( snippet ) <EOL> def finish ( snippet ) : <EOL> global createConfig <EOL> global context <EOL> fileContent = "<STR_LIT>" <EOL> if createConfig [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> fileContent = "<STR_LIT>" <EOL> if len ( context . settings [ "<STR_LIT>" ] ) > <NUM_LIT:0> : <EOL> for module in context . settings [ "<STR_LIT>" ] : <EOL> addEdit = editor . ModuleEdit ( fileContent , context ) <EOL> addEdit . addModule ( context . getModuleByImportString ( module ) , module ) <EOL> fileContent = addEdit . render ( ) + "<STR_LIT:\n>" + snippet + "<STR_LIT>" <EOL> file = open ( createConfig [ "<STR_LIT>" ] , '<STR_LIT>' ) <EOL> file . write ( fileContent ) <EOL> file . close ( ) <EOL> if createConfig [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> temp = ( createConfig [ "<STR_LIT>" ] ) . split ( context . getBaseDir ( ) + createConfig [ "<STR_LIT>" ] + "<STR_LIT:/>" ) [ <NUM_LIT:1> ] ; <EOL> importString = temp [ <NUM_LIT:0> : temp . rfind ( "<STR_LIT:.>" ) ] <EOL> elif createConfig [ "<STR_LIT:type>" ] == "<STR_LIT:text>" : <EOL> temp = ( createConfig [ "<STR_LIT>" ] ) . split ( context . getBaseDir ( ) + createConfig [ "<STR_LIT>" ] + "<STR_LIT:/>" ) [ <NUM_LIT:1> ] ; <EOL> importString = "<STR_LIT>" + context . settings [ "<STR_LIT>" ] + "<STR_LIT:/>" + temp <EOL> createConfig [ "<STR_LIT>" ] ( importString , createConfig ) <EOL> def onNameChange ( input ) : <EOL> pass <EOL> def onNamceCancle ( input ) : <EOL> pass </s>
