Discard python 2.7 compatibility

This commit is contained in:
Cédric Leporcq 2021-04-17 17:00:39 +02:00
parent 0363fd4302
commit 21ed551a54
29 changed files with 9 additions and 100 deletions

View File

@ -1,6 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
import os import os
import re import re
import sys import sys
@ -36,9 +35,6 @@ from elodie import constants
FILESYSTEM = FileSystem() FILESYSTEM = FileSystem()
def import_file(_file, destination, album_from_folder, trash, allow_duplicates): def import_file(_file, destination, album_from_folder, trash, allow_duplicates):
_file = _decode(_file)
destination = _decode(destination)
"""Set file metadata and move it to destination. """Set file metadata and move it to destination.
""" """

View File

@ -30,51 +30,3 @@ def _bytes(string):
else: else:
return bytes(string) return bytes(string)
def _copyfile(src, dst):
# shutil.copy seems slow, changing to streaming according to
# http://stackoverflow.com/questions/22078621/python-how-to-copy-files-fast # noqa
# Python 3 hangs using open/write method so we proceed with shutil.copy
# and only perform the optimized write for Python 2.
if (constants.python_version == 3):
# Do not use copy2(), it will have an issue when copying to a
# network/mounted drive.
# Using copy and manual set_date_from_filename gets the job done.
# The calling function is responsible for setting the time.
shutil.copy(src, dst)
return
try:
O_BINARY = os.O_BINARY
except:
O_BINARY = 0
READ_FLAGS = os.O_RDONLY | O_BINARY
WRITE_FLAGS = os.O_WRONLY | os.O_CREAT | os.O_TRUNC | O_BINARY
TEN_MEGABYTES = 10485760
BUFFER_SIZE = min(TEN_MEGABYTES, os.path.getsize(src))
try:
fin = os.open(src, READ_FLAGS)
stat = os.fstat(fin)
fout = os.open(dst, WRITE_FLAGS, stat.st_mode)
for x in iter(lambda: os.read(fin, BUFFER_SIZE), ""):
os.write(fout, x)
finally:
try:
os.close(fin)
except:
pass
try:
os.close(fout)
except:
pass
# If you want cross-platform overwriting of the destination,
# use os.replace() instead of rename().
# https://docs.python.org/3/library/os.html#os.rename
def _rename(src, dst):
if (constants.python_version == 3):
return os.replace(src, dst)
else:
return os.rename(src, dst)

View File

@ -2,7 +2,6 @@
Helpers for checking for an interacting with external dependencies. These are Helpers for checking for an interacting with external dependencies. These are
things that Elodie requires, but aren't installed automatically for the user. things that Elodie requires, but aren't installed automatically for the user.
""" """
from __future__ import print_function
import os import os
import sys import sys

View File

@ -55,8 +55,6 @@ Example usage::
d["EXIF:DateTimeOriginal"])) d["EXIF:DateTimeOriginal"]))
""" """
from __future__ import unicode_literals
import sys import sys
import subprocess import subprocess
import os import os
@ -65,7 +63,6 @@ import warnings
import logging import logging
import codecs import codecs
from future.utils import with_metaclass
try: # Py3k compatibility try: # Py3k compatibility
basestring basestring
@ -162,7 +159,7 @@ class Singleton(type):
cls.instance = super(Singleton, cls).__call__(*args, **kwargs) cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls.instance return cls.instance
class ExifTool(object, with_metaclass(Singleton)): class ExifTool(object, metaclass=Singleton):
"""Run the `exiftool` command-line tool and communicate to it. """Run the `exiftool` command-line tool and communicate to it.
You can pass two arguments to the constructor: You can pass two arguments to the constructor:

View File

@ -3,7 +3,6 @@ General file system methods.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
from builtins import object from builtins import object
import os import os
@ -12,7 +11,6 @@ import shutil
import time import time
from datetime import datetime from datetime import datetime
from elodie import compatability
from elodie import geolocation from elodie import geolocation
from elodie import log from elodie import log
from elodie.config import load_config from elodie.config import load_config

View File

@ -1,10 +1,6 @@
"""Look up geolocation information for media objects.""" """Look up geolocation information for media objects."""
from __future__ import print_function
from __future__ import division
from future import standard_library
from past.utils import old_div from past.utils import old_div
standard_library.install_aliases() # noqa
from os import path from os import path

