Skip to content

Commit 068c082

Browse files
committed
Vet paths in Windows registry before using them
Registry paths can contain illegal path characters, which caused Paths.get() calls to throw, which in turn cancelled Python binary search.
1 parent f8f17f2 commit 068c082

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

MSFragger-GUI/src/umich/msfragger/gui/MsfraggerGuiFrame.form

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@
510510
<TitledBorder title="DB Slicing"/>
511511
</Border>
512512
</Property>
513-
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;Requires &lt;b&gt;Python 3&lt;/b&gt; with packages &lt;b&gt;Numpy, Pandas&lt;/b&gt;&#xa;Ways to get everything set up:&lt;br&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;Install Python 3 if you don&apos;t yet have it.&lt;/li&gt;&#xa;&lt;li&gt;Install required python modules using &lt;i&gt;pip&lt;/i&gt;, the python package manager, with commands:&lt;/li&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;pip install numpy&lt;/li&gt;&#xa;&lt;li&gt;pip install pandas&lt;/li&gt;&#xa;&lt;li&gt;pip install cython&lt;/li&gt;&#xa;&lt;li&gt;pip install msproteomicstools&lt;/li&gt;&#xa;&lt;/ul&gt;&#xa;&lt;/ul&gt;&#xa;"/>
513+
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;Requires &lt;b&gt;Python 3&lt;/b&gt; with packages &lt;b&gt;Numpy, Pandas&lt;/b&gt;&#xa;Ways to get everything set up:&lt;br&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;Install Python 3 if you don&apos;t yet have it.&lt;/li&gt;&#xa;&lt;li&gt;Install required python modules using &lt;i&gt;pip&lt;/i&gt;, the python package manager, with command:&lt;/li&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;pip install numpy pandas&lt;/li&gt;&#xa;&lt;/ul&gt;&#xa;&lt;/ul&gt;&#xa;"/>
514514
</Properties>
515515

516516
<Layout>
@@ -571,7 +571,7 @@
571571
<TitledBorder title="Spectral Lib generation"/>
572572
</Border>
573573
</Property>
574-
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;Requires &lt;b&gt;Python 3&lt;/b&gt; with packages &lt;b&gt;Cython, Msproteomicstools&lt;/b&gt;.&lt;br/&gt;&#xa;Ways to get everything set up:&lt;br&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;Install Python 3 if you don&apos;t yet have it.&lt;/li&gt;&#xa;&lt;li&gt;Install required python modules using &lt;i&gt;pip&lt;/i&gt;, the python package manager, with commands:&lt;/li&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;pip install numpy&lt;/li&gt;&#xa;&lt;li&gt;pip install pandas&lt;/li&gt;&#xa;&lt;li&gt;pip install cython&lt;/li&gt;&#xa;&lt;li&gt;pip install msproteomicstools&lt;/li&gt;&#xa;&lt;/ul&gt;&#xa;&lt;/ul&gt;&#xa;"/>
574+
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;Requires &lt;b&gt;Python 3&lt;/b&gt; with packages &lt;b&gt;Cython, Msproteomicstools&lt;/b&gt;.&lt;br/&gt;&#xa;Ways to get everything set up:&lt;br&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;Install Python 3 if you don&apos;t yet have it.&lt;/li&gt;&#xa;&lt;li&gt;Install required python modules using &lt;i&gt;pip&lt;/i&gt;, the python package manager, with commands:&lt;/li&gt;&#xa;&lt;ul&gt;&#xa;&lt;li&gt;pip install numpy pandas cython&lt;/li&gt;&#xa;&lt;li&gt;pip install msproteomicstools&lt;/li&gt;&#xa;&lt;/ul&gt;&#xa;&lt;/ul&gt;&#xa;"/>
575575
</Properties>
576576

577577
<Layout>

MSFragger-GUI/src/umich/msfragger/gui/MsfraggerGuiFrame.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
10691069
});
10701070

10711071
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("DB Slicing"));
1072-
jPanel2.setToolTipText("<html>Requires <b>Python 3</b> with packages <b>Numpy, Pandas</b>\nWays to get everything set up:<br>\n<ul>\n<li>Install Python 3 if you don't yet have it.</li>\n<li>Install required python modules using <i>pip</i>, the python package manager, with commands:</li>\n<ul>\n<li>pip install numpy</li>\n<li>pip install pandas</li>\n<li>pip install cython</li>\n<li>pip install msproteomicstools</li>\n</ul>\n</ul>\n");
1072+
jPanel2.setToolTipText("<html>Requires <b>Python 3</b> with packages <b>Numpy, Pandas</b>\nWays to get everything set up:<br>\n<ul>\n<li>Install Python 3 if you don't yet have it.</li>\n<li>Install required python modules using <i>pip</i>, the python package manager, with command:</li>\n<ul>\n<li>pip install numpy pandas</li>\n</ul>\n</ul>\n");
10731073

