diff options
| author | jvoisin | 2011-07-22 11:16:41 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-22 11:16:41 +0200 |
| commit | 66bf68ea7f0f1abcd4c22d63f71ddfec6aa21561 (patch) | |
| tree | 30b9149c13d10b5d63bf58d35b1038a917af9cbe /lib/parser.py | |
| parent | 33e0d44142f185bc197f7258c8146c187ee563cf (diff) | |
Cleanup
Diffstat (limited to 'lib/parser.py')
| -rw-r--r-- | lib/parser.py | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/lib/parser.py b/lib/parser.py index 6e6ee34..9d523c0 100644 --- a/lib/parser.py +++ b/lib/parser.py | |||
| @@ -17,10 +17,10 @@ POSTFIX = ".cleaned" | |||
| 17 | 17 | ||
| 18 | class Generic_parser(object): | 18 | class Generic_parser(object): |
| 19 | def __init__(self, realname, filename, parser, editor, backup, add2archive): | 19 | def __init__(self, realname, filename, parser, editor, backup, add2archive): |
| 20 | self.filename = filename | 20 | self.filename = filename #path + filename |
| 21 | self.realname = realname | 21 | self.realname = realname #path + filename |
| 22 | self.shortname = os.path.basename(filename) | 22 | self.shortname = os.path.basename(filename) #only filename |
| 23 | self.mime = mimetypes.guess_type(filename)[0] | 23 | self.mime = mimetypes.guess_type(filename)[0] #mimetype |
| 24 | self.parser = parser | 24 | self.parser = parser |
| 25 | self.editor = editor | 25 | self.editor = editor |
| 26 | self.backup = backup | 26 | self.backup = backup |
| @@ -44,7 +44,7 @@ class Generic_parser(object): | |||
| 44 | hachoir_core.field.writeIntoFile(self.editor, self.filename + POSTFIX) | 44 | hachoir_core.field.writeIntoFile(self.editor, self.filename + POSTFIX) |
| 45 | if self.backup is False: | 45 | if self.backup is False: |
| 46 | mat.secure_remove(self.filename) #remove the old file | 46 | mat.secure_remove(self.filename) #remove the old file |
| 47 | os.rename(self.filename+ POSTFIX, self.filename)#rename the new | 47 | os.rename(self.filename+ POSTFIX, self.filename) #rename the new |
| 48 | 48 | ||
| 49 | def remove_all_ugly(self): | 49 | def remove_all_ugly(self): |
| 50 | ''' | 50 | ''' |
| @@ -52,34 +52,17 @@ class Generic_parser(object): | |||
| 52 | this method is implemented : | 52 | this method is implemented : |
| 53 | It is efficient, but destructive. | 53 | It is efficient, but destructive. |
| 54 | In a perfect world, with nice fileformat, | 54 | In a perfect world, with nice fileformat, |
| 55 | this method does not exist. | 55 | this method would not exist. |
| 56 | ''' | 56 | ''' |
| 57 | self.remove_all() | 57 | self.remove_all() |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | def _remove(self, field): | 60 | def _remove(self, field): |
| 61 | ''' | 61 | ''' |
| 62 | Remove the given field | 62 | Delete the given field |
| 63 | ''' | 63 | ''' |
| 64 | del self.editor[field.name] | 64 | del self.editor[field.name] |
| 65 | 65 | ||
| 66 | def search(self, value): | ||
| 67 | return self.__search(value, self.editor) | ||
| 68 | |||
| 69 | def __search(self, value, graph): | ||
| 70 | ''' | ||
| 71 | Search a given file | ||
| 72 | ''' | ||
| 73 | for node in graph: | ||
| 74 | try: | ||
| 75 | iter(node) | ||
| 76 | return node.value + self.__search(value, node) | ||
| 77 | except: | ||
| 78 | if node.name == value: | ||
| 79 | return value | ||
| 80 | return False | ||
| 81 | |||
| 82 | |||
| 83 | def get_meta(self): | 66 | def get_meta(self): |
| 84 | ''' | 67 | ''' |
| 85 | return a dict with all the meta of the file | 68 | return a dict with all the meta of the file |
