aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Tomecek <ttomecek@redhat.com>2016-07-28 14:17:18 +0200
committerBryn M. Reeves <bmr@redhat.com>2016-12-07 11:57:16 +0000
commit32ef6e6e9d4ead11cc6356fd357591f7eb91e7a7 (patch)
treef52073128ba9a81a7bae3abadc1caecb221fa3fa
parente9458ae0e263ea9997465a46873e9fe7be6ae3c8 (diff)
downloadsos-32ef6e6e9d4ead11cc6356fd357591f7eb91e7a7.tar.gz
[npm] find modules in npm cache
npm installs modules: 1. globally — so everyone can use those 2. per project If you don't know the path to the project, the only way to see the list of those modules is by traversing the whole filesystem, which is pretty unreal. This patch browses npm cache of every user on the system and saves module names and all available versions into sosreport. Signed-off-by: Tomas Tomecek <ttomecek@redhat.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com> Closes: #879.
-rw-r--r--sos/plugins/npm.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/sos/plugins/npm.py b/sos/plugins/npm.py
index 77464c22..f76bafee 100644
--- a/sos/plugins/npm.py
+++ b/sos/plugins/npm.py
@@ -14,6 +14,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import os
+import pwd
+import json
from sos.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin, \
SuSEPlugin
@@ -44,6 +46,41 @@ class Npm(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin, SuSEPlugin):
runat=working_directory
)
+ def _find_modules_in_npm_cache(self):
+ """
+ since format of `~/.npm` is changing with newer npm releases, let's do
+ the easiest thing and don't predict nor expect anything, the structure
+ is suppose to be:
+
+ ~/.npm
+ |-- asap
+ | `-- 2.0.4
+ |-- dezalgo
+ | |-- 1.0.2
+ | `-- 1.0.3
+ """
+ output = []
+
+ for p in pwd.getpwall():
+ user_cache = os.path.join(p.pw_dir, ".npm")
+ try:
+ # most of these stand for names of modules
+ module_names = os.listdir(user_cache)
+ except OSError:
+ self._log_debug("Skipping directory %s" % user_cache)
+ continue
+ else:
+ for m in module_names:
+ module_path = os.path.join(user_cache, m)
+ try:
+ versions = os.listdir(module_path)
+ except OSError:
+ continue
+ else:
+ output.append({m: versions})
+ outfn = self._make_command_filename("npm-cache-modules")
+ self.archive.add_string(json.dumps(output), outfn)
+
def setup(self):
if self.get_option("project_path") != 0:
project_path = os.path.abspath(os.path.expanduser(
@@ -51,6 +88,7 @@ class Npm(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin, SuSEPlugin):
self._get_npm_output("npm ls --json", "npm-ls-project",
working_directory=project_path)
self._get_npm_output("npm ls -g --json", "npm-ls-global")
+ self._find_modules_in_npm_cache()
class NpmViaNodeJS(Npm):