简体   繁体   中英

python script to run a node application and to output dependencies

I am trying to write a python script that will download a Node GitHub repository. once downloaded it will use build command to build the app, and then also to output the dependencies of this node project.

import json
import pymongo
import requests
import os
import subprocess
from git import Repo

from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017')
db = client['ibm_test']
collection_dep = db['dep']


headers = {'Authorization': 'token '}
r = requests.get('https://github.com/app.git', headers=headers)
#if(r.ok):
#    repoItem = package.json.loads(r.text or r.content)
#if  repoItem['language'] == 'JavaScript':

HTTPS_REMOTE_URL = 'https//git.url'
DEST_NAME = 'build/npm'
cloned_repo = Repo.clone_from(HTTPS_REMOTE_URL, DEST_NAME)
buildCommand = "build/npm/express-ibm/npm run-script devstart -b build/npm/express-ibm/package.json"
process = subprocess.Popen(buildCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
print(output)
print(error)
    # depo = subprocess.run(cmd)
     #depo = subprocess.check_output(['ls','-l'])
     #depo = os.system("gradle dependencies")
    # depo = os.system('path gradle *./graldew dependencies*')
    # collection_dep.insert(depo)
f= open("npm.json","w+")
#print(depo)
print("end")
client.close()

EDIT: add exception trace back.

Original exception was:

Traceback (most recent call last):
File "node.py", line 34, in <module>
    process = subprocess.Popen(buildCommand.split(), stdout=subprocess.PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in init
    restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'build/npm/express-ibm/npm'

The path 'build/npm/express-ibm/npm' does not exist.

You need to give a full path

exe_path = os.path.join('/the/path/to', 'build/npm/express-ibm/npm')

And use it in subprocess.Popen (or subprocess.run which is better)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM