Skip to content

Commit

Permalink
Merge pull request #1 from MartinStej/dev
Browse files Browse the repository at this point in the history
Fixed problem with (possible) nonsesne message due to insufficient rights
  • Loading branch information
JNevrly authored May 4, 2018
2 parents 172fcd0 + b550bf1 commit 0bcc627
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 19 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
History
=======

0.9.8 (2018-05-04)
------------------
* Added information how to access device s regular user (sudo not needed)
* Added verbose option
* When communication with device will fail, more friendly message is shown
* Updated links in documentation

0.9.0 (2017-06-13)
------------------

Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ which will be expanded to the same thing.
Notes
-----
* Tested on Linux with Python 2.7, 3.2, 3.3 and 3.4
* If you have **problems with permissions**, you can always use ``sudo``, but
better way is create rule for udev. Create file
`/etc/udev/rules.d/11-alps_devices.rules`
and paste there following line:
``SUBSYSTEM=="usb", MODE="0644", GROUP="plugdev"``.
Unplug USB device, restart udev, plug USB device and try again. Also make
sure you are at group ``plugdev``
* Tested on Windows XP and Windows 7 with Python 2.7 (but it should work on
version 3.2, 3.3 and so on)
* For more info run application with "-h" parameter
Expand Down
Empty file removed UCA_lib/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion concon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

__author__ = """Martin Stejskal"""
__email__ = '[email protected]'
__version__ = '0.9.5'
__version__ = '0.9.8'
26 changes: 19 additions & 7 deletions concon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
DEFAULT_CONFIG = 'config/config.yml'
DEFAULT_LOG_CONFIG = 'config/logging_global.cfg'


# logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('UCA console')
logger = logging.getLogger('ConCon')



def report_errors(err):
Expand All @@ -34,13 +34,25 @@ def report_errors(err):
help="Application specific configuration file.")
@click.option('-d', '--device', default=None,
help="Selected device to configure.")
@click.option('--verbose/--quiet', default=False,
help="Enable / disable logging to Log.txt file")
@click.pass_context
def main(ctx, config, device, args=None):
def main(ctx, config, device, verbose, args=None):
"""Tool for configuration of devices implementing "Uniprot" communication
layer over USB (HID profile).
"""
ctx.obj = {}
logging.basicConfig(level=logging.ERROR)

# Check if verbose mode is on
if(verbose):
logging.config.fileConfig(
pkg_resources.resource_filename('concon',
DEFAULT_LOG_CONFIG),
None,
False)
# /if verbose

# TODO: Config doesn't work...
# logging.config.fileConfig(
# pkg_resources.resource_filename('concon', DEFAULT_LOG_CONFIG)
Expand Down Expand Up @@ -89,7 +101,7 @@ def main(ctx, config, device, args=None):
# Show device selection prompt
click.secho("More than one configurable devices detected.\n"
"Choose one from below and run concon with"
" -d [0 ~ {0}] option.".format(len(found_devices)-1),
" -d [0 ~ {0}] option.".format(len(found_devices) - 1),
fg='yellow')
ctx.invoke(device_list)
raise click.Abort()
Expand All @@ -99,12 +111,11 @@ def main(ctx, config, device, args=None):
except (IndexError, ValueError):
report_errors('Invalid device number "{0}". '
'Choose between 0~{1}'.format(device,
len(found_devices)-1))
len(found_devices) - 1))
ctx.invoke(device_list)
raise click.Abort()



@main.command()
@click.argument("file_name")
@click.pass_context
Expand All @@ -124,7 +135,7 @@ def write(ctx, file_name):
click.echo("Reading configuration from: {0}".format(file_name))
cfg_pars.read_setting_from_file(file_name,
ignore_errors=False,
try_fix_errors=True)
try_fix_errors=False)

# And send changes to device
label = "Writing configuration to {0}".format(device.name)
Expand Down Expand Up @@ -177,5 +188,6 @@ def device_list(ctx):
click.echo(" Dev# {0} <{1}>".format(
i, found_devices[i].name))


if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions concon/config/logging_global.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ keys=time_name_lvl_msg,name_lvl_msg

[logger_root]
level=DEBUG
handlers=consoleHandler,LogFileHandler
qualname=UCA console
handlers=LogFileHandler
qualname=ConCon
propagate=0

[logger_Bridge_HW_uniprot]
level=DEBUG
handlers=consoleHandler,LogFileHandler
handlers=LogFileHandler
qualname=Bridge HW <---> uniprot
propagate=0

Expand All @@ -27,7 +27,7 @@ propagate=0

[logger_Bridge_config_parser]
level=DEBUG
handlers=consoleHandler,LogFileHandler
handlers=LogFileHandler
qualname=Bridge config parser
propagate=0

Expand Down
2 changes: 1 addition & 1 deletion concon/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ def set_from_file(self, file_name):
self._config['usb']['timeout'])
cfg_pars.read_setting_from_file(file_name,
ignore_errors=False,
try_fix_errors=True)
try_fix_errors=False)

cfg_pars.write_setting_to_device()
18 changes: 14 additions & 4 deletions concon/usb_driver/linux/usb_driver_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,18 @@ def usb_list_connected_devices(vid=None):
{'find_all': True, }
devices = []

for device in usb.core.find(**kwargs):
name = device.product or device.address
uid = device.bus * 0xff + device.address
devices.append((name, device.idVendor, device.idProduct, uid))
# Following may fail if user does not have sufficient rights
try:
for device in usb.core.find(**kwargs):
name = device.product or device.address
uid = device.bus * 0xff + device.address
devices.append((name, device.idVendor, device.idProduct, uid))
except ValueError as e:
msg = "{}\n\n"\
"It looks like you can not access USB devices."\
" Maybe insufficient rights?\n"\
"Please check if you can read/write to USB devices (refer to "\
"README file)"\
"".format(e)
raise Exception(msg)
return devices
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.9.5
current_version = 0.9.8
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

setup(
name='concon',
version='0.9.5',
version='0.9.8',
description="Universal configuration tool for USB devices implementing the Uniprot (HID) communication layer.",
long_description=readme + '\n\n' + history,
author="Martin Stejskal",
Expand Down

0 comments on commit 0bcc627

Please sign in to comment.