mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
43
tools/python/data_files/__init__.py
Normal file
43
tools/python/data_files/__init__.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import os
|
||||
import site
|
||||
import sys
|
||||
|
||||
|
||||
def find_data_files_in_user_installations(directory):
|
||||
possible_paths = [os.path.join(site.USER_BASE, directory),] + [
|
||||
os.path.normpath(os.path.join(p, "../../..", directory))
|
||||
for p in site.getusersitepackages()
|
||||
]
|
||||
|
||||
for p in possible_paths:
|
||||
if os.path.isdir(p):
|
||||
return p
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def find_data_files_in_sys_installations(directory):
|
||||
possible_paths = [os.path.join(sys.prefix, directory),] + [
|
||||
os.path.normpath(os.path.join(p, "../../..", directory))
|
||||
for p in site.getsitepackages()
|
||||
]
|
||||
for p in possible_paths:
|
||||
if os.path.isdir(p):
|
||||
return p
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def find_data_files(directory, user_inst_first=True):
|
||||
functions = [
|
||||
(int(user_inst_first), find_data_files_in_user_installations),
|
||||
(int(not user_inst_first), find_data_files_in_sys_installations),
|
||||
]
|
||||
|
||||
functions.sort(key=lambda k: k[0])
|
||||
for prior, func in functions:
|
||||
res = func(directory)
|
||||
if res is not None:
|
||||
return res
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user