Ability to pass custom data_files location
This commit is contained in:
		@@ -474,6 +474,7 @@ debugging.
 | 
				
			|||||||
- `IGNORE_SSL=1`: to ignore SSL certs when fetch feeds and articles
 | 
					- `IGNORE_SSL=1`: to ignore SSL certs when fetch feeds and articles
 | 
				
			||||||
- `DELAY` (seconds) sets the browser cache delay, only for HTTP clients
 | 
					- `DELAY` (seconds) sets the browser cache delay, only for HTTP clients
 | 
				
			||||||
- `TIMEOUT` (seconds) sets the HTTP timeout when fetching rss feeds and articles
 | 
					- `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
 | 
					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
 | 
					time to parse it, or might even run into a memory overflow on some shared
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,7 +65,8 @@ def parse_rules(filename=None):
 | 
				
			|||||||
            # for each rule
 | 
					            # for each rule
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if rules[section][arg].startswith('file:'):
 | 
					            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)
 | 
					                file_clean = re.sub('<[/?]?(xsl|xml)[^>]+?>', '', file_raw)
 | 
				
			||||||
                rules[section][arg] = file_clean
 | 
					                rules[section][arg] = file_clean
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,32 +15,37 @@
 | 
				
			|||||||
# You should have received a copy of the GNU Affero General Public License along
 | 
					# 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/>.
 | 
					# with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
import os.path
 | 
					import os.path
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def pkg_path(path=''):
 | 
					def pkg_path(*path_elements):
 | 
				
			||||||
    return os.path.join(os.path.dirname(__file__), path)
 | 
					    return os.path.join(os.path.dirname(__file__), *path_elements)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
data_path_base = None
 | 
					data_path_base = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def data_path(path=''):
 | 
					def data_path(*path_elements):
 | 
				
			||||||
    global data_path_base
 | 
					    global data_path_base
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    path = os.path.join(*path_elements)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if data_path_base is not None:
 | 
					    if data_path_base is not None:
 | 
				
			||||||
        return os.path.join(data_path_base, path)
 | 
					        return os.path.join(data_path_base, path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bases = [
 | 
					    bases = [
 | 
				
			||||||
        os.path.join(sys.prefix, 'share/morss/www'), # when installed as root
 | 
					        os.path.join(sys.prefix, 'share/morss'), # when installed as root
 | 
				
			||||||
        pkg_path('../../../share/morss/www'), 
 | 
					        pkg_path('../../../share/morss'), 
 | 
				
			||||||
        pkg_path('../../../../share/morss/www'),
 | 
					        pkg_path('../../../../share/morss'),
 | 
				
			||||||
        pkg_path('../share/morss/www'), # for `pip install --target=dir morss`
 | 
					        pkg_path('../share/morss'), # for `pip install --target=dir morss`
 | 
				
			||||||
        pkg_path('../www'), # when running from source tree
 | 
					        pkg_path('..'), # when running from source tree
 | 
				
			||||||
        pkg_path('../..'), # when running on `.cgi` subdir on Apache
 | 
					 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if 'DATA_PATH' in os.environ:
 | 
				
			||||||
 | 
					        bases.append(os.environ['DATA_PATH'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for base in bases:
 | 
					    for base in bases:
 | 
				
			||||||
        full_path = os.path.join(base, path)
 | 
					        full_path = os.path.join(base, path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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 re.match(r'^/?([a-zA-Z0-9_-][a-zA-Z0-9\._-]+/?)*$', url):
 | 
				
			||||||
        # if it is a legitimate url (no funny relative paths)
 | 
					        # if it is a legitimate url (no funny relative paths)
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            path = data_path(url)
 | 
					            path = data_path('www', url)
 | 
				
			||||||
            f = open(path, 'rb')
 | 
					            f = open(path, 'rb')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except IOError:
 | 
					        except IOError:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user