10741074
lblDbsliceInfo1.setText(DbSlice.DEFAULT_MESSAGE);
10751075

@@ -1105,7 +1105,7 @@ public void stateChanged(javax.swing.event.ChangeEvent evt) {
11051105
});
11061106

11071107
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Spectral Lib generation"));
1108-
jPanel1.setToolTipText("<html>Requires <b>Python 3</b> with packages <b>Cython, Msproteomicstools</b>.<br/>\nWays to get everything set up:<br>\n<ul>\n<li>Install Python 3 if you don't yet have it.</li>\n<li>Install required python modules using <i>pip</i>, the python package manager, with commands:</li>\n<ul>\n<li>pip install numpy</li>\n<li>pip install pandas</li>\n<li>pip install cython</li>\n<li>pip install msproteomicstools</li>\n</ul>\n</ul>\n");
1108+
jPanel1.setToolTipText("<html>Requires <b>Python 3</b> with packages <b>Cython, Msproteomicstools</b>.<br/>\nWays to get everything set up:<br>\n<ul>\n<li>Install Python 3 if you don't yet have it.</li>\n<li>Install required python modules using <i>pip</i>, the python package manager, with commands:</li>\n<ul>\n<li>pip install numpy pandas cython</li>\n<li>pip install msproteomicstools</li>\n</ul>\n</ul>\n");
11091109

11101110
lblSpeclibInfo1.setText(SpecLibGen.DEFAULT_MESSAGE);
11111111

MSFragger-GUI/src/umich/msfragger/util/PythonInfo.java

+27-6
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,20 @@ private String tryPythonCommandVersion(String cmd) throws Exception {
156156
public boolean setPythonCommand(String command) throws Exception {
157157
return trySetPythonCommand(command);
158158
}
159-
159+
160+
/**
161+
* Checks that a registry location can be converted to {@link java.nio.file.Path}
162+
* via {@link Paths#get(String, String...)} method.
163+
*/
164+
private boolean vetRegistryLocation(String loc) {
165+
try {
166+
Paths.get(loc);
167+
} catch (Exception ignored) {
168+
return false;
169+
}
170+
return true;
171+
}
172+
160173
public void findPythonCommand() throws Exception {
161174
String[] commands = {"python", "python3"};
162175

@@ -169,7 +182,10 @@ public void findPythonCommand() throws Exception {
169182
List<String> potentialLocs = new ArrayList<>();
170183
for (String root : roots) {
171184
for (String loc : locations) {
172-
potentialLocs.addAll(RegQuery.query(root + loc));
185+
List<String> query = RegQuery.query(root + loc);
186+
potentialLocs.addAll(query.stream()
187+
.filter(this::vetRegistryLocation)
188+
.collect(Collectors.toList()));
173189
}
174190
}
175191

@@ -178,11 +194,16 @@ public void findPythonCommand() throws Exception {
178194
.sorted(Comparator.reverseOrder())
179195
.collect(Collectors.toList());
180196
for (String possiblePython3InstallPath : possiblePython3InstallPaths) {
181-
List<String> res = RegQuery.query(possiblePython3InstallPath + "\\InstallPath", "");
182-
for (String r : res) {
183-
for(String cmd : commands) {
197+
final List<String> qureyInstallPath;
198+
try {
199+
qureyInstallPath = RegQuery.query(possiblePython3InstallPath + "\\InstallPath", "");
200+
} catch (Exception ignored) {
201+
continue;
202+
}
203+
for (String installPath : qureyInstallPath) {
204+
for (String cmd : commands) {
184205
try {
185-
final String rVal = RegQuery.getTokenValue(RegQuery.TOKEN_REGSZ, r);
206+
final String rVal = RegQuery.getTokenValue(RegQuery.TOKEN_REGSZ, installPath);
186207
final String pythonBinPath = Paths.get(rVal, cmd).toString();
187208
if (trySetPythonCommand(pythonBinPath))
188209
return;

0 commit comments

Comments
 (0)