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 54 55 56 57 58 59 60
| import sys
from pathlib import Path
PapaIcon = {"application" : "application-x-executable", "video" : "video-x-generic","text" : "text-x-generic", "image" : "image-x-generic", "package" : "package-x-generic", "audio" : "audio-x-generic"}
def Coco(MimeType):
Icon = ""
SubClass = ""
Alias = ""
Link = Path("/usr/share/mime/", MimeType)
Text = ""
if Link.exists():
with Link.open() as MimeTypeFile:
for Line in MimeTypeFile:
if "generic-icon name" in Line:
Icon = Line.split('"')[1]
elif "sub-class-of" in Line:
SubClass = Line.split('"')[1]
elif "alias type" in Line:
Alias = Line.split('"')[1]
if Icon:
print("Icone de {} : {}".format(Link.name, Icon))
elif SubClass:
SubClassLink = Path(Link.parents[1], SubClass + ".xml")
print(MimeType, "est une sous classe de", SubClassLink)
Coco(SubClassLink)
else:
with Path("/usr/share/mime/generic-icons").open() as IconsFile:
for Line in IconsFile:
if MimeType in Line:
Icon = Line.split(":")[1]
if Icon:
print("Icone generique de {} : {}".format(Link.name, Icon))
else:
try:
papa = MimeType.split("/")[0]
print("utilisation de l'icone du papa :", PapaIcon[papa])
except:
print("aucune icone trouvée !")
else:
# Ce doit être un alias
with Path("/usr/share/mime/aliases").open() as AliasesFile:
for Line in AliasesFile:
a, b = Line.split(" ")
if MimeType == a:
Alias = Line.split(" ")[1].replace('\n','') + ".xml"
if Alias:
print(MimeType, "est un alias de", Alias)
Coco(Alias)
else:
print(MimeType, "n'existe pas et n'est pas un alias...") |
Partager