Ability to pass custom data_files location

master
pictuga 2022-01-25 22:36:34 +01:00
parent bfaf7b0fac
commit b2b04691d6
4 changed files with 18 additions and 11 deletions

View File

@ -474,6 +474,7 @@ debugging.
- `IGNORE_SSL=1`: to ignore SSL certs when fetch feeds and articles
- `DELAY` (seconds) sets the browser cache delay, only for HTTP clients
- `TIMEOUT` (seconds) sets the HTTP timeout when fetching rss feeds and articles
- `DATA_PATH`: to set custom file location for the `www` folder
When parsing long feeds, with a lot of items (100+), morss might take a lot of
time to parse it, or might even run into a memory overflow on some shared

View File

@ -65,7 +65,8 @@ def parse_rules(filename=None):
# for each rule
if rules[section][arg].startswith('file:'):
file_raw = open(data_path(rules[section][arg][5:])).read()
path = data_path('www', rules[section][arg][5:])
file_raw = open(path).read()
file_clean = re.sub('<[/?]?(xsl|xml)[^>]+?>', '', file_raw)
rules[section][arg] = file_clean

View File

@ -15,32 +15,37 @@
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import os.path
import sys
def pkg_path(path=''):
return os.path.join(os.path.dirname(__file__), path)
def pkg_path(*path_elements):
return os.path.join(os.path.dirname(__file__), *path_elements)
data_path_base = None
def data_path(path=''):
def data_path(*path_elements):
global data_path_base
path = os.path.join(*path_elements)
if data_path_base is not None:
return os.path.join(data_path_base, path)
bases = [
os.path.join(sys.prefix, 'share/morss/www'), # when installed as root
pkg_path('../../../share/morss/www'),
pkg_path('../../../../share/morss/www'),
pkg_path('../share/morss/www'), # for `pip install --target=dir morss`
pkg_path('../www'), # when running from source tree
pkg_path('../..'), # when running on `.cgi` subdir on Apache
os.path.join(sys.prefix, 'share/morss'), # when installed as root
pkg_path('../../../share/morss'),
pkg_path('../../../../share/morss'),
pkg_path('../share/morss'), # for `pip install --target=dir morss`
pkg_path('..'), # when running from source tree
]
if 'DATA_PATH' in os.environ:
bases.append(os.environ['DATA_PATH'])
for base in bases:
full_path = os.path.join(base, path)

View File

@ -169,7 +169,7 @@ def cgi_file_handler(environ, start_response, app):
if re.match(r'^/?([a-zA-Z0-9_-][a-zA-Z0-9\._-]+/?)*$', url):
# if it is a legitimate url (no funny relative paths)
try:
path = data_path(url)
path = data_path('www', url)
f = open(path, 'rb')
except IOError: