[英]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. 我正在尝试编写一个Python脚本,该脚本将下载Node GitHub存储库。 once downloaded it will use build command to build the app, and then also to output the dependencies of this node project. 一旦下载,它将使用build命令来构建应用程序,然后还输出该节点项目的依赖项。
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. 路径“ build / npm / express-ibm / npm”不存在。
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) 并在subprocess.Popen
(或更好的subprocess.run
)中使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.