@@ -1977,6 +1977,21 @@ def __call__(self, parser, namespace, fname, option_string=None):
19771977
19781978 main (args_content .split ("\r \n " )[1 :])
19791979
1980+ def show_location ():
1981+ if os .path .exists (opts .location ):
1982+ all_identifiers = get_installed_identifiers ()
1983+
1984+ if all_identifiers :
1985+ print ("Programs installed in {}:" .format (opts .location ))
1986+
1987+ for program in [RioLua , LuaJIT , LuaRocks ]:
1988+ if program .name in all_identifiers :
1989+ show_identifiers (all_identifiers [program .name ])
1990+ else :
1991+ print ("No programs installed in {}." .format (opts .location ))
1992+ else :
1993+ print ("{} does not exist." .format (opts .location ))
1994+
19801995def main (argv = None ):
19811996 parser = argparse .ArgumentParser (
19821997 description = hererocks_version + ", a tool for installing Lua and/or LuaRocks locally." ,
@@ -2013,7 +2028,7 @@ def main(argv=None):
20132028 "Lua 5.3 is supported only since LuaRocks 2.2.0, and Lua 5.4 is supported only since "
20142029 "LuaRocks 3.0.0." )
20152030 parser .add_argument ("--show" , default = False , action = "store_true" ,
2016- help = "Instead of installing show programs already present in <location>" )
2031+ help = "Show programs installed in <location>, possibly after installing new ones. " )
20172032 parser .add_argument ("-i" , "--ignore-installed" , default = False , action = "store_true" ,
20182033 help = "Install even if requested version is already present." )
20192034 parser .add_argument (
@@ -2080,74 +2095,59 @@ def main(argv=None):
20802095 if opts .lua and opts .luajit :
20812096 parser .error ("can't install both PUC-Rio Lua and LuaJIT" )
20822097
2083- if (opts .lua or opts .luajit or opts .luarocks ) and opts .show :
2084- parser .error ("can't both install and show" )
2085-
2086- if opts .show :
2087- if os .path .exists (opts .location ):
2088- all_identifiers = get_installed_identifiers ()
2089-
2090- if all_identifiers :
2091- print ("Programs installed in {}:" .format (opts .location ))
2098+ if opts .lua or opts .luajit or opts .luarocks :
2099+ global temp_dir
2100+ temp_dir = tempfile .mkdtemp ()
20922101
2093- for program in [RioLua , LuaJIT , LuaRocks ]:
2094- if program .name in all_identifiers :
2095- show_identifiers (all_identifiers [program .name ])
2096- else :
2097- print ("No programs installed in {}." .format (opts .location ))
2098- else :
2099- print ("Location does not exist." )
2102+ if (opts .lua or opts .luajit ) and os .name == "nt" and argv is None and using_cl ():
2103+ setup_vs (opts .target )
21002104
2101- sys .exit (0 )
2105+ start_dir = os .getcwd ()
2106+ opts .location = os .path .abspath (opts .location )
21022107
2103- global temp_dir
2104- temp_dir = tempfile . mkdtemp ( )
2108+ if opts . downloads is not None :
2109+ opts . downloads = os . path . abspath ( opts . downloads )
21052110
2106- if ( opts . lua or opts . luajit ) and os . name == "nt" and argv is None and using_cl () :
2107- setup_vs (opts .target )
2111+ if opts . builds is not None :
2112+ opts . builds = os . path . abspath (opts .builds )
21082113
2109- start_dir = os .getcwd ()
2110- opts .location = os .path .abspath (opts .location )
2114+ identifiers = get_installed_identifiers ()
21112115
2112- if opts . downloads is not None :
2113- opts . downloads = os .path .abspath (opts .downloads )
2116+ if not os . path . exists ( os . path . join ( opts . location , "bin" )) :
2117+ os .makedirs ( os . path .join (opts .location , "bin" ) )
21142118
2115- if opts .builds is not None :
2116- opts .builds = os .path .abspath (opts .builds )
2119+ write_activation_scripts ()
21172120
2118- identifiers = get_installed_identifiers ()
2121+ if opts .lua :
2122+ if "LuaJIT" in identifiers :
2123+ del identifiers ["LuaJIT" ]
21192124
2120- if not os . path . exists ( os . path . join ( opts .location , "bin" ) ):
2121- os . makedirs ( os . path . join ( opts . location , "bin" ) )
2125+ if RioLua ( opts .lua ). update_identifiers ( identifiers ):
2126+ save_installed_identifiers ( identifiers )
21222127
2123- write_activation_scripts ()
2124-
2125- if opts .lua :
2126- if "LuaJIT" in identifiers :
2127- del identifiers ["LuaJIT" ]
2128+ os .chdir (start_dir )
21282129
2129- if RioLua (opts .lua ).update_identifiers (identifiers ):
2130- save_installed_identifiers (identifiers )
2130+ if opts .luajit :
2131+ if "lua" in identifiers :
2132+ del identifiers ["lua" ]
21312133
2132- os .chdir (start_dir )
2134+ if LuaJIT (opts .luajit ).update_identifiers (identifiers ):
2135+ save_installed_identifiers (identifiers )
21332136
2134- if opts .luajit :
2135- if "lua" in identifiers :
2136- del identifiers ["lua" ]
2137+ os .chdir (start_dir )
21372138
2138- if LuaJIT (opts .luajit ).update_identifiers (identifiers ):
2139- save_installed_identifiers (identifiers )
2139+ if opts .luarocks :
2140+ if LuaRocks (opts .luarocks ).update_identifiers (identifiers ):
2141+ save_installed_identifiers (identifiers )
21402142
2141- os .chdir (start_dir )
2143+ os .chdir (start_dir )
21422144
2143- if opts .luarocks :
2144- if LuaRocks (opts .luarocks ).update_identifiers (identifiers ):
2145- save_installed_identifiers (identifiers )
2145+ remove_dir (temp_dir )
2146+ print ("Done." )
21462147
2147- os .chdir (start_dir )
2148+ if opts .show :
2149+ show_location ()
21482150
2149- remove_dir (temp_dir )
2150- print ("Done." )
21512151 sys .exit (0 )
21522152
21532153if __name__ == "__main__" :
0 commit comments