Skip to content

Commit

Permalink
0.3.2 fix select() for windows, and now all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
sylikc committed Jul 19, 2019
1 parent b8a1ce2 commit 03a8595
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Date (Timezone) | Version | Comment
07/18/2019 04:14:32 AM (PDT) | 0.1.9 | Merge the test cases from the [Pull request #5 "add set_tags_batch, set_tags + constructor takes added options"](https://github.com/smarnach/pyexiftool/pull/5) by [halloleo](https://github.com/halloleo) on Aug 1, 2012
07/18/2019 04:34:46 AM (PDT) | 0.3.0 | changed the setup.py licensing and updated the version numbering as in changelog<br>changed the version number scheme, as it appears the "official last release" was 0.2.0 tagged. There's going to be a lot of things broken in this current build, and I'll fix it as they come up. I'm going to start playing with the library and the included tests and such. <br>There's one more pull request #11 which would be pending, but it duplicates the extra arguments option. <br>I'm also likely to remove the print conversion as it's now covered by the extra args. I'll also rename some variable names with the addedargs patch<br>**for my changes (sylikc), I can only guarantee they will work on Python 3.7, because that's my environment... and while I'll try to maintain compatibility, there's no guarantees**
07/18/2019 05:06:19 AM (PDT) | 0.3.1 | make some minor tweaks to the naming of the extra args variable. The other pull request 11 names them params, and when I decide how to merge that pull request, I'll probably change the variable names again.

07/19/2019 12:01:22 AM (PTD) | 0.3.2 | fix the select() problem for windows, and fix all tests


# Changes around the web
Expand Down
28 changes: 18 additions & 10 deletions exiftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,23 @@ def execute(self, *params):
if not self.running:
raise ValueError("ExifTool instance not running.")
cmd_text = b"\n".join(params + (b"-execute\n",))
self._process.stdin.write(cmd_text.encode("utf-8")) # a commit reverted this to the original where it's not encoded in UTF-8, will see if there are conflicts later
# cmd_text.encode("utf-8") # a commit put this in the next line, but i can't get it to work TODO
# might look at something like this https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3
self._process.stdin.write(cmd_text)
self._process.stdin.flush()
output = b""
fd = self._process.stdout.fileno()
while not output[-32:].strip().endswith(sentinel):
#output += os.read(fd, block_size)

# not sure if this works on windows
inputready,outputready,exceptready = select.select([fd],[],[])
for i in inputready:
if i == fd:
output += os.read(fd, block_size)
if sys.platform == 'win32':
# windows does not support select() for anything except sockets
# https://docs.python.org/3.7/library/select.html
output += os.read(fd, block_size)
else:
# this does NOT work on windows... and it may not work on other systems... in that case, put more things to use the original code above
inputready,outputready,exceptready = select.select([fd],[],[])
for i in inputready:
if i == fd:
output += os.read(fd, block_size)
return output.strip()[:-len(sentinel)]

def execute_json(self, *params):
Expand Down Expand Up @@ -486,7 +491,8 @@ def set_keywords_batch(self, mode, keywords, filenames):
raise TypeError("The argument 'filenames' must be "
"an iterable of strings")

params = []
params = []
params_utf8 = []

kw_operation = {KW_REPLACE:"-%s=%s",
KW_ADD:"-%s+=%s",
Expand All @@ -497,7 +503,9 @@ def set_keywords_batch(self, mode, keywords, filenames):
params.extend(kw_params)
params.extend(filenames)
logging.debug (params)
return self.execute(*params)

params_utf8 = [x.encode('utf-8') for x in params]
return self.execute(*params_utf8)

def set_keywords(self, mode, keywords, filename):
"""Modifies the keywords tag for the given file.
Expand Down
2 changes: 1 addition & 1 deletion test/test_exiftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class TestExifTool(unittest.TestCase):
def setUp(self):
self.et = exiftool.ExifTool(addedargs=["-overwrite_original"])
self.et = exiftool.ExifTool(added_args=["-overwrite_original"])
def tearDown(self):
if hasattr(self, "et"):
self.et.terminate()
Expand Down

0 comments on commit 03a8595

Please sign in to comment.