diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-09-30 20:36:47 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-10-08 16:41:10 +0200 |
commit | 35c75272aa44c33341c0b5228d762e7d9010401f (patch) | |
tree | 47b757fa06f0e745569fcaef59aaae172e6e9a9f /format.py | |
parent | 09556979d6499a3fac49f809a71ea0e5785272d0 (diff) | |
download | clufter-35c75272aa44c33341c0b5228d762e7d9010401f.tar.gz clufter-35c75272aa44c33341c0b5228d762e7d9010401f.tar.xz clufter-35c75272aa44c33341c0b5228d762e7d9010401f.zip |
command+format: move magic FDs handling command->format
...where it is probably a more natural fit.
Also, enable it for input file specs.
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'format.py')
-rw-r--r-- | format.py | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -21,7 +21,7 @@ from lxml import etree from .error import ClufterError from .plugin_registry import MetaPlugin, PluginRegistry from .protocol import Protocol -from .utils import arg2wrapped, args2tuple, args2unwrapped, \ +from .utils import arg2wrapped, args2sgpl, args2tuple, args2unwrapped, \ classproperty, \ head_tail, \ iterattrs, \ @@ -359,12 +359,27 @@ class SimpleFormat(Format, MetaPlugin): return outfile @classmethod - def io_decl_fd(cls, io_decl): - """Return file descriptor (int) if conforms to "magic file" or None""" + def io_decl_specials(cls, io_decl, in_mode, magic_fds): + """Special file decl. treatment: "magic files" + + Only return number if we've hit "magic file" (otherwise None). + """ + # turning @DIGIT+ magic files into fileobjs (needs global view) if tuplist(io_decl) and len(io_decl) >= 2 and io_decl[0] == cls.FILE: + # XXX handle also '-', but be careful about not duplicating? + # maybe even nothing should be duplicated at all? if io_decl[1].rstrip('0123456789') == '@': - return int(io_decl[1][1:]) - return None + fd = int(io_decl[1][1:]) + if fd not in magic_fds: + try: + magic_fds[fd] = fdopen(fd, 'r+b' if in_mode else 'ab') + except (OSError, IOError): + # keep untouched + pass + else: + io_decl = args2sgpl(io_decl[0], magic_fds[fd], + *io_decl[2:]) + return io_decl class CompositeFormat(Format, MetaPlugin): |