Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rickskyy
Copy link
Collaborator

This PR includes:

  1. VersionConverter and DirectoryParser classes for converting all suitable .xml files in the directory with subdirectories into version 1.1 .xml files.
  2. Converted files from gin repo. The files include original files from gin, updated xmls and respective odmls generated by the parser.
  3. Changes to .gitignore for adding .odml files.

Copy link
Contributor

@mpsonntag mpsonntag left a 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.

def __init__(self):
self.doc = None

def convert_directory(self, directory_path, suffix, extension):
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

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'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical if clause

# 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'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical if clause

"""
Fix an xml file by deleting known mismatching tags
"""
changes_list = []
Copy link
Contributor

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)

Copy link
Collaborator Author

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)


# Write the changed content, if found in the file
with open(filename, 'w') as f:
for str in changes_list:
Copy link
Contributor

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.

@jgrewe jgrewe mentioned this pull request Jul 25, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-6.6%) to 72.15% when pulling e988bca on rickskyy:version-converter into ecad40e on G-Node:dev-odml-rdf.

@rickskyy rickskyy force-pushed the version-converter branch from e988bca to 10ef0a7 Compare July 28, 2017 01:43
@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.794% when pulling 10ef0a7 on rickskyy:version-converter into ecad40e on G-Node:dev-odml-rdf.

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.6%) to 72.15% when pulling 2665ce2 on rickskyy:version-converter into ecad40e on G-Node:dev-odml-rdf.

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)
Copy link
Member

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

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.6%) to 72.15% when pulling ed50236 on rickskyy:version-converter into ecad40e on G-Node:dev-odml-rdf.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.4%) to 76.384% when pulling 7d1fd8a on rickskyy:version-converter into ecad40e on G-Node:dev-odml-rdf.

@jgrewe jgrewe merged commit 6b8635a into G-Node:dev-odml-rdf Aug 7, 2017
@rickskyy rickskyy deleted the version-converter branch August 7, 2017 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants