Skip to content

Commit

Permalink
Call GrFormat only if file is actually binary
Browse files Browse the repository at this point in the history
  • Loading branch information
marioba committed Sep 29, 2019
1 parent 8b54dd8 commit 4893e61
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions comptages/comptages.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,12 @@ def do_import_files_action(self):
def import_file(self, file_path, count_id=None):

# Manage binary files
extension = os.path.splitext(file_path)[1]
if extension.startswith('.i'):
file_path_formatted = list(file_path)
file_path_formatted[-3] = 'a'
file_path_formatted = "".join(file_path_formatted)
os.system("GrFromat.exe {} {}".format(
file_path, file_path_formatted))
file_path = file_path_formatted
elif extension.startswith('.V'):
file_path_formatted = list(file_path)
file_path_formatted[-3] = 'a'
file_path_formatted[-2] = 'V'
file_path_formatted = "".join(file_path_formatted)
with open(file_path, 'rb') as fd:
file_head = fd.read(24)

if file_head == b'Golden River Traffic Ltd': # is a binary file

file_path_formatted = "{}_for".format(file_path)
os.system("GrFromat.exe {} {}".format(
file_path, file_path_formatted))
file_path = file_path_formatted
Expand Down

3 comments on commit 4893e61

@spch-GL
Copy link
Contributor

@spch-GL spch-GL commented on 4893e61 Oct 4, 2019

Choose a reason for hiding this comment

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

A la ligne 208, tu as oublié d'utiliser l'info provenant de model/formatter_name

@marioba
Copy link
Contributor Author

@marioba marioba commented on 4893e61 Oct 4, 2019

Choose a reason for hiding this comment

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

Il y a un problème. Si on utilise l'outil générique "importation" et non l'"importation single file", avant de convertir le fichier binaire, je ne peux pas savoir à quel comptage il se rapporte et donc je ne peux pas connaître le modèle utilisé.

Une possibilité serait de lire l'en-tête du fichier binaire qui contient quelque chose comme Golden River Traffic Ltd\r\nMarksman 660 compatible data file, mais pas le modèle exact et donc avec la table model actuelle on ne peut pas faire une query exacte.

@spch-GL
Copy link
Contributor

@spch-GL spch-GL commented on 4893e61 Oct 4, 2019

Choose a reason for hiding this comment

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

Ok, je comprend. On peut alors mettre l'info dans la table brand, car c'est identique pour tous nos modèles

Please sign in to comment.