forked from sch/Slixfeed
Add arguments -v and --version
This commit is contained in:
parent
c7fa2496a8
commit
acce4fafdc
5 changed files with 66 additions and 66 deletions
|
@ -92,25 +92,26 @@ import os
|
||||||
# import time
|
# import time
|
||||||
|
|
||||||
# from eliot import start_action, to_file
|
# from eliot import start_action, to_file
|
||||||
# # to_file(open("slixfeed.log", "w"))
|
# # to_file(open('slixfeed.log', 'w'))
|
||||||
# # with start_action(action_type="set_date()", jid=jid):
|
# # with start_action(action_type='set_date()', jid=jid):
|
||||||
# # with start_action(action_type="message()", msg=msg):
|
# # with start_action(action_type='message()', msg=msg):
|
||||||
|
|
||||||
#import slixfeed.smtp
|
#import slixfeed.smtp
|
||||||
#import slixfeed.irc
|
#import slixfeed.irc
|
||||||
#import slixfeed.matrix
|
#import slixfeed.matrix
|
||||||
|
|
||||||
import slixfeed.config as config
|
import slixfeed.config as config
|
||||||
|
from slixfeed.version import __version__
|
||||||
|
|
||||||
import socks
|
import socks
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
xmpp_type = config.get_value("accounts", "XMPP", "type")
|
xmpp_type = config.get_value('accounts', 'XMPP', 'type')
|
||||||
|
|
||||||
match xmpp_type:
|
match xmpp_type:
|
||||||
case "client":
|
case 'client':
|
||||||
from slixfeed.xmpp.client import Slixfeed
|
from slixfeed.xmpp.client import Slixfeed
|
||||||
case "component":
|
case 'component':
|
||||||
from slixfeed.xmpp.component import SlixfeedComponent
|
from slixfeed.xmpp.component import SlixfeedComponent
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,15 +164,15 @@ class JabberClient:
|
||||||
xmpp.register_plugin('xep_0402') # PEP Native Bookmarks
|
xmpp.register_plugin('xep_0402') # PEP Native Bookmarks
|
||||||
xmpp.register_plugin('xep_0444') # Message Reactions
|
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':
|
# if proxy_enabled == '1':
|
||||||
# values = config.get_value("accounts", "XMPP", [
|
# values = config.get_value('accounts', 'XMPP', [
|
||||||
# "proxy_host",
|
# 'proxy_host',
|
||||||
# "proxy_port",
|
# 'proxy_port',
|
||||||
# "proxy_username",
|
# 'proxy_username',
|
||||||
# "proxy_password"
|
# '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.use_proxy = True
|
||||||
# xmpp.proxy_config = {
|
# xmpp.proxy_config = {
|
||||||
# 'host': values[0],
|
# 'host': values[0],
|
||||||
|
@ -184,8 +185,8 @@ class JabberClient:
|
||||||
|
|
||||||
# Connect to the XMPP server and start processing XMPP stanzas.
|
# Connect to the XMPP server and start processing XMPP stanzas.
|
||||||
|
|
||||||
address = config.get_value(
|
address = config.get_value('accounts', 'XMPP Client',
|
||||||
"accounts", "XMPP Client", ["hostname", "port"])
|
['hostname', 'port'])
|
||||||
if address[0] and address[1]:
|
if address[0] and address[1]:
|
||||||
xmpp.connect(tuple(address))
|
xmpp.connect(tuple(address))
|
||||||
else:
|
else:
|
||||||
|
@ -196,11 +197,11 @@ class JabberClient:
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
config_dir = config.get_default_config_directory()
|
config_dir = config.get_default_config_directory()
|
||||||
logging.info("Reading configuration from {}".format(config_dir))
|
logging.info('Reading configuration from {}'.format(config_dir))
|
||||||
print("Reading configuration from {}".format(config_dir))
|
print('Reading configuration from {}'.format(config_dir))
|
||||||
|
|
||||||
values = config.get_value(
|
values = config.get_value('accounts', 'XMPP Proxy',
|
||||||
"accounts", "XMPP Proxy", ["socks5_host", "socks5_port"])
|
['socks5_host', 'socks5_port'])
|
||||||
if values[0] and values[1]:
|
if values[0] and values[1]:
|
||||||
host = values[0]
|
host = values[0]
|
||||||
port = values[1]
|
port = values[1]
|
||||||
|
@ -212,21 +213,24 @@ def main():
|
||||||
# Setup the command line arguments.
|
# Setup the command line arguments.
|
||||||
parser = ArgumentParser(description=Slixfeed.__doc__)
|
parser = ArgumentParser(description=Slixfeed.__doc__)
|
||||||
|
|
||||||
|
parser.add_argument('-v', '--version', help='Print version',
|
||||||
|
action='version', version=__version__)
|
||||||
|
|
||||||
# Output verbosity options.
|
# Output verbosity options.
|
||||||
parser.add_argument("-q", "--quiet", help="set logging to ERROR",
|
parser.add_argument('-q', '--quiet', help='set logging to ERROR',
|
||||||
action="store_const", dest="loglevel",
|
action='store_const', dest='loglevel',
|
||||||
const=logging.ERROR, default=logging.INFO)
|
const=logging.ERROR, default=logging.INFO)
|
||||||
parser.add_argument("-d", "--debug", help="set logging to DEBUG",
|
parser.add_argument('-d', '--debug', help='set logging to DEBUG',
|
||||||
action="store_const", dest="loglevel",
|
action='store_const', dest='loglevel',
|
||||||
const=logging.DEBUG, default=logging.INFO)
|
const=logging.DEBUG, default=logging.INFO)
|
||||||
|
|
||||||
# JID and password options.
|
# JID and password options.
|
||||||
parser.add_argument("-j", "--jid", help="Jabber ID", dest="jid")
|
parser.add_argument('-j', '--jid', help='Jabber ID', dest='jid')
|
||||||
parser.add_argument("-p", "--password", help="Password of JID",
|
parser.add_argument('-p', '--password', help='Password of JID',
|
||||||
dest="password")
|
dest='password')
|
||||||
parser.add_argument("-a", "--alias", help="Display name", dest="alias")
|
parser.add_argument('-a', '--alias', help='Display name', dest='alias')
|
||||||
parser.add_argument("-n", "--hostname", help="Hostname", dest="hostname")
|
parser.add_argument('-n', '--hostname', help='Hostname', dest='hostname')
|
||||||
parser.add_argument("-o", "--port", help="Port number", dest="port")
|
parser.add_argument('-o', '--port', help='Port number', dest='port')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -235,8 +239,8 @@ def main():
|
||||||
format='%(levelname)-8s %(message)s')
|
format='%(levelname)-8s %(message)s')
|
||||||
|
|
||||||
# Try configuration file
|
# Try configuration file
|
||||||
values = config.get_value("accounts", "XMPP Client",
|
values = config.get_value('accounts', 'XMPP Client',
|
||||||
["alias", "jid", "password", "hostname", "port"])
|
['alias', 'jid', 'password', 'hostname', 'port'])
|
||||||
alias = values[0]
|
alias = values[0]
|
||||||
jid = values[1]
|
jid = values[1]
|
||||||
password = values[2]
|
password = values[2]
|
||||||
|
@ -257,18 +261,18 @@ def main():
|
||||||
|
|
||||||
# Prompt for credentials if none were given
|
# Prompt for credentials if none were given
|
||||||
if not jid:
|
if not jid:
|
||||||
jid = input("JID: ")
|
jid = input('JID: ')
|
||||||
if not password:
|
if not password:
|
||||||
password = getpass("Password: ")
|
password = getpass('Password: ')
|
||||||
if not alias:
|
if not alias:
|
||||||
alias = (input("Alias: ")) or "Slixfeed"
|
alias = (input('Alias: ')) or 'Slixfeed'
|
||||||
|
|
||||||
match xmpp_type:
|
match xmpp_type:
|
||||||
case "client":
|
case 'client':
|
||||||
JabberClient(jid, password, hostname=hostname, port=port, alias=alias)
|
JabberClient(jid, password, hostname=hostname, port=port, alias=alias)
|
||||||
case "component":
|
case 'component':
|
||||||
JabberComponent(jid, password, hostname, port, alias=alias)
|
JabberComponent(jid, password, hostname, port, alias=alias)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -113,11 +113,10 @@ async def start_tasks_xmpp(self, jid, tasks=None):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
task_manager[jid]
|
task_manager[jid]
|
||||||
print('Old details for tasks of {}:\n'.format(jid), task_manager[jid].keys())
|
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
task_manager[jid] = {}
|
task_manager[jid] = {}
|
||||||
logging.info('KeyError:', str(e))
|
logging.debug('KeyError:', str(e))
|
||||||
logging.debug('Creating new task manager for JID {}'.format(jid))
|
logging.info('Creating new task manager for JID {}'.format(jid))
|
||||||
if not tasks:
|
if not tasks:
|
||||||
tasks = ['interval', 'status', 'check']
|
tasks = ['interval', 'status', 'check']
|
||||||
logging.info('Stopping tasks {} for JID {}'.format(tasks, jid))
|
logging.info('Stopping tasks {} for JID {}'.format(tasks, jid))
|
||||||
|
@ -126,7 +125,7 @@ async def start_tasks_xmpp(self, jid, tasks=None):
|
||||||
try:
|
try:
|
||||||
task_manager[jid][task].cancel()
|
task_manager[jid][task].cancel()
|
||||||
except:
|
except:
|
||||||
logging.debug('No task {} for JID {} (start_tasks_xmpp)'
|
logging.info('No task {} for JID {} (start_tasks_xmpp)'
|
||||||
.format(task, jid))
|
.format(task, jid))
|
||||||
logging.info('Starting tasks {} for JID {}'.format(tasks, jid))
|
logging.info('Starting tasks {} for JID {}'.format(tasks, jid))
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
|
@ -181,7 +180,6 @@ async def start_tasks_xmpp(self, jid, tasks=None):
|
||||||
# print(jid)
|
# print(jid)
|
||||||
# breakpoint()
|
# breakpoint()
|
||||||
# await task
|
# await task
|
||||||
print('New details for tasks of {}:\n'.format(jid), task_manager[jid])
|
|
||||||
|
|
||||||
|
|
||||||
async def clean_tasks_xmpp(jid, tasks=None):
|
async def clean_tasks_xmpp(jid, tasks=None):
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
__version__ = '1.0.0'
|
__version__ = '0.1.1'
|
||||||
__version_info__ = (1, 0, 0)
|
__version_info__ = (0, 1, 1)
|
||||||
|
|
|
@ -961,7 +961,6 @@ async def message(self, message):
|
||||||
await sqlite.update_settings_value(db_file, [key, val])
|
await sqlite.update_settings_value(db_file, [key, val])
|
||||||
else:
|
else:
|
||||||
await sqlite.set_settings_value(db_file, [key, val])
|
await sqlite.set_settings_value(db_file, [key, val])
|
||||||
# asyncio.create_task(task_jid(self, jid))
|
|
||||||
await task.start_tasks_xmpp(self, jid)
|
await task.start_tasks_xmpp(self, jid)
|
||||||
response = 'Updates are enabled.'
|
response = 'Updates are enabled.'
|
||||||
# print(current_time(), 'task_manager[jid]')
|
# print(current_time(), 'task_manager[jid]')
|
||||||
|
|
|
@ -44,22 +44,22 @@ async def set_avatar(self):
|
||||||
config_dir = get_default_config_directory()
|
config_dir = get_default_config_directory()
|
||||||
if not os.path.isdir(config_dir):
|
if not os.path.isdir(config_dir):
|
||||||
config_dir = '/usr/share/slixfeed/'
|
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/'):
|
if not filename and os.path.isdir('/usr/share/slixfeed/'):
|
||||||
# filename = '/usr/share/slixfeed/image.svg'
|
# filename = '/usr/share/slixfeed/image.svg'
|
||||||
filename = glob.glob("/usr/share/slixfeed/image.*")
|
filename = glob.glob('/usr/share/slixfeed/image.*')
|
||||||
if not filename:
|
if not filename:
|
||||||
config_dir = os.path.dirname(__file__)
|
config_dir = os.path.dirname(__file__)
|
||||||
config_dir = config_dir.split("/")
|
config_dir = config_dir.split('/')
|
||||||
config_dir.pop()
|
config_dir.pop()
|
||||||
config_dir = "/".join(config_dir)
|
config_dir = '/'.join(config_dir)
|
||||||
filename = glob.glob(config_dir + "/assets/image.*")
|
filename = glob.glob(config_dir + '/assets/image.*')
|
||||||
filename = filename[0]
|
filename = filename[0]
|
||||||
image_file = os.path.join(config_dir, filename)
|
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()
|
avatar = avatar_file.read()
|
||||||
# await self.plugin["xep_0084"].publish_avatar(avatar)
|
# await self.plugin['xep_0084'].publish_avatar(avatar)
|
||||||
await self.plugin["xep_0153"].set_avatar(avatar=avatar)
|
await self.plugin['xep_0153'].set_avatar(avatar=avatar)
|
||||||
|
|
||||||
|
|
||||||
def set_identity(self, category):
|
def set_identity(self, category):
|
||||||
|
@ -86,20 +86,19 @@ def set_identity(self, category):
|
||||||
|
|
||||||
|
|
||||||
async def set_vcard(self):
|
async def set_vcard(self):
|
||||||
vcard = self.plugin["xep_0054"].make_vcard()
|
vcard = self.plugin['xep_0054'].make_vcard()
|
||||||
fields = {
|
fields = {
|
||||||
"BDAY": "birthday",
|
'BDAY': 'birthday',
|
||||||
"DESC": "description",
|
'DESC': 'description',
|
||||||
"FN": "name",
|
'FN': 'name',
|
||||||
"NICKNAME": "nickname",
|
'NICKNAME': 'nickname',
|
||||||
"NOTE": "note",
|
'NOTE': 'note',
|
||||||
"ORG": "organization",
|
'ORG': 'organization',
|
||||||
"ROLE": "role",
|
'ROLE': 'role',
|
||||||
"TITLE": "title",
|
'TITLE': 'title',
|
||||||
"URL": "url",
|
'URL': 'url',
|
||||||
}
|
}
|
||||||
for key in fields:
|
for key in fields:
|
||||||
vcard[key] = get_value(
|
vcard[key] = get_value('accounts', 'XMPP Profile', fields[key])
|
||||||
"accounts", "XMPP Profile", fields[key])
|
await self.plugin['xep_0054'].publish_vcard(vcard)
|
||||||
await self.plugin["xep_0054"].publish_vcard(vcard)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue