|
77 | 77 | fp.write("@REM created by run of makeBat.py on {:%d %b %Y %H:%M}\n".format( |
78 | 78 | datetime.datetime.now())) |
79 | 79 | #activate = os.path.join(os.path.split(pythonexe)[0],'Scripts','activate') |
80 | | - activate = os.path.join(os.path.split(pythonexe)[0],'condabin','conda.bat') |
| 80 | + installloc = os.path.split(pythonexe)[0] |
| 81 | + activate = os.path.join(installloc,'condabin','conda.bat') |
81 | 82 | print("Looking for",activate) |
82 | 83 | # for a non-base conda install, it might be better to use the activate in |
83 | 84 | # the base, but for now let's use the one we find relative to our python |
84 | 85 | if os.path.exists(activate): |
85 | 86 | activate = os.path.realpath(activate) |
86 | | - if ' ' in activate: |
87 | | - activate = f'call "{activate}" activate\n' |
88 | | - else: |
89 | | - activate = f'call {activate} activate\n' |
90 | | - print(f'adding activate command to .bat file\n({activate})') |
| 87 | + if ' ' in activate: activate = f'"{activate}"' |
| 88 | + if ' ' in installloc: installloc = f'"{installloc}"' |
| 89 | + actcmd = f'''@echo {activate} activate |
| 90 | +@call {activate} activate |
| 91 | +@REM In case the previous did not work because a different conda is active, the |
| 92 | +@REM next command should fix that. If it did work, it will not change anything |
| 93 | +@echo call conda activate {installloc} |
| 94 | +@call conda activate {installloc} |
| 95 | +''' |
| 96 | + print(f'adding activate command to .bat file\n({actcmd})') |
91 | 97 | else: |
92 | 98 | print('Note: conda activate not found') |
93 | | - activate = '@REM no activate command found' |
| 99 | + actcmd = '@REM no activate command found\n' |
94 | 100 | #pexe = pythonexe |
95 | 101 | #if ' ' in pythonexe: pexe = '"'+pythonexe+'"' |
96 | 102 | G2s = G2script |
97 | 103 | if ' ' in G2s: G2s = '"'+G2script+'"' |
98 | | - fp.write(Script.format(activate,'python.exe',G2s)) |
| 104 | + fp.write(Script.format(actcmd,'python.exe',G2s)) |
99 | 105 | fp.close() |
100 | 106 | print(f'\nCreated GSAS-II batch file {G2bat}') |
101 | 107 |
|
102 | 108 | # create a reset script |
103 | 109 | gitstrap = os.path.abspath( |
104 | 110 | os.path.normpath(os.path.join(path2repo,'..','gitstrap.py'))) |
| 111 | + G2s = gitstrap |
| 112 | + if ' ' in G2s: G2s = '"'+gitstrap+'"' |
105 | 113 | if not os.path.exists: |
106 | 114 | print(f'the installation script was not found: {gitstrap!r}') |
107 | 115 | else: |
108 | 116 | G2reset = os.path.normpath(os.path.join(path2repo,'..','2Reset2FreshGSASII.bat')) |
109 | 117 | fp = open(G2reset,'w') |
110 | 118 | fp.write("@REM created by run of makeBat.py on {:%d %b %Y %H:%M}\n".format( |
111 | 119 | datetime.datetime.now())) |
112 | | - fp.write("REM This script will reset GSAS-II to the latest version, even if the program can't be started\n") |
| 120 | + fp.write("@echo This script will reset GSAS-II to the latest version, even if the program can't be started\n") |
| 121 | + if os.path.exists(activate): fp.write(f"{actcmd}") |
| 122 | + |
113 | 123 | pexe = pythonexe |
114 | 124 | if ' ' in pythonexe: pexe = '"'+pythonexe+'"' |
115 | | - G2s = gitstrap |
116 | | - if ' ' in G2s: G2s = '"'+gitstrap+'"' |
117 | | - if activate: fp.write(f"{activate}") |
118 | 125 | fp.write('choice /c yn /n /m "Reset any local changes and install latest GSAS-II version? (y/n)"\n') |
119 | 126 | fp.write(f"goto %ERRORLEVEL%\n") |
120 | 127 | fp.write(f":1\n") |
| 128 | + fp.write("@echo Updating to the current version of the gitstrap script\n") |
| 129 | + fp.write(f"curl -L -o {G2s} https://github.com/AdvancedPhotonSource/GSAS-II-buildtools/raw/main/install/gitstrap.py\n") |
| 130 | + fp.write("@echo Now running gitstrap to update downloaded files (--reset)...\n") |
121 | 131 | fp.write(f"{pexe} {G2s} --reset\n") |
| 132 | + fp.write("@echo Now running gitstrap to create .bat files (--nodownload)...\n") |
| 133 | + fp.write(f"{pexe} {G2s} --nodownload\n") |
122 | 134 | fp.write(f":2\n") |
123 | 135 | fp.write(f"pause\n") |
124 | 136 | fp.close() |
|
0 commit comments