Skip to content

Commit

Permalink
Vet paths in Windows registry before using them
Browse files Browse the repository at this point in the history
Registry paths can contain illegal path characters, which caused
Paths.get() calls to throw, which in turn cancelled Python binary
search.
chhh committed Nov 16, 2018
1 parent f8f17f2 commit 068c082
Showing 3 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions MSFragger-GUI/src/umich/msfragger/gui/MsfraggerGuiFrame.form
Original file line number Diff line number Diff line change
@@ -510,7 +510,7 @@
<TitledBorder title="DB Slicing"/>
</Border>
</Property>
<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;"/>
<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;"/>
</Properties>

<Layout>
@@ -571,7 +571,7 @@
<TitledBorder title="Spectral Lib generation"/>
</Border>
</Property>
<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;"/>
<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;"/>
</Properties>

<Layout>
4 changes: 2 additions & 2 deletions MSFragger-GUI/src/umich/msfragger/gui/MsfraggerGuiFrame.java
Original file line number Diff line number Diff line change
@@ -1069,7 +1069,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});

jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("DB Slicing"));
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");
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");

lblDbsliceInfo1.setText(DbSlice.DEFAULT_MESSAGE);

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

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Spectral Lib generation"));
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");
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");

lblSpeclibInfo1.setText(SpecLibGen.DEFAULT_MESSAGE);

33 changes: 27 additions & 6 deletions MSFragger-GUI/src/umich/msfragger/util/PythonInfo.java
Original file line number Diff line number Diff line change
@@ -156,7 +156,20 @@ private String tryPythonCommandVersion(String cmd) throws Exception {
public boolean setPythonCommand(String command) throws Exception {
return trySetPythonCommand(command);
}


/**
* Checks that a registry location can be converted to {@link java.nio.file.Path}
* via {@link Paths#get(String, String...)} method.
*/
private boolean vetRegistryLocation(String loc) {
try {
Paths.get(loc);
} catch (Exception ignored) {
return false;
}
return true;
}

public void findPythonCommand() throws Exception {
String[] commands = {"python", "python3"};

@@ -169,7 +182,10 @@ public void findPythonCommand() throws Exception {
List<String> potentialLocs = new ArrayList<>();
for (String root : roots) {
for (String loc : locations) {
potentialLocs.addAll(RegQuery.query(root + loc));
List<String> query = RegQuery.query(root + loc);
potentialLocs.addAll(query.stream()
.filter(this::vetRegistryLocation)
.collect(Collectors.toList()));
}
}

@@ -178,11 +194,16 @@ public void findPythonCommand() throws Exception {
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
for (String possiblePython3InstallPath : possiblePython3InstallPaths) {
List<String> res = RegQuery.query(possiblePython3InstallPath + "\\InstallPath", "");
for (String r : res) {
for(String cmd : commands) {
final List<String> qureyInstallPath;
try {
qureyInstallPath = RegQuery.query(possiblePython3InstallPath + "\\InstallPath", "");
} catch (Exception ignored) {
continue;
}
for (String installPath : qureyInstallPath) {
for (String cmd : commands) {
try {
final String rVal = RegQuery.getTokenValue(RegQuery.TOKEN_REGSZ, r);
final String rVal = RegQuery.getTokenValue(RegQuery.TOKEN_REGSZ, installPath);
final String pythonBinPath = Paths.get(rVal, cmd).toString();
if (trySetPythonCommand(pythonBinPath))
return;

0 comments on commit 068c082

Please sign in to comment.