Skip to content

Commit

Permalink
Added untested code for firmware update for #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamek committed Jan 8, 2020
1 parent 24fe79e commit 3577ba9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
20 changes: 20 additions & 0 deletions huawei_lte_api/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ def post(self,

return data

def post_file(self,
endpoint: str,
files: dict,
data: Optional[dict]=None,
prefix: str = 'api',
) -> str:

if self.request_verification_tokens:
data['csrf_token'] = self.request_verification_tokens[0]

response = self.session.post(
self._build_final_url(endpoint, prefix),
files=files,
data=data,
timeout=self.timeout
)
response.raise_for_status()

return response.content.lower()

@_try_or_reload_and_retry
def get(self, endpoint: str, params: Optional[dict]=None, prefix: str='api') -> dict:
headers = {}
Expand Down
25 changes: 20 additions & 5 deletions huawei_lte_api/api/FileManager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@

import os
from typing import BinaryIO
from huawei_lte_api.ApiGroup import ApiGroup


class FileManager(ApiGroup):
def upload(self, uploadfile: str):
return self._connection.post('filemanager/upload', {
'uploadfile': uploadfile
}) # !FIXME see issue #2
def upload(self, uploadfile: BinaryIO, uploadfile_name: str) -> str:
"""
Uploads firmware update and triggers it
:param uploadfile: filehandle on file to upload
:param uploadfile_name: name of uploaded file
:return: str
"""
uploadfile_basename = os.path.basename(uploadfile_name)
filename, extension = os.path.splitext(uploadfile_basename)

if extension not in ['bin', 'zip']:
raise Exception('Only *.bin or *.zip is allowed')

return self._connection.post_file('filemanager/upload', {
'uploadfile': uploadfile,
}, {
'cur_path': 'OU:{}'.format(uploadfile_basename)
})

0 comments on commit 3577ba9

Please sign in to comment.