File indexing completed on 2024-05-12 17:18:07
0001 # -*- coding: UTF-8 -*- 0002 0003 """ 0004 Catalog clasification. 0005 0006 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net> 0007 @license: GPLv3 0008 """ 0009 0010 import os 0011 import re 0012 0013 0014 def get_project_subdir (catpath): 0015 """ 0016 Get canonical project subdirectory path for given catalog path. 0017 0018 @param catpath: catalog path 0019 @type catpath: string 0020 0021 @returns: project subdirectory path for this catalog 0022 @rtype: string 0023 """ 0024 0025 apath = os.path.abspath(catpath) 0026 up1dir = os.path.basename(os.path.dirname(apath)) 0027 up2dir = os.path.basename(os.path.dirname(os.path.dirname(apath))) 0028 if (not re.search(r"^(|doc|wiki)messages$", up2dir) 0029 ): 0030 subdir = None 0031 else: 0032 subdir = os.path.join(up2dir, up1dir) 0033 0034 return subdir 0035 0036 0037 def is_txt_cat (catname, subdir): 0038 """ 0039 Check whether the project catalog covers plain text sources. 0040 0041 @param catname: catalog domain name 0042 @type catname: string 0043 @param subdir: catalog project subdirectory 0044 @type subdir: string 0045 0046 @returns: C{True} if plain text catalog, C{False} otherwise 0047 @rtype: bool 0048 """ 0049 0050 up1dir = os.path.basename(subdir) 0051 if up1dir == "others": 0052 return False 0053 return (False 0054 or catname.startswith("desktop_") or catname.endswith("._desktop_") or (catname.endswith(".desktop") and not catname.endswith("org.kde.plasma.desktop")) 0055 or catname.startswith("json_") or catname.endswith("._json_") or catname.endswith(".json") 0056 or catname.startswith("xml_") or catname.endswith("._xml_") 0057 ) 0058 0059 0060 # - pure Qt 0061 _qt_catdirs = ( 0062 "qt", 0063 ) 0064 _qt_catnames = ( 0065 "kdgantt2", "kdgantt1", "kdgantt", 0066 ) 0067 _qt_catname_ends = ( 0068 "_qt", 0069 ) 0070 0071 def is_qt_cat (catname, subdir): 0072 """ 0073 Check whether the project catalog covers pure Qt sources. 0074 0075 @param catname: catalog domain name 0076 @type catname: string 0077 @param subdir: catalog project subdirectory 0078 @type subdir: string 0079 0080 @returns: C{True} if pure Qt catalog, C{False} otherwise 0081 @rtype: bool 0082 """ 0083 0084 up1dir = os.path.basename(subdir) 0085 if up1dir in _qt_catdirs: 0086 return True 0087 if catname in _qt_catnames: 0088 return True 0089 for end in _qt_catname_ends: 0090 if catname.endswith(end): 0091 return True 0092 return False 0093 0094 0095 def is_docbook_cat (catname, subdir): 0096 """ 0097 Check whether the project catalog covers Docbook sources. 0098 0099 @param catname: catalog domain name 0100 @type catname: string 0101 @param subdir: catalog project subdirectory 0102 @type subdir: string 0103 0104 @returns: C{True} if Docbook catalog, C{False} otherwise 0105 @rtype: bool 0106 """ 0107 0108 up2dir = os.path.basename(os.path.dirname(subdir)) 0109 0110 return (up2dir == "docmessages") 0111 0112 0113 def is_html_cat (catname, subdir): 0114 """ 0115 Check whether the project catalog covers HTML sources. 0116 0117 @param catname: catalog domain name 0118 @type catname: string 0119 @param subdir: catalog project subdirectory 0120 @type subdir: string 0121 0122 @returns: C{True} if HTML catalog, C{False} otherwise 0123 @rtype: bool 0124 """ 0125 0126 up1dir = os.path.basename(subdir) 0127 0128 return (up1dir == "www") 0129 0130 0131 def is_unknown_cat (catname, subdir): 0132 """ 0133 Check whether the project catalog covers unknown sources. 0134 0135 @param catname: catalog domain name 0136 @type catname: string 0137 @param subdir: catalog project subdirectory 0138 @type subdir: string 0139 0140 @returns: C{True} if unknown catalog, C{False} otherwise 0141 @rtype: bool 0142 """ 0143 0144 up1dir = os.path.basename(subdir) 0145 return up1dir == "others" 0146