0

我想用 python 脚本安装一个包。我已阅读有关 PackageManager API 的文档(http://doc.aldebaran.com/2-4/naoqi/core/packagemanager-api.html):

因此,我已将应用程序与 choregraphe 打包在一起,如http://doc.aldebaran.com/2-4/naoqi/core/packagemanager.html中所述,我尝试使用如下所示的 python 脚本安装它:

import qi
import sys


if __name__ == '__main__':
    ip = "11.1.11.111"
    port = 9559

    session = qi.Session()
    try:
        session.connect("tcp://" + ip + ":" + str(port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + ip + "\" on port " + str(port))
        sys.exit(1)

    service = session.service("PackageManager")

    package = "C:\\test_package_handlers_01-835a92-1.0.0.pkg"

    # this is to see if the problem is that python can not locate the file
    with open(package) as f:
        print f

    service.install(package)

这是我收到的错误:

# provided package could be opened
<open file 'C:\\test_package_handlers_01-835a92-1.0.0.pkg', mode 'r' at 0x02886288>
Traceback (most recent call last):
  File "C:/test.py", line 24, in <module>
    service.install(package)
RuntimeError: C:\test_package_handlers_01-835a92-1.0.0.pkg: no such file

我猜这是因为必须将包上传到机器人上,并且包文件路径必须是机器人上的路径。

已编辑

我已将包添加到编排空白项目并在机器人上运行此空白项目。通过这种方式,包被保存到带有路径的机器人中/home/nao/.local/share/PackageManager/apps/.lastUploadedChoregrapheBehavior/test_package_handlers_01-835a92-1.0.0.pkg,当我更改脚本中的路径("C:\\test_package_handlers_01-835a92-1.0.0.pkg"with "/home/nao/.local/share/PackageManager/apps/.lastUploadedChoregrapheBehavior/test_package_handlers_01-835a92-1.0.0.pkg")时,脚本按预期工作并且包安装在机器人上。

那么有没有办法从我的 PC 安装包而不将它们上传到机器人,因为否则最好使用 Choregraphe 来上传项目。

也许最好对我想要实现的目标进行以下解释:

  • 例如,我的 PC 上有一个包含 20 个包的文件夹
  • 我想用一个 python 脚本安装所有这 20 个包
  • 有一个 python 脚本,当它被这样调用时,它会安装文件夹中的所有包: python package_installer.py path_to_packages_folder

已编辑_2

import qi
import ftplib
import os

ROBOT_URL = "10.80.129.90"

print "Uploading PKG"
pkg_file = "my-application-0.0.1.pkg"
pkg_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), pkg_file)

ftp = ftplib.FTP(ROBOT_URL)
ftp.login("nao", "nao")
with open(pkg_path) as pkg:
    ftp.storbinary("STOR "+pkg_file, pkg)

print "Connecting NAOqi session"
app = qi.Application(url='tcp://'+ROBOT_URL+':9559')
app.start()
session = app.session

print "Installing app"
packagemgr = session.service("PackageManager")
packagemgr.install("/home/nao/"+pkg_file)

print "Cleaning robot"
ftp.delete(pkg_file)
ftp.quit()

print "End"
app.stop()

这段代码ftp = ftplib.FTP(ROBOT_URL)抛出以下异常:

Traceback (most recent call last):
  File "C:/Stefan/DSK_PEPPER_clode_2/PythonScripts/_local_testing/uploading_and_installing_package.py", line 11, in <module>
    ftp = ftplib.FTP(ROBOT_URL)
  File "C:\Python27\lib\ftplib.py", line 120, in __init__
    self.connect(host)
  File "C:\Python27\lib\ftplib.py", line 135, in connect
    self.sock = socket.create_connection((self.host, self.port), self.timeout)
  File "C:\Python27\lib\socket.py", line 575, in create_connection
    raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

此外,当我使用用户名“nao”连接到机器人并按照http://doc.aldebaran.com/2-5/dev/tools/opennao.html中的描述传递“nao”时,然后尝试在/home/nao/.local/share/PackageManager/apps/其中创建一个文件夹sudo mkdir它告诉我:Sorry, user nao is not allowed to execute '/bin/mkdir dasdas' as root on Pepper.。如果我只mkdir在这里使用它会告诉我:mkdir: cannot create directory 'new_folder': Permission denied

4

2 回答 2

3

使用qibuild,您也可以使用以下命令直接安装:

qipkg deploy-package /path/to/my-package.pkg --url nao@10.10.23.45
于 2017-09-12T16:51:03.093 回答
1

您确实需要先上传文件。您可以使用scpsftp来执行此操作。一旦在.pkg机器人上,您就可以使用PackageManager.install.

想象一下:

import qi
import paramiko
import os

ROBOT_URL = "10.80.129.90"

print "Uploading PKG"
pkg_file = "my-application-0.0.1.pkg"
pkg_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), pkg_file)

transport = paramiko.Transport((ROBOT_URL, 22))
transport.connect(username="nao", password="nao")
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put(pkg_path, pkg_file)

print "Connecting NAOqi session"
app = qi.Application(url='tcp://'+ROBOT_URL+':9559')
app.start()
session = app.session

print "Installing app"
packagemgr = session.service("PackageManager")
packagemgr.install("/home/nao/"+pkg_file)

print "Cleaning robot"
sftp.remove(pkg_file)
sftp.close()
transport.close()

print "End"
app.stop()
于 2017-09-07T23:49:21.660 回答