GithubHelp home page GithubHelp logo

balena-sdk-python's People

Contributors

amirfuhrmann avatar balena-ci avatar chibby0ne avatar cywang117 avatar fisehara avatar flowzone-app[bot] avatar imrehg avatar james2710 avatar jsreds avatar klutchell avatar lucianbuzzo avatar nghiant2710 avatar otaviojacobi avatar page- avatar petrosagg avatar pimterry avatar pranasziaukas avatar siecje avatar thgreasi avatar thomas-sieren-tmh avatar vipulgupta2048 avatar xginn8 avatar zvin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

balena-sdk-python's Issues

invalid syntax in settings.py

I'm new to using the resin-sdk-python. I'm using python 2.7.11 and when I try to import the resin sdk, I get a syntax error:
Traceback (most recent call last): File "<input>", line 1, in <module> File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/resin/__init__.py", line 9, in <module> from .base_request import BaseRequest File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/resin/base_request.py", line 9, in <module> from .settings import Settings File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/resin/settings.py", line 56 print(Message.INVALID_SETTINGS.format(path=config_file_path), file=sys.stderr)

but if I change the file to:

sys.stderr.write(Message.INVALID_SETTINGS.format(path=config_file_path))
then I don't get an invalid syntax.

Am I using the sdk wrong? or am I using it wrong?

New API calls

Hi @nghiant2710,

The new API implementation works confusing because of the login state. If already logged in on the SDK version 1.x the old API address is retained even when updated to the latest 2.0 version. Only after a logout or removal of the resin.cfg file. But, if I try to reproduce it, I do get:

Settings file not found or not in proper format. Rewriting default settings to: /Users/username/.resin/resin.cfg

2nd point. The device.set_to_build command doesn't work. It returns:

>>> resin.models.device.set_to_build("ef448bdb8ac0000bb9013d98c6491587","339379")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    resin.models.device.set_to_build("ef448bdb8ac0000bb9013d98c6491587","339379")
  File "/usr/local/lib/python2.7/site-packages/resin/models/device.py", line 721, in set_to_build
    endpoint=self.settings.get('pine_endpoint')
  File "/usr/local/lib/python2.7/site-packages/resin/base_request.py", line 171, in request
    raise exceptions.RequestError(response._content)
RequestError

3th and last point ๐Ÿ˜…. Some return values have different labelling with API v3.
Like:

build โžก๏ธ should_be_running__build
commit โžก๏ธ is_on__commit

I understand I am quite early using these commands. However, it would be nice to have some documentation on which values changed in API v3.

Thanks! ๐Ÿ˜ฌ

Unused import ?

In resin/models/device_os.py
from sets import Set, Set is never used. Plus it is deprecated since version 2.6

Unable to set device to specific release, "Release is not valid for this device"

I currently cannot set a device to a specific release with the Python SDK. I tried using both the release hash and the release ID.

Release Hash: RequestError: b'"Release is not valid for this device"'
Release ID: ReleaseNotFound: <RELEASE_ID>

I am able to set the release using the shell scripts here, using the same UUID I attempted with the Python SDK.

I'm not sure what changed recently because I was able to use the Python SDK to do this same operation earlier this week.

Front logo Front conversations

Build issues on Debian stretch and gcc, cffi dependence.

Hi I am having some issues trying to build the package, specifically in the cffi dependence.

Error:

arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-haFsHd/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.5m -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.5/c/_cffi_backend.o
c/_cffi_backend.c:15:17: fatal error: ffi.h: No such file or directory
#include <ffi.h>
^
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-_j379qbe/cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-cqnd3icb-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_j379qbe/cffi/

Docker file.

`# Base image
FROM resin/armv7hf-debian:stretch

Install required Linux packages

RUN apt-cache policy
RUN apt-get update && apt-get install -yq
curl
gcc
git
iputils-ping
libboost-all-dev
libcurl4-openssl-dev
libssl-dev \

python3
python3-dev
python3-pip
python3-setuptools
modemmanager
valgrind &&
apt-get clean && rm -rf /var/lib/apt/lists/*

Install required Python packages

RUN pip3 install -U --no-binary :all:
git+https://github.com/resin-io/resin-sdk-python.git

Set the working directory

WORKDIR /usr/src/app

Copy everything into the container

COPY . ./

COPY env_vars.yaml /data/env_vars.yaml

ENV DBUS_SYSTEM_BUS_ADDRESS unix:path=/host/run/dbus/system_bus_socket

Start application

CMD ["bash", "start.sh"]`

Support changing device name

Support changing device name as in the node SDK, i.e.:

resin.models.device.rename(process.env.RESIN_DEVICE_UUID, 'some-new-name');

On Python3 the SDK also needs urlparse

While on Python 2 it works fine, the SDK seems to have a missing dependency on Python 3.

Python 3.5.2 (default, Jun 28 2016, 08:46:01) 
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import resin
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/greg/resin/prog/bluemix-resin-python/venv3/lib/python3.5/site-packages/resin/__init__.py", line 9, in <module>
    from .base_request import BaseRequest
  File "/home/greg/resin/prog/bluemix-resin-python/venv3/lib/python3.5/site-packages/resin/base_request.py", line 7, in <module>
    from urlparse import urljoin
ImportError: No module named 'urlparse'

