2017-04-09 10:30:48 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-08-18 12:08:27 +02:00
|
|
|
# Copyright © 2015-2019 Carl Chenet <carl.chenet@ohmytux.com>
|
2017-04-09 10:30:48 +02:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
# Get values of the configuration file
|
|
|
|
'''Get values of the configuration file'''
|
|
|
|
|
|
|
|
# standard library imports
|
2017-07-31 15:58:30 +02:00
|
|
|
from configparser import SafeConfigParser
|
2017-04-09 10:30:48 +02:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import sys
|
2017-07-13 20:19:04 +02:00
|
|
|
import re
|
2017-04-09 10:30:48 +02:00
|
|
|
|
|
|
|
# 3rd party library imports
|
|
|
|
import feedparser
|
|
|
|
|
2017-08-01 18:30:24 +02:00
|
|
|
# feed2toot library imports
|
2017-08-01 23:15:50 +02:00
|
|
|
from feed2toot.confparsers.cache import parsecache
|
2017-08-01 18:30:24 +02:00
|
|
|
from feed2toot.confparsers.hashtaglist import parsehashtaglist
|
2017-08-01 23:15:50 +02:00
|
|
|
from feed2toot.confparsers.feedparser import parsefeedparser
|
2019-08-17 15:26:49 +02:00
|
|
|
from feed2toot.confparsers.lock import parselock
|
2018-05-30 23:24:47 +02:00
|
|
|
from feed2toot.confparsers.media import parsemedia
|
2017-08-01 18:30:24 +02:00
|
|
|
from feed2toot.confparsers.plugins import parseplugins
|
2019-12-25 23:27:44 +01:00
|
|
|
from feed2toot.confparsers.rss.ignoressl import parseignoressl
|
2017-08-01 23:15:50 +02:00
|
|
|
from feed2toot.confparsers.rss.pattern import parsepattern
|
|
|
|
from feed2toot.confparsers.rss.toot import parsetoot
|
2017-08-01 23:34:11 +02:00
|
|
|
from feed2toot.confparsers.rss.uri import parseuri
|
2017-08-01 23:15:50 +02:00
|
|
|
from feed2toot.confparsers.rss.urilist import parseurilist
|
2018-09-12 10:53:13 +02:00
|
|
|
from feed2toot.confparsers.rss.addtags import parseaddtags
|
2017-08-01 18:30:24 +02:00
|
|
|
|
2017-07-31 15:58:30 +02:00
|
|
|
class ConfParse:
|
2017-04-09 10:30:48 +02:00
|
|
|
'''ConfParse class'''
|
|
|
|
def __init__(self, clioptions):
|
|
|
|
'''Constructor of the ConfParse class'''
|
|
|
|
self.clioptions = clioptions
|
|
|
|
self.tweetformat = ''
|
|
|
|
self.stringsep = ','
|
|
|
|
self.confs = []
|
|
|
|
self.main()
|
|
|
|
|
|
|
|
def main(self):
|
|
|
|
'''Main of the ConfParse class'''
|
|
|
|
for pathtoconfig in self.clioptions.configs:
|
|
|
|
options = {}
|
|
|
|
# read the configuration file
|
|
|
|
config = SafeConfigParser()
|
|
|
|
if not config.read(os.path.expanduser(pathtoconfig)):
|
|
|
|
sys.exit('Could not read config file')
|
2017-08-01 23:15:50 +02:00
|
|
|
####################
|
|
|
|
# feedparser section
|
|
|
|
####################
|
|
|
|
accept_bozo_exceptions = parsefeedparser(config)
|
2017-04-09 10:30:48 +02:00
|
|
|
###########################
|
|
|
|
# the rss section
|
|
|
|
###########################
|
2017-08-01 23:15:50 +02:00
|
|
|
self.tweetformat = parsetoot(config)
|
|
|
|
#################################################
|
|
|
|
# pattern and patter_case_sensitive format option
|
|
|
|
#################################################
|
|
|
|
options['patterns'], options['patternscasesensitive'] = parsepattern(config)
|
2019-08-17 15:26:49 +02:00
|
|
|
#################################################
|
|
|
|
# lock file options
|
|
|
|
#################################################
|
|
|
|
options['lockfile'], options['locktimeout'] = parselock(self.clioptions.lockfile, self.clioptions.locktimeout, config)
|
2018-09-12 10:53:13 +02:00
|
|
|
###############################
|
|
|
|
# addtags option, default: True
|
|
|
|
###############################
|
|
|
|
options['addtags'] = parseaddtags(config)
|
2019-12-25 23:27:44 +01:00
|
|
|
###################
|
|
|
|
# ignore_ssl option
|
|
|
|
###################
|
|
|
|
ignore_ssl = parseignoressl(config, self.clioptions.ignore_ssl)
|
2017-08-01 23:15:50 +02:00
|
|
|
#################
|
|
|
|
# uri_list option
|
|
|
|
#################
|
|
|
|
feeds = []
|
2019-12-25 23:27:44 +01:00
|
|
|
feeds = parseurilist(config, accept_bozo_exceptions, ignore_ssl)
|
2017-08-01 23:34:11 +02:00
|
|
|
############
|
|
|
|
# uri option
|
|
|
|
############
|
2019-12-25 23:27:44 +01:00
|
|
|
options['rss_uri'], feed, feedname, options['nopatternurinoglobalpattern'] = parseuri(config, self.clioptions.rss_uri, feeds, ignore_ssl)
|
2017-04-09 10:30:48 +02:00
|
|
|
###########################
|
|
|
|
# the cache section
|
|
|
|
###########################
|
2017-08-01 23:15:50 +02:00
|
|
|
options['cachefile'], options['cache_limit'] = parsecache(self.clioptions.cachefile, config)
|
2017-04-09 10:30:48 +02:00
|
|
|
###########################
|
|
|
|
# the hashtag section
|
|
|
|
###########################
|
2017-08-01 18:30:24 +02:00
|
|
|
options['hashtaglist'] = parsehashtaglist(self.clioptions.hashtaglist, config)
|
2017-04-09 10:30:48 +02:00
|
|
|
###########################
|
2018-05-30 23:24:47 +02:00
|
|
|
# the media section
|
|
|
|
###########################
|
|
|
|
options['media'] = parsemedia(config)
|
|
|
|
###########################
|
2017-04-09 10:30:48 +02:00
|
|
|
# the plugins section
|
|
|
|
###########################
|
2017-08-01 18:30:24 +02:00
|
|
|
plugins = parseplugins(config)
|
|
|
|
########################################
|
|
|
|
# return the final configurations values
|
|
|
|
########################################
|
2017-04-09 10:30:48 +02:00
|
|
|
if feeds:
|
|
|
|
self.confs.append((options, config, self.tweetformat, feeds, plugins))
|
|
|
|
else:
|
2017-08-01 16:55:26 +02:00
|
|
|
self.confs.append((options, config, self.tweetformat, [{'feed': feed, 'patterns': [], 'rssobject': '', 'feedname': feedname}], plugins))
|
2017-07-13 20:19:04 +02:00
|
|
|
|
2017-04-09 10:30:48 +02:00
|
|
|
@property
|
|
|
|
def confvalues(self):
|
|
|
|
'''Return the values of the different configuration files'''
|
|
|
|
return self.confs
|