Skip to content

Commit

Permalink
Add support for easy-enum version 0.2.0 and fix dependency versioning…
Browse files Browse the repository at this point in the history
… issue
  • Loading branch information
molejar committed Jul 20, 2019
1 parent 24b35d5 commit 17ef345
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 37 deletions.
118 changes: 106 additions & 12 deletions .gitignore
@@ -1,13 +1,107 @@
# directories
.idea
.pytest*
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.eggs
*.egg-info
__pycache__
build
dist
temp

# files
*.pyc
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# IDE
.idea
6 changes: 3 additions & 3 deletions requirements.txt
@@ -1,3 +1,3 @@
fdt>=0.1.2
click>=5.0
easy_enum>=0.1.0
fdt==0.1.2
click==7.0
easy_enum==0.2.0
6 changes: 5 additions & 1 deletion setup.py
Expand Up @@ -41,7 +41,11 @@ def long_description():
description='Open Source library for manipulating with U-Boot images and environment variables',
long_description=long_description(),
python_requires='>=3.6',
install_requires=['click>=5.0', 'fdt>=0.1.2'],
install_requires=[
'fdt==0.1.2',
'click==7.0',
'easy_enum==0.2.0'
],
packages=['uboot'],
classifiers=[
'Programming Language :: Python :: 3',
Expand Down
2 changes: 1 addition & 1 deletion uboot/common.py
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


from easy_enum import EEnum as Enum
from easy_enum import Enum

# ----------------------------------------------------------------------------------------------------------------------
# Image Types
Expand Down
2 changes: 1 addition & 1 deletion uboot/env_blob.py
Expand Up @@ -88,7 +88,7 @@ def get(self, name=None):
"""
if name:
assert isinstance(name, str), "name is not a string: %r" % name
if not name in self._env:
if name not in self._env:
raise Exception("ERROR: Env %s doesnt exist !" % name)
return self._env[name]
else:
Expand Down
10 changes: 5 additions & 5 deletions uboot/fdt_image.py
Expand Up @@ -94,13 +94,13 @@ def add_img(self, nfo, data):

for p in nfo.props:
name, value = p.name, p[0]
if name == "type" and value != "flat_dt" and not EnumImageType.is_valid(value):
if name == "type" and value != "flat_dt" and value not in EnumImageType:
raise Exception("Unknown IMAGE type")
elif name == "os" and not EnumOsType.is_valid(value):
elif name == "os" and value not in EnumOsType:
raise Exception("Unknown OS type")
elif name == "arch" and not EnumArchType.is_valid(value):
elif name == "arch" and value not in EnumArchType:
raise Exception("Unknown ARCH type")
elif name == "compression" and not EnumCompressionType.is_valid(value):
elif name == "compression" and value not in EnumCompressionType:
raise Exception("Unknown Compression type")

self.img_info.append(nfo)
Expand Down Expand Up @@ -274,7 +274,7 @@ def parse_itb(data, offset=0):
elif img.exist_property("data-size") and img.exist_property("data-position"):
data_size = get_value(img, "data-size")
data_offset = get_value(img, "data-position")
img_data = data[offset + data_offset : offset + data_offset + data_size]
img_data = data[offset + data_offset: offset + data_offset + data_size]
img.remove_property("data-size")
img.remove_property("data-position")
else:
Expand Down
28 changes: 14 additions & 14 deletions uboot/old_image.py
Expand Up @@ -61,43 +61,43 @@ def os_type(self):

@os_type.setter
def os_type(self, value):
assert EnumOsType.is_valid(value), "HEADER: Unknown Value of OS Type: %d" % value
self._os_type = int(value)
assert value in EnumOsType, "HEADER: Unknown Value of OS Type: %d" % value
self._os_type = value

@property
def arch_type(self):
return self._arch_type

@arch_type.setter
def arch_type(self, value):
assert EnumArchType.is_valid(value), "HEADER: Unknown Value of Arch Type: %d" % value
self._arch_type = int(value)
assert value in EnumArchType, "HEADER: Unknown Value of Arch Type: %d" % value
self._arch_type = value

@property
def image_type(self):
return self._image_type

@image_type.setter
def image_type(self, value):
assert EnumImageType.is_valid(value), "HEADER: Unknown Value of Image Type: %d" % value
self._image_type = int(value)
assert value in EnumImageType, "HEADER: Unknown Value of Image Type: %d" % value
self._image_type = value

@property
def compression(self):
return self._compression

@compression.setter
def compression(self, value):
assert EnumCompressionType.is_valid(value), "HEADER: Unknown Value of Compression Type: %d" % value
self._compression = int(value)
assert value in EnumCompressionType, "HEADER: Unknown Value of Compression Type: %d" % value
self._compression = value

@property
def name(self):
return self._name

@name.setter
def name(self, value):
assert type(value) is str, "HEADER: Name must be a string"
assert isinstance(value, str), "HEADER: Name must be a string"
assert len(value) <= 32, "HEADER: Name to long: %d char instead 32" % len(value)
self._name = value

Expand Down Expand Up @@ -407,8 +407,8 @@ def info(self):
return msg

def append(self, cmd_name, cmd_value):
assert type(cmd_name) is str, "ScriptImage: Command name must be a string"
assert type(cmd_value) is str, "ScriptImage: Command value must be a string"
assert isinstance(cmd_name, str), "ScriptImage: Command name must be a string"
assert isinstance(cmd_value, str), "ScriptImage: Command value must be a string"
self._cmds.append([cmd_name, cmd_value])

def pop(self, index):
Expand Down Expand Up @@ -660,8 +660,8 @@ def new_img(**kwargs):
else:
img_type = kwargs['image']

if not EnumImageType.is_valid(img_type):
raise Exception()
if img_type not in EnumImageType:
raise Exception("Not a valid image type")

if img_type == EnumImageType.MULTI:
img_obj = MultiImage(**kwargs)
Expand All @@ -683,7 +683,7 @@ def parse_img(data, offset=0):
"""
(img_type, offset) = get_img_type(bytearray(data), offset)

if not EnumImageType.is_valid(img_type):
if img_type not in EnumImageType:
raise Exception("Not a valid image type")

if img_type == EnumImageType.MULTI:
Expand Down

0 comments on commit 17ef345

Please sign in to comment.