Sample Header Ad - 728x90

How do I run a supervisor command in a Eclipse PyDev project without being asked for a password?

1 vote
0 answers
189 views
So I've got the following code that should check whether an npm package is installed: def is_installed(name, as_global=True): # Returns whether NPM package is installed. s = shell(_get_npm_command("ls -p --depth 0", as_global)) match = re.search(r'\b%s\b' % (name), s['stdout']) if match: return True return False With the shell function being a subprocess.Popen() wrapper: def shell(c, stdin=None, env={}): # Simplified wrapper for shell calls to subprocess.Popen() environ = os.environ environ["LC_ALL"] = "C" for x in env: environ[x] = env[x] if not "HOME" in environ: environ["HOME"] = "/root" p = subprocess.Popen(shlex.split(c), stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE, env=environ) data = p.communicate(stdin) return {"code": p.returncode, "stdout": data, "stderr": data} and with a get_npm_command like this: def _get_npm_command(command, as_global, path=None): # returns npm command if as_global: return _get_global_npm_command(command) else: return _get_local_npm_command(command, path) def _get_global_npm_command(command): # returns global npm command os.chdir(NPM_PATH) return "gksu -u npm 'npm " + command + " -g'" def _get_local_npm_command(command, install_path): # returns local npm command if install_path: os.chdir(install_path) return "npm " + command + " " As you can see, the eventual command is: gksu -u npm npm ls -p --depth 0 In other words, I've created a user called npm to install global npm packages, because not that long ago npm recommended that one should not use root privileges in order to use it. They've changed their minds, but I intend stick with this solution I've found on the web that someone came up with. Anyway, gksu prompts me with a password for this command, but npm is not meant to have a password and so I would like to be able to run this command without being asked a password for. I've tried the following: /etc/sudoers.d/arkos.sudo npm ALL=(ALL) NOPASSWD: /usr/bin/npm ..but that doesn't seem to have any effect.
Asked by Folaht (1156 rep)
Jun 13, 2016, 03:01 AM
Last activity: Jun 13, 2016, 06:40 AM