-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guinsly Mondesir
committed
Feb 10, 2016
1 parent
1b9a03a
commit 96fc2e0
Showing
5 changed files
with
145 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1 @@ | ||
import subprocess, json, os | ||
|
||
|
||
this_file_exist = lambda x: os.path.exists(filename) | ||
|
||
####HELPER section | ||
|
||
def command_line(cmd): | ||
try: | ||
s = subprocess.check_output(cmd) | ||
return s.strip() | ||
except subprocess.CalledProcessError: | ||
return 0 | ||
|
||
def information(filename): | ||
"""Returns the file exif""" | ||
result = get_json(filename) | ||
result = result[0] | ||
return result | ||
###################### | ||
|
||
def ver(): | ||
'''Retrieve the current version of exiftool installed on your computer | ||
''' | ||
s = command_line(["exiftool","-ver"]) | ||
if s: | ||
return s.split() | ||
else: | ||
return 0 | ||
|
||
def get_json(filename): | ||
'''Return a json value of the exif | ||
''' | ||
filename = os.path.abspath(filename) | ||
s = command_line(['exiftool', '-G', '-j', '-sort', filename]) | ||
if s: | ||
s = s.rstrip('\r\n') | ||
return json.loads(s) | ||
else: | ||
return 0 | ||
|
||
def get_csv(filename): | ||
'''Return a csv representation of the exif | ||
arg: filename | ||
''' | ||
filename = os.path.abspath(filename) | ||
s = command_line(['exiftool', '-G', '-csv', '-sort', filename]) | ||
if s: | ||
return s | ||
else: | ||
return 0 | ||
|
||
def get_xml(filename): | ||
'''Return a XML representation of the exif | ||
''' | ||
filename = os.path.abspath(filename) | ||
s = command_line(['exiftool', '-G', '-X', '-sort', filename]) | ||
if s: | ||
return s | ||
else: | ||
return 0 | ||
|
||
def fileType(filename): | ||
"""Returns the file extension""" | ||
result = information(filename) | ||
return result.get('File:FileType', 0) | ||
|
||
def mimeType(filename): | ||
"""Returns the file extension""" | ||
result = information(filename) | ||
return result.get('File:MIMEType', 0) | ||
|
||
def imageSize(filename): | ||
"""Returns the file size""" | ||
result = information(filename) | ||
return result.get('Composite:ImageSize', 0) | ||
|
||
def imageWidth(filename): | ||
"""Returns the file width""" | ||
result = information(filename) | ||
return result.get('PNG:ImageWidth', 0) | ||
|
||
def imageHeight(filename): | ||
"""Returns the file height""" | ||
result = information(filename) | ||
return result.get('PNG:imageHeight', 0) | ||
from .pyexifinfo import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import subprocess, json, os | ||
|
||
|
||
this_file_exist = lambda x: os.path.exists(filename) | ||
|
||
####HELPER section | ||
|
||
def command_line(cmd): | ||
"""Handle the command line call | ||
keyword arguments: | ||
cmd = a list | ||
return | ||
0 if error | ||
or a string for the command line output | ||
""" | ||
try: | ||
s = subprocess.check_output(cmd) | ||
return s.strip() | ||
except subprocess.CalledProcessError: | ||
return 0 | ||
|
||
def information(filename): | ||
"""Returns the file exif""" | ||
result = get_json(filename) | ||
result = result[0] | ||
return result | ||
###################### | ||
|
||
def ver(): | ||
'''Retrieve the current version of exiftool installed on your computer | ||
''' | ||
s = command_line(["exiftool","-ver"]) | ||
if s: | ||
return s.split() | ||
else: | ||
return 0 | ||
|
||
def get_json(filename): | ||
'''Return a json value of the exif | ||
''' | ||
filename = os.path.abspath(filename) | ||
s = command_line(['exiftool', '-G', '-j', '-sort', filename]) | ||
if s: | ||
#convert bytes to string | ||
s = s.decode('utf-8').rstrip('\r\n') | ||
return json.loads(s) | ||
else: | ||
return filename | ||
|
||
def get_csv(filename): | ||
'''Return a csv representation of the exif | ||
arg: filename | ||
''' | ||
filename = os.path.abspath(filename) | ||
s = command_line(['exiftool', '-G', '-csv', '-sort', filename]) | ||
if s: | ||
return s | ||
else: | ||
return 0 | ||
|
||
def get_xml(filename): | ||
'''Return a XML representation of the exif''' | ||
filename = os.path.abspath(filename) | ||
s = command_line(['exiftool', '-G', '-X', '-sort', filename]) | ||
if s: | ||
return s | ||
else: | ||
return 0 | ||
|
||
def fileType(filename): | ||
"""Returns the file extension""" | ||
result = information(filename) | ||
return result.get('File:FileType', 0) | ||
|
||
def mimeType(filename): | ||
"""Returns the file extension""" | ||
result = information(filename) | ||
return result.get('File:MIMEType', 0) | ||
|
||
def imageSize(filename): | ||
"""Returns the file size""" | ||
result = information(filename) | ||
return result.get('Composite:ImageSize', 0) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pyexifinfo import * | ||
import pyexifinfo as p | ||
import os | ||
|
||
# content of test_sample.py | ||
image = 'python-logo-master-v3-TM.png' | ||
def test_version_is_greater_than_8(): | ||
""" test the version is greater than 8 """ | ||
a = p.ver() | ||
#transforming bytes to string | ||
a = a[0].decode('utf-8') | ||
#transform string to float | ||
a = float(a) | ||
assert a >= 8 | ||
|
||
def test_get_json(): | ||
a = p.get_json(image) | ||
print('hello') | ||
assert len("sss") == 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pyexifinfo as p | ||
import os | ||
|
||
|
||
# content of test_sample.py | ||
image = 'python-logo-master-v3-TM.png' | ||
def test_version_is_greater_than_8(): | ||
""" test the version is greater than 8 """ | ||
a = p.ver() | ||
#transforming bytes to string | ||
a = a[0].decode('utf-8') | ||
#transform string to float | ||
a = float(a) | ||
assert a >= 8 | ||
|
||
def test_get_json(): | ||
a = p.get_json("tests/"+image) | ||
assert len(a[0]) == 25 | ||
|
||
def test_get_fileType(): | ||
a = p.fileType("tests/"+image) | ||
assert a.lower() == 'png' | ||
|
||
def test_get_mimeType(): | ||
a = p.mimeType("tests/"+image) | ||
assert a.lower() == 'image/png' | ||
|
||
def test_get_imageSize(): | ||
a = p.imageSize("tests/"+image) | ||
assert a.lower() == '601x203' | ||
|
||
def test_get_imageWidh(): | ||
a = p.imageWidth("tests/"+image) | ||
assert a == 601 | ||
|
||
def test_get_imageHeight(): | ||
a = p.imageHeight("tests/"+image) | ||
assert a == 203 |