View File

@ -3,7 +3,6 @@ General file system methods.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
import sys import sys

View File

@ -5,7 +5,6 @@ class.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import absolute_import
from .video import Video from .video import Video

View File

@ -8,7 +8,6 @@ are used to represent the actual files.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
import os import os
import six import six

View File

@ -4,8 +4,6 @@ image objects (JPG, DNG, etc.).
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
from __future__ import absolute_import
import imghdr import imghdr
import os import os

View File

@ -4,9 +4,6 @@ objects (AVI, MOV, etc.).
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
# load modules # load modules
from datetime import datetime from datetime import datetime

View File

@ -3,7 +3,6 @@ Dummy plugin object used for tests.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
from elodie.plugins.plugins import PluginBase from elodie.plugins.plugins import PluginBase

View File

@ -19,7 +19,6 @@ Upload code adapted from https://github.com/eshmu/gphotos-upload
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
import json import json

View File

@ -3,7 +3,6 @@ Plugin object.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
from builtins import object from builtins import object
import io import io

View File

@ -3,7 +3,6 @@ RuntimeError plugin object used for tests.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
from elodie.plugins.plugins import PluginBase from elodie.plugins.plugins import PluginBase

View File

@ -3,7 +3,6 @@ ThrowError plugin object used for tests.
.. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com> .. moduleauthor:: Jaisen Mathai <jaisen@jmathai.com>
""" """
from __future__ import print_function
from elodie.plugins.plugins import PluginBase, ElodiePluginError from elodie.plugins.plugins import PluginBase, ElodiePluginError

View File

@ -1,4 +1,3 @@
from __future__ import print_function
import os import os
import re import re

View File

@ -1,7 +1,6 @@
click==6.6 click==6.6
requests==2.20.0 requests==2.20.0
Send2Trash==1.3.0 Send2Trash==1.3.0
future==0.16.0
configparser==3.5.0 configparser==3.5.0
tabulate==0.7.7 tabulate==0.7.7
Pillow==6.2.2; python_version == '2.7' Pillow==6.2.2; python_version == '2.7'

View File

@ -1,4 +1,3 @@
from __future__ import absolute_import
# Project imports # Project imports
import os import os

View File

@ -1,14 +1,13 @@
from __future__ import absolute_import # # Project imports
# Project imports
import os # import os
import sys # import sys
import unittest # import unittest
try: # try:
reload # Python 2.7 # reload # Python 2.7
except NameError: # except NameError:
try: # try:
from importlib import reload # Python 3.4+ from importlib import reload # Python 3.4+
except ImportError: except ImportError:
from imp import reload # Python 3.0 - 3.3 from imp import reload # Python 3.0 - 3.3

View File

@ -1,4 +1,3 @@
from __future__ import absolute_import
# Project imports # Project imports
import mock import mock
import os import os

View File

@ -1,5 +1,3 @@
from __future__ import division
from __future__ import unicode_literals
from builtins import range from builtins import range
from past.utils import old_div from past.utils import old_div
import hashlib import hashlib
@ -14,7 +12,6 @@ import urllib
from datetime import datetime from datetime import datetime
from datetime import timedelta from datetime import timedelta
from elodie.compatability import _rename
from elodie.external.pyexiftool import ExifTool from elodie.external.pyexiftool import ExifTool
from elodie.dependencies import get_exiftool from elodie.dependencies import get_exiftool
from elodie import constants from elodie import constants

View File

@ -1,5 +1,3 @@
from __future__ import print_function
from __future__ import absolute_import
# Project imports # Project imports
import os import os
import sys import sys

View File

@ -1,4 +1,3 @@
from __future__ import absolute_import
# Project imports # Project imports
import os import os

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 # -*- coding: utf-8
# Project imports # Project imports
from __future__ import print_function
import os import os
import sys import sys

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 # -*- coding: utf-8
# Project imports # Project imports
from __future__ import unicode_literals
import os import os
import sys import sys

View File

@ -1,4 +1,3 @@
from __future__ import absolute_import
# Project imports # Project imports
import mock import mock
import os import os

View File

@ -1,4 +1,3 @@
from __future__ import absolute_import
# Project imports # Project imports
import mock import mock
import os import os

View File

@ -1,4 +1,3 @@
from __future__ import absolute_import
# Project imports # Project imports
import os import os