7 from fnmatch
import fnmatch
30 FORMAT =
'%(asctime)s %(levelname)s %(message)s' 31 logging.basicConfig(format=FORMAT, datefmt=
'%H:%M:%S', level=logging.DEBUG)
35 """ Return a list based on `a`. """ 36 return a
if type(a)
is list
else [a]
40 """ Return a serialized name. 42 For now it only replaces ' ' with '_' and lower the letters. 45 return '_'.join(name.lower().split(
' '))
50 """ Return the repopath for the repo id, queried from projects.kde.org 53 id: unique KDE repo identifier 59 r = requests.get(
'https://projects.kde.org/api/v1/identifier/' + id)
60 return r.json()[
'repo']
61 except Exception
as exc:
64 logging.warning(
"Failed to get repository url for '{}' from projects.kde.org: {}".format(id, exc))
68 """ Expend the name of the maintainers. 71 dictionary: (dict) Dictionary from which the name to expend will be read. 72 key: (string) Key of the dictionary where the name to expend is saved. 73 all_maintainers: (dict of dict) Look-up table where the names and emails of 74 the maintainers are stored. 77 >>> maintainer_keys = ['arthur', 'toto'] 79 >>> myteam = {'arthur': {'name': 'Arthur Pendragon', 80 'email': '[email protected]'}, 81 'toto': {'name': 'Toto', 82 'email: '[email protected]'} 85 >>> set_maintainers(maintainer_keys, my_team) 88 if not maintainer_keys:
90 elif isinstance(maintainer_keys, list):
91 maintainers = map(
lambda x: all_maintainers.get(x,
None),
94 maintainers = [all_maintainers.get(maintainer_keys,
None)]
96 maintainers = [x
for x
in maintainers
if x
is not None]
101 """Return the framework name for a given source dir 103 The framework name is the name of the toplevel CMake project 105 cmakelists_path = os.path.join(fw_dir,
"CMakeLists.txt")
106 if not os.path.exists(cmakelists_path):
107 logging.error(
"No CMakeLists.txt in {}".format(fw_dir))
109 project_re = re.compile(
r"project\s*\(\s*([\w\-\_]+)", re.I)
110 with open(cmakelists_path)
as f:
111 for line
in f.readlines():
112 match = project_re.search(line)
114 return match.group(1)
115 logging.error(
"Failed to find framework name: Could not find a " 116 "'project()' command in {}.".format(cmakelists_path))
121 """Find/create a semi-long-term cache directory. 123 We do not use tempdir, except as a fallback, because temporary directories 124 are intended for files that only last for the program's execution. 127 if sys.platform ==
'darwin':
129 from AppKit
import NSSearchPathForDirectoriesInDomains
134 cachedir = os.path.join(
135 NSSearchPathForDirectoriesInDomains(14, 1,
True)[0],
139 elif os.name ==
"posix":
140 if 'HOME' in os.environ
and os.path.exists(os.environ[
'HOME']):
141 cachedir = os.path.join(os.environ[
'HOME'],
'.cache',
'kapidox')
142 elif os.name ==
"nt":
143 if 'APPDATA' in os.environ
and os.path.exists(os.environ[
'APPDATA']):
144 cachedir = os.path.join(os.environ[
'APPDATA'],
'KApiDox')
146 cachedir = os.path.join(tempfile.gettempdir(),
'kapidox')
147 if not os.path.isdir(cachedir):
148 os.makedirs(cachedir)
152 def svn_export(remote, local, overwrite=False):
156 remote: (string) the remote url. 157 local: (string) the local path where to dowload. 158 overwrite: (bool) whether to overwrite `local` or not. (optional, 165 FileNotFoundError: 166 subprocess.CalledProcessError: 171 logging.debug(
"Using Python libsvn bindings to fetch %s", remote)
172 ctx = svn.client.create_context()
173 ctx.auth_baton = svn.core.svn_auth_open([])
175 latest = svn.core.svn_opt_revision_t()
176 latest.type = svn.core.svn_opt_revision_head
178 svn.client.export(remote, local, latest,
True, ctx)
180 logging.debug(
"Using external svn client to fetch %s", remote)
181 cmd = [
'svn',
'export',
'--quiet']
183 cmd.append(
'--force')
184 cmd += [remote, local]
186 subprocess.check_call(cmd, stderr=subprocess.STDOUT)
187 except subprocess.CalledProcessError
as e:
188 raise subprocess.StandardException(e.output)
189 except FileNotFoundError
as e:
190 logging.debug(
"External svn client not found")
193 os.utime(local,
None)
198 """Copy the contents of a directory 201 directory: (string) the directory to copy the contents of. 202 dest: (string) the directory to copy them into. 204 ignored = [
'CMakeLists.txt']
205 ignore = shutil.ignore_patterns(*ignored)
206 for fn
in os.listdir(directory):
207 f = os.path.join(directory, fn)
208 if os.path.isfile(f):
216 elif os.path.isdir(f):
217 dest_f = os.path.join(dest, fn)
218 if os.path.isdir(dest_f):
219 shutil.rmtree(dest_f)
220 shutil.copytree(f, dest_f, ignore=ignore)
223 _KAPIDOX_VERSION =
None 225 """Get commit id of running code if it is running from git repository. 227 May return an empty string if it failed to extract the commit id. 229 Assumes .git/HEAD looks like this: 231 ref: refs/heads/master 233 and assumes .git/refs/heads/master contains the commit id 235 global _KAPIDOX_VERSION
237 if _KAPIDOX_VERSION
is not None:
238 return _KAPIDOX_VERSION
240 _KAPIDOX_VERSION =
"" 241 bin_dir = os.path.dirname(sys.argv[0])
242 git_dir = os.path.join(bin_dir,
"..",
".git")
243 if not os.path.isdir(git_dir):
245 return _KAPIDOX_VERSION
247 git_HEAD = os.path.join(git_dir,
"HEAD")
248 if not os.path.isfile(git_HEAD):
249 logging.warning(
"Getting git info failed: {} is not a file".format(git_HEAD))
250 return _KAPIDOX_VERSION
253 line = open(git_HEAD).readline()
254 ref_name = line.split(
": ")[1].strip()
255 with open(os.path.join(git_dir, ref_name))
as f:
256 _KAPIDOX_VERSION = f.read().strip()
257 except Exception
as exc:
260 logging.warning(
"Getting git info failed: {}".format(exc))
261 return _KAPIDOX_VERSION
265 """Returns a list of path to files ending with .dot in subdirs of `dot_dir`.""" 267 for (root, dirs, files)
in os.walk(dot_dir):
268 lst.extend([os.path.join(root, x)
for x
in files
if x.endswith(
'.dot')])
def serialize_name(name)
Return a serialized name.
def parse_fancyname(fw_dir)
Return the framework name for a given source dir.
def find_dot_files(dot_dir)
Returns a list of path to files ending with .dot in subdirs of dot_dir.
def set_repopath(id)
Return the repopath for the repo id, queried from projects.kde.org.
def tolist(a)
Return a list based on a.
def cache_dir()
Find/create a semi-long-term cache directory.
def svn_export(remote, local, overwrite=False)
Wraps svn export.
def get_kapidox_version()
Get commit id of running code if it is running from git repository.
def set_maintainers(maintainer_keys, all_maintainers)
Expend the name of the maintainers.
def copy_dir_contents(directory, dest)
Copy the contents of a directory.