Univention Bugzilla – Bug 41861
ucs-school-import: make interactive use of ucsschool-import easier
Last modified: 2016-10-04 13:24:48 CEST
Although it is possible to simply import and create ImportUser objects (in an interactive Python shell), they cannot simply be saved: --------------------------------------------------------- from ucsschool.importer.models.import_user import ImportStaff from ucsschool.importer.utils.ldap_connection import get_admin_connection lo, po = get_admin_connection() daniel = ImportStaff(name="Daniel", school="schule1") daniel.create(lo) → InitialisationError: Concrete factory not yet configured. --------------------------------------------------------- To make development, support and testing easier, a comfortable and configurable way to initialize the ucsschool-import system should be created.
A module was added. Production code is not effected. # This module initializes the ucsschool-import system and loads useful # classes to make working in an interactive Python shell easier. # It is NOT intended for production use! # To use the module simply import its content by running in a Python shell: # # >>> from ucsschool.importer.utils.shell import * # # Two ways exist to configure the system additionally to the default # configuration (same as with the import script): # * create (or symlink to) a JSON configuration file: ~/.import_shell_config # * store command line arguments in a JSON file in ~/.import_shell_args # python Python 2.7.3 (default, Jul 2 2014, 15:00:03) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from ucsschool.importer.utils.shell_config import * Reading configuration from '/usr/share/ucs-school-import/configs/global_defaults.json'... Reading configuration from '/var/lib/ucs-school-import/configs/global.json'... Reading configuration from '/usr/share/ucs-school-import/configs/user_import_defaults.json'... Reading configuration from '/var/lib/ucs-school-import/configs/user_import.json'... Reading configuration from '/root/.import_shell_config'... 2016-07-27 10:51:31 INFO cmdline.setup_logging:67 To change the loglevel, set UCRV ucsschool/logging/level/importer. 2016-07-27 10:51:31 INFO shell_config.<module>:35 ------ UCS@school import tool configured ------ 2016-07-27 10:51:31 INFO shell_config.<module>:36 Used configuration files: ['/usr/share/ucs-school-import/configs/global_defaults.json', '/var/lib/ucs-school-import/configs/global.json', '/usr/share/ucs-school-import/configs/user_import_defaults.json', '/var/lib/ucs-school-import/configs/user_import.json', '/root/.import_shell_config']. 2016-07-27 10:51:31 INFO shell_config.<module>:38 Using command line arguments: {u'dry_run': True, u'testarg': 42} 2016-07-27 10:51:31 INFO shell_config.<module>:39 Configuration is: {u'activate_new_users': {u'default': True}, u'classes': {}, u'csv': {u'header_lines': 1, u'incell-delimiter': {u'default': u','}, u'mapping': {}}, u'dry_run': True, u'factory': u'ucsschool.importer.default_user_import_factory.DefaultUserImportFactory', u'input': {u'filename': u'/var/lib/ucs-school-import/new-format-userimport.csv', u'type': u'csv'}, u'logfile': u'/var/log/univention/ucs-school-import.log', u'maildomain': None, u'mandatory_attributes': [u'firstname', u'lastname', u'name', u'school'], u'no_delete': False, u'output': {u'new_user_passwords': None, u'user_import_summary': u'/var/lib/ucs-school-import/user_import_summary_%Y-%m-%d_%H:%M:%S.csv'}, u'password_length': 15, u'scheme': {u'email': u'<firstname>[0].<lastname>@<maildomain>', u'recordUID': u'<email>', u'username': {u'allow_rename': False, u'default': u'<:umlauts><firstname>[0].<lastname><:lower>[COUNTER2]'}}, u'school': None, u'sourceUID': 'TestDB', u'testarg': 42, u'testarg2': False, u'testarg3': 43, u'tolerate_errors': 0, u'user_deletion': {u'delete': True, u'expiration': 0}, u'user_role': None, u'verbose': True} >>> dir() ['ImportStaff', 'ImportStudent', 'ImportTeacher', 'ImportTeachersAndStaff', 'ImportUser', '__builtins__', '__doc__', '__name__', '__package__', 'config', 'factory', 'json', 'lo', 'logger', 'os', 'pprint'] Code: 71263 YAML: 71264
r72508: added 90_ucsschool/108_import_shell to test if the setup created by the import works
Can you please mention everything what should be included by wildcard import in '*'. Otherwise the error messages occur with pyflakes and one might remove these "unused imports" in the future: shell.py:56: 'ImportUser' imported but unused shell.py:56: 'ImportTeacher' imported but unused shell.py:56: 'ImportStudent' imported but unused shell.py:56: 'ImportTeachersAndStaff' imported but unused shell.py:56: 'ImportStaff' imported but unused 108_import_shell:16: 'from ucsschool.importer.utils.shell import *' used; unable to detect undefined names
That is actually a problem of pyflakes not supporting exceptions (like pep8, pylint etc). r72656: added code to make pyflakes happy
(In reply to Daniel Tröder from comment #4) > That is actually a problem of pyflakes not supporting exceptions (like pep8, > pylint etc). > > r72656: added code to make pyflakes happy I disagree here. PEP8 says """ Wildcard imports ( from <module> import * ) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. There is one defensible use case for a wildcard import, which is to republish an internal interface as part of a public API (for example, overwriting a pure Python implementation of an interface with the definitions from an optional accelerator module and exactly which definitions will be overwritten isn't known in advance). """ As the only exception is not the case here this must not be used. Pyflakes/Flake8/pep8 is completely correct in what it says.
(In reply to Florian Best from comment #5) > (In reply to Daniel Tröder from comment #4) > > That is actually a problem of pyflakes not supporting exceptions (like pep8, > > pylint etc). > I disagree here. PEP8 says [..] > As the only exception is not the case here this must not be used. > Pyflakes/Flake8/pep8 is completely correct in what it says. Ah sorry - my comment was misleading. I didn't mean that wildcard imports should be used or such. Only that here is a case, where an exceptions would make sense: The ucs-test was _supposed_ to test the import exactly like it is documented, and that was with a wildcard. So for such a case, exceptions should be possible - and most checking programs support them.
OK: code OK: YAML
http://jenkins.knut.univention.de:8080/job/UCSschool%204.1/job/UCSschool%204.1%20(R2)%20Multiserver/lastCompletedBuild/SambaVersion=s4-only-master/testReport/90_ucsschool/108_import_shell/test/ (2016-09-22 19:50:43.700773) Traceback (most recent call last): (2016-09-22 19:50:43.700908) File "108_import_shell", line 33, in <module> (2016-09-22 19:50:43.700984) main() (2016-09-22 19:50:43.701029) File "108_import_shell", line 30, in main (2016-09-22 19:50:43.701099) logger("Test was successful.\n\n\n") (2016-09-22 19:50:43.701199) TypeError: 'Logger' object is not callable
Already fixed that morning in r72768.
(In reply to Daniel Tröder from comment #9) > Already fixed that morning in r72768. Yes, okay.
UCS@school 4.1 R2 v5 has been released. http://docs.software-univention.de/changelog-ucsschool-4.1R2v5-de.html If this error occurs again, please clone this bug.