Add arguments -v and --version

This commit is contained in:
Schimon Jehudah 2024-02-04 18:19:56 +00:00
parent c7fa2496a8
commit acce4fafdc
5 changed files with 66 additions and 66 deletions

View file

@ -92,25 +92,26 @@ import os
# import time
# from eliot import start_action, to_file
# # to_file(open("slixfeed.log", "w"))
# # with start_action(action_type="set_date()", jid=jid):
# # with start_action(action_type="message()", msg=msg):
# # to_file(open('slixfeed.log', 'w'))
# # with start_action(action_type='set_date()', jid=jid):
# # with start_action(action_type='message()', msg=msg):
#import slixfeed.smtp
#import slixfeed.irc
#import slixfeed.matrix
import slixfeed.config as config
from slixfeed.version import __version__
import socks
import socket
xmpp_type = config.get_value("accounts", "XMPP", "type")
xmpp_type = config.get_value('accounts', 'XMPP', 'type')
match xmpp_type:
case "client":
case 'client':
from slixfeed.xmpp.client import Slixfeed
case "component":
case 'component':
from slixfeed.xmpp.component import SlixfeedComponent
@ -163,15 +164,15 @@ class JabberClient:
xmpp.register_plugin('xep_0402') # PEP Native Bookmarks
xmpp.register_plugin('xep_0444') # Message Reactions
# proxy_enabled = config.get_value("accounts", "XMPP", "proxy_enabled")
# proxy_enabled = config.get_value('accounts', 'XMPP', 'proxy_enabled')
# if proxy_enabled == '1':
# values = config.get_value("accounts", "XMPP", [
# "proxy_host",
# "proxy_port",
# "proxy_username",
# "proxy_password"
# values = config.get_value('accounts', 'XMPP', [
# 'proxy_host',
# 'proxy_port',
# 'proxy_username',
# 'proxy_password'
# ])
# print("Proxy is enabled: {}:{}".format(values[0], values[1]))
# print('Proxy is enabled: {}:{}'.format(values[0], values[1]))
# xmpp.use_proxy = True
# xmpp.proxy_config = {
# 'host': values[0],
@ -184,8 +185,8 @@ class JabberClient:
# Connect to the XMPP server and start processing XMPP stanzas.
address = config.get_value(
"accounts", "XMPP Client", ["hostname", "port"])
address = config.get_value('accounts', 'XMPP Client',
['hostname', 'port'])
if address[0] and address[1]:
xmpp.connect(tuple(address))
else:
@ -196,11 +197,11 @@ class JabberClient:
def main():
config_dir = config.get_default_config_directory()
logging.info("Reading configuration from {}".format(config_dir))
print("Reading configuration from {}".format(config_dir))
logging.info('Reading configuration from {}'.format(config_dir))
print('Reading configuration from {}'.format(config_dir))
values = config.get_value(
"accounts", "XMPP Proxy", ["socks5_host", "socks5_port"])
values = config.get_value('accounts', 'XMPP Proxy',
['socks5_host', 'socks5_port'])
if values[0] and values[1]:
host = values[0]
port = values[1]
@ -212,21 +213,24 @@ def main():
# Setup the command line arguments.
parser = ArgumentParser(description=Slixfeed.__doc__)
parser.add_argument('-v', '--version', help='Print version',
action='version', version=__version__)
# Output verbosity options.
parser.add_argument("-q", "--quiet", help="set logging to ERROR",
action="store_const", dest="loglevel",
parser.add_argument('-q', '--quiet', help='set logging to ERROR',
action='store_const', dest='loglevel',
const=logging.ERROR, default=logging.INFO)
parser.add_argument("-d", "--debug", help="set logging to DEBUG",
action="store_const", dest="loglevel",
parser.add_argument('-d', '--debug', help='set logging to DEBUG',
action='store_const', dest='loglevel',
const=logging.DEBUG, default=logging.INFO)
# JID and password options.
parser.add_argument("-j", "--jid", help="Jabber ID", dest="jid")
parser.add_argument("-p", "--password", help="Password of JID",
dest="password")
parser.add_argument("-a", "--alias", help="Display name", dest="alias")
parser.add_argument("-n", "--hostname", help="Hostname", dest="hostname")
parser.add_argument("-o", "--port", help="Port number", dest="port")
parser.add_argument('-j', '--jid', help='Jabber ID', dest='jid')
parser.add_argument('-p', '--password', help='Password of JID',
dest='password')
parser.add_argument('-a', '--alias', help='Display name', dest='alias')
parser.add_argument('-n', '--hostname', help='Hostname', dest='hostname')
parser.add_argument('-o', '--port', help='Port number', dest='port')
args = parser.parse_args()
@ -235,8 +239,8 @@ def main():
format='%(levelname)-8s %(message)s')
# Try configuration file
values = config.get_value("accounts", "XMPP Client",
["alias", "jid", "password", "hostname", "port"])
values = config.get_value('accounts', 'XMPP Client',
['alias', 'jid', 'password', 'hostname', 'port'])
alias = values[0]
jid = values[1]
password = values[2]
@ -257,18 +261,18 @@ def main():
# Prompt for credentials if none were given
if not jid:
jid = input("JID: ")
jid = input('JID: ')
if not password:
password = getpass("Password: ")
password = getpass('Password: ')
if not alias:
alias = (input("Alias: ")) or "Slixfeed"
alias = (input('Alias: ')) or 'Slixfeed'
match xmpp_type:
case "client":
case 'client':
JabberClient(jid, password, hostname=hostname, port=port, alias=alias)
case "component":
case 'component':
JabberComponent(jid, password, hostname, port, alias=alias)
sys.exit(0)
if __name__ == "__main__":
if __name__ == '__main__':
main()

View file

@ -113,11 +113,10 @@ async def start_tasks_xmpp(self, jid, tasks=None):
return
try:
task_manager[jid]
print('Old details for tasks of {}:\n'.format(jid), task_manager[jid].keys())
except KeyError as e:
task_manager[jid] = {}
logging.info('KeyError:', str(e))
logging.debug('Creating new task manager for JID {}'.format(jid))
logging.debug('KeyError:', str(e))
logging.info('Creating new task manager for JID {}'.format(jid))
if not tasks:
tasks = ['interval', 'status', 'check']
logging.info('Stopping tasks {} for JID {}'.format(tasks, jid))
@ -126,7 +125,7 @@ async def start_tasks_xmpp(self, jid, tasks=None):
try:
task_manager[jid][task].cancel()
except:
logging.debug('No task {} for JID {} (start_tasks_xmpp)'
logging.info('No task {} for JID {} (start_tasks_xmpp)'
.format(task, jid))
logging.info('Starting tasks {} for JID {}'.format(tasks, jid))
for task in tasks:
@ -181,7 +180,6 @@ async def start_tasks_xmpp(self, jid, tasks=None):
# print(jid)
# breakpoint()
# await task
print('New details for tasks of {}:\n'.format(jid), task_manager[jid])
async def clean_tasks_xmpp(jid, tasks=None):

View file

@ -1,2 +1,2 @@
__version__ = '1.0.0'
__version_info__ = (1, 0, 0)
__version__ = '0.1.1'
__version_info__ = (0, 1, 1)

View file

@ -961,7 +961,6 @@ async def message(self, message):
await sqlite.update_settings_value(db_file, [key, val])
else:
await sqlite.set_settings_value(db_file, [key, val])
# asyncio.create_task(task_jid(self, jid))
await task.start_tasks_xmpp(self, jid)
response = 'Updates are enabled.'
# print(current_time(), 'task_manager[jid]')

View file

@ -44,22 +44,22 @@ async def set_avatar(self):
config_dir = get_default_config_directory()
if not os.path.isdir(config_dir):
config_dir = '/usr/share/slixfeed/'
filename = glob.glob(config_dir + "/image.*")
filename = glob.glob(config_dir + '/image.*')
if not filename and os.path.isdir('/usr/share/slixfeed/'):
# filename = '/usr/share/slixfeed/image.svg'
filename = glob.glob("/usr/share/slixfeed/image.*")
filename = glob.glob('/usr/share/slixfeed/image.*')
if not filename:
config_dir = os.path.dirname(__file__)
config_dir = config_dir.split("/")
config_dir = config_dir.split('/')
config_dir.pop()
config_dir = "/".join(config_dir)
filename = glob.glob(config_dir + "/assets/image.*")
config_dir = '/'.join(config_dir)
filename = glob.glob(config_dir + '/assets/image.*')
filename = filename[0]
image_file = os.path.join(config_dir, filename)
with open(image_file, "rb") as avatar_file:
with open(image_file, 'rb') as avatar_file:
avatar = avatar_file.read()
# await self.plugin["xep_0084"].publish_avatar(avatar)
await self.plugin["xep_0153"].set_avatar(avatar=avatar)
# await self.plugin['xep_0084'].publish_avatar(avatar)
await self.plugin['xep_0153'].set_avatar(avatar=avatar)
def set_identity(self, category):
@ -86,20 +86,19 @@ def set_identity(self, category):
async def set_vcard(self):
vcard = self.plugin["xep_0054"].make_vcard()
vcard = self.plugin['xep_0054'].make_vcard()
fields = {
"BDAY": "birthday",
"DESC": "description",
"FN": "name",
"NICKNAME": "nickname",
"NOTE": "note",
"ORG": "organization",
"ROLE": "role",
"TITLE": "title",
"URL": "url",
'BDAY': 'birthday',
'DESC': 'description',
'FN': 'name',
'NICKNAME': 'nickname',
'NOTE': 'note',
'ORG': 'organization',
'ROLE': 'role',
'TITLE': 'title',
'URL': 'url',
}
for key in fields:
vcard[key] = get_value(
"accounts", "XMPP Profile", fields[key])
await self.plugin["xep_0054"].publish_vcard(vcard)
vcard[key] = get_value('accounts', 'XMPP Profile', fields[key])
await self.plugin['xep_0054'].publish_vcard(vcard)