Front logo Front conversations

Error with resin.cfg on application start

When running an application using this SDK, the error Settings file not found or not in proper format. Rewriting default settings to: /root/.resin/resin.cfg is present on every device reboot, where hostOS is rebooted as well. Generally it is harmless, however it appears to take 15s to process this error, which slows down the boot process.

Application in question is the following: https://github.com/IRNAS/PiRA-zero-firmware

We use the Pyhton SDK to issue shutdown and reboot commands to the host os.

Downloading device OS for quad core platform

There does not seem to be a parameter for single/quad core switch as per the web interface when downloading device OS image. Any ideas how this could be achieved with current SDK?

`set_to_build` command does not work

See https://app.frontapp.com/open/cnv_gtna5t

File "resin_cli.py", line 130, in main
res = resin.models.device.set_to_build(arguments["--device_uuid"],build_id)
File "/usr/local/lib/python3.6/site-packages/resin/models/device.py", line 721, in set_to_build
endpoint=self.settings.get('pine_endpoint')
File "/usr/local/lib/python3.6/site-packages/resin/base_request.py", line 171, in request
raise exceptions.RequestError(response._content)
resin.exceptions.RequestError: b'Internal Server Error'

Front logo Front conversations

API Endpoints Update

Hello I posted on the gitter chat about an issue where setting a single environment variable causes all environment variables in the project to be changed, making my devices basically unusable.

Example code:
`
resin = Resin()

key = open("/blah/blah/blah/resin_key",'r')
token = key.readline().rstrip()
print(token)

resin.auth.login_with_token(token)
print("Is Login Successful?: " + str(resin.auth.is_logged_in()) )

import pprint
pp = pprint.PrettyPrinter(indent=4)

env = resin.models.environment_variables.device.get_all('{uuid}')

pp.pprint(env)

resin.models.environment_variables.device.update({var_id},"This should only change one")
`
This is also from Gitter:
Shaun Mulligan
@shaunmulligan
14:02

Okay @sako0938 , I have reproduced this, its a bug in our translation layer. The node.js SDK isn't affected by it because it has been updated to use the latest API version, but the python sdk hasn't been updated yet, so it uses older endpoints that have translation logic behind them to make sure the data maps onto the new model changes we deployed.

I will get the guys to fix this asap

How to use the SDK via WSGI

I used the Pythonic resin-sdk before from the command line.
Now I'm trying to move some of my code into a WSGI application, but I get:

OSError: [Errno 13] Permission denied: '/usr/share/httpd/.balena'

Is there a way to not use such a directory? Maybe using the RESIN_API_KEY?

Handle errors when reading settings

It's possible that reading ~/.resin/resin.cfg will fail and the reading code is not robust. It currently checks for the existence of the data directory and .cfg file before attempting to read settings, but it's possible that the file exists but hasn't been saved correctly. Here's a traceback that reads the file but it's not in proper format:

    a = resin.Auth()
  File "/var/projects/foo/virtualenv/local/src/resinsdk/resin/auth.py", line 14, in __init__
    self.base_request = BaseRequest()
  File "/var/projects/foo/virtualenv/local/src/resinsdk/resin/base_request.py", line 23, in __init__
    self.settings = Settings()
  File "/var/projects/foo/virtualenv/local/src/resinsdk/resin/settings.py", line 41, in __init__
    self.__read_settings()
  File "/var/projects/foo/virtualenv/local/src/resinsdk/resin/settings.py", line 64, in __read_settings
    options = config_reader.options(self.CONFIG_SECTION)
  File "/usr/lib/python2.7/ConfigParser.py", line 279, in options
    raise NoSectionError(section)
NoSectionError: No section: 'Settings'

Unless we save user data in resin.cfg, I think it makes sense to try/catch reading the settings, and fallback to just writing the file, like so:

    def __init__(self):
        try:
                self.__read_settings()
        except Exception as e:
                print('Settings file not found or not in proper format', e)
                self.__write_settings()

Cannot set a tag value for a device when it was deleted once

Hello. I am having problems with the Python-SDK. Let me first explain what am I doing right now. I am creating a backup file every day of all variables and tags for device. I am currently working on a backup processor script which is taking the values and restoring the devices variables and tags. I found an interesting thing while testing the script. When I deleted a tag and after that I tried to set it back on - it is returning "OK" as it exists and it was updated but it doesn't exist and it isn't populated at all. I think, you are caching things up on your end and you are returning this for a faster response. The devices are raspberry pi 3, if that matter.

Front logo Front conversations

Check Supervisor API compatibility of device

Some Supervisor API endpoints (e.g. /v1/apps) are only provided by the latest supervisor versions, so the SDK should check the device.supervisor_version field and display a descriptive error message if the SDK users invokes an unsupported method.

Also check discussion here: balena-io/balena-sdk#206

Get name (From 4.0.0 Update) is broken

resin.models.device.get_name("#####")
Traceback (most recent call last):
File "", line 1, in
File "/home/skorn/Babylon-Web/django/env/lib/python3.6/site-packages/resin/models/device.py", line 202, in get_name
return self.get(uuid)['device_name']
KeyError: 'device_name'

When you go find the file /resin/models/device.py in the repo it talks about a large breaking change, so it seems something is just a bit off with the 4.0.0 update.

Thanks for the support!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.