Cleanup import in segments.common:

- move `import re` to top
- if import is in a `try` block and there is some processing before it and
  `except` move this to `else`.
Merge branch 'common-imports' into develop
Fix non-ASCII directories processing

Fixes #788
Merge branch 'fix-788' into develop