-
Notifications
You must be signed in to change notification settings - Fork 30
Version converter #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Version converter #120
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move version_converter.py to odml/tools/ and remove the empty doc/gin_files/__init__.py.
doc/gin_files/version_converter.py
Outdated
| def __init__(self): | ||
| self.doc = None | ||
|
|
||
| def convert_directory(self, directory_path, suffix, extension): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of suffix is a bit unclear to me. If I interpret correctly: With it, the user is given the choice of how the folder containing the result files should be suffixed with. But only if the suffix is literally _updated or _odmls, then these folders will be excluded from a second round of conversion, if it is run again. If the suffix is any other string, a second conversion will include these result files as well. Maybe we should either allow only _updated or _odmls as valid suffix strings or explicitly tell the user in the docstring, what can happen if a different suffix is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My implementation should be discussed even more precisely. I agree that suffix is smth that is really unclear and I plan to rewrite this a little bit.
doc/gin_files/version_converter.py
Outdated
| for file_name in file_names: | ||
| if ("_updated" or "_odmls") not in dir_path and extension == ".xml": | ||
| file_path = os.path.join(dir_path, file_name) | ||
| if file_path.endswith('.xml') or file_path.endswith('.xml'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical if clause
doc/gin_files/version_converter.py
Outdated
| # converting validated xmls in "./{directory}_updated | ||
| elif "_updated" in dir_path and extension == ".odml": | ||
| file_path = os.path.join(dir_path, file_name) | ||
| if file_path.endswith('.xml') or file_path.endswith('.xml'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical if clause
doc/gin_files/version_converter.py
Outdated
| """ | ||
| Fix an xml file by deleting known mismatching tags | ||
| """ | ||
| changes_list = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace the function body with a more condensed code (hope I got it right) ;)
changes = False
with open(filename, 'r+') as f:
doc = f.read()
for k, v in VersionConverter._error_strings.items():
if k in doc:
doc = doc.replace(k, VersionConverter._error_strings[k])
changes = True
if changes:
f.truncate(0)
f.write(doc)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you got it right, I tested it. Nice suggestion)
doc/gin_files/version_converter.py
Outdated
|
|
||
| # Write the changed content, if found in the file | ||
| with open(filename, 'w') as f: | ||
| for str in changes_list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try avoiding to shadow built-in keywords.
Merge pull request G-Node#121 from rickskyy/dev-odml-rdf
e988bca to
10ef0a7
Compare
| parser.add_argument("result_format", choices=['v1_1', 'odml'], help="Format of output files") | ||
| parser.add_argument("-out", "--output_dir", help="Path for output directory") | ||
| parser.add_argument("-sub", "--subdirs", action="store_true", help="Enable converting files from subdirectories") | ||
| args = parser.parse_args(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use -r for recursive operations
This PR includes: