MCPcopy Create free account
hub / github.com/SmingHub/Sming / buildFileMap

Function buildFileMap

docs/source/filemap.py:46–82  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

44
45# Get map of directories to submodule URLs
46def buildFileMap(ctx):
47 rootmap = {}
48
49 # index.rst files may be generated from README.md or README.rst
50 def getSourceFilename(srcdir, filename):
51 if filename != 'index.rst':
52 return filename
53 if os.path.exists(f"{srcdir}/README.md"):
54 return 'README.md'
55 if os.path.exists(f"{srcdir}/README.rst"):
56 return 'README.rst'
57 return filename
58
59 filemap = {}
60 for dirpath, dirnames, filenames in os.walk('_inc'):
61 srcpath = dirpath[5:] # skip '_inc/'
62 srcdir = os.path.join(SMINGDIR, srcpath)
63 # print(f"srcdir = {srcdir}", file=sys.stderr)
64 remotePath = getRemotePath(srcdir)
65 url = getRemoteUrl(srcdir)
66 commit = getRemoteCommit(srcdir)
67 if remotePath:
68 srcpath = srcpath.rsplit(remotePath)[0].rstrip('/')
69 rootmap[srcpath] = urljoin([url, 'tree', commit])
70 for f in filenames:
71 s = urljoin([url, 'blob', commit, remotePath, getSourceFilename(srcdir, f)])
72 filemap[f"{dirpath}/{f}"] = s
73
74 # for k, v in filemap.items():
75 # print(f"{k}: {v}", file=sys.stderr)
76
77 # for k, v in rootmap.items():
78 # print(f"{k}: {v}", file=sys.stderr)
79
80 ctx['page_urls'] = filemap
81 ctx['root_urls'] = rootmap
82 ctx['root_paths'] = sorted(rootmap.keys(), reverse=True)

Callers 1

conf.pyFile · 0.90

Calls 6

getRemotePathFunction · 0.85
getRemoteUrlFunction · 0.85
getRemoteCommitFunction · 0.85
urljoinFunction · 0.85
getSourceFilenameFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected