-
Notifications
You must be signed in to change notification settings - Fork 0
/
funct.py
53 lines (49 loc) · 1.89 KB
/
funct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3
#-*- coding: utf-8 -*-
#
#Copyright pops (pops451@gmail.com), 2010-2011
#
#This file is part of imagemash.
#
# imagemash is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# imagemash is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with imagemash. If not, see <http://www.gnu.org/licenses/>.
import os
import re
def return_new_filename(orifn, fn, incr=1):
""" return filename after processing
replaces %F by the original filename
replaces %E by the original extension
replaces %III... by an increment """
fn = fn.replace('%F', os.path.splitext(orifn)[0])
fn = fn.replace('%E', os.path.splitext(orifn)[1])
for i in reversed(range(1, 15)):
if re.search("%I{" + str(i) + "}", fn):
fn = fn.replace("%"+("I"*i), str(incr).zfill(i))
return fn
def verif_images(url):
""" verify that the url is a file and that the file is an image """
images = []
for i in url:
ext = os.path.splitext(i) [1].lower()
if (os.path.isfile(i) and
(ext == ".png" or ext == ".gif" or
ext == ".jpg" or ext == ".jpeg" or
ext == ".tif" or ext == ".tiff")):
images.append(i)
images.sort()
return images
if __name__=="__main__":
fichiers = [os.path.join("test/imgs", i)
for i in os.listdir("test/imgs")]
print(verif_images(fichiers))
print(return_new_filename("truc.bidule", "%Fmachin%E%IIII", 34))