get rid of defaults, hardcode stuff instead, also use os.chdir into config dir
This commit is contained in:
		
							parent
							
								
									acc390ef11
								
							
						
					
					
						commit
						9eeabd8ae9
					
				
					 4 changed files with 7 additions and 17 deletions
				
			
		
							
								
								
									
										7
									
								
								pgbot
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								pgbot
									
										
									
									
									
								
							| 
						 | 
					@ -1,12 +1,12 @@
 | 
				
			||||||
#!/usr/bin/env python3
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import asyncio
 | 
					import asyncio
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import telethon
 | 
					import telethon
 | 
				
			||||||
import yaml
 | 
					import yaml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pgbotlib.defaults
 | 
					 | 
				
			||||||
import pgbotlib.dbstuff
 | 
					import pgbotlib.dbstuff
 | 
				
			||||||
import pgbotlib.commands
 | 
					import pgbotlib.commands
 | 
				
			||||||
import pgbotlib.cron
 | 
					import pgbotlib.cron
 | 
				
			||||||
| 
						 | 
					@ -15,9 +15,10 @@ import pgbotlib.response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def init(args: list) -> tuple:
 | 
					def init(args: list) -> tuple:
 | 
				
			||||||
    conf_path = args[0] if args else pgbotlib.defaults.CONFIG
 | 
					    conf_dir = args[0] if args else '/etc/pgbot'
 | 
				
			||||||
 | 
					    os.chdir(conf_dir)
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        with open(conf_path, 'r', encoding='utf-8') as data:
 | 
					        with open('pgbot.yml', 'r', encoding='utf-8') as data:
 | 
				
			||||||
            config = yaml.safe_load(data.read())
 | 
					            config = yaml.safe_load(data.read())
 | 
				
			||||||
    except FileNotFoundError as err:
 | 
					    except FileNotFoundError as err:
 | 
				
			||||||
        sys.exit(err)
 | 
					        sys.exit(err)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,6 @@ import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import aiocron
 | 
					import aiocron
 | 
				
			||||||
import telethon
 | 
					import telethon
 | 
				
			||||||
import pgbotlib.defaults
 | 
					 | 
				
			||||||
import pgbotlib.response
 | 
					import pgbotlib.response
 | 
				
			||||||
import pgbotlib.misc
 | 
					import pgbotlib.misc
 | 
				
			||||||
import pytz
 | 
					import pytz
 | 
				
			||||||
| 
						 | 
					@ -16,8 +15,8 @@ class Cron:
 | 
				
			||||||
                 config: dict,
 | 
					                 config: dict,
 | 
				
			||||||
                 client: telethon.TelegramClient,
 | 
					                 client: telethon.TelegramClient,
 | 
				
			||||||
                 responder: pgbotlib.response.Responder) -> None:
 | 
					                 responder: pgbotlib.response.Responder) -> None:
 | 
				
			||||||
        schedule_conf = config.get('schedule', pgbotlib.defaults.SCHEDULE)
 | 
					        schedule_conf = config.get('schedule', 'sched.yml')
 | 
				
			||||||
        local_tz = config.get('timezone', pgbotlib.defaults.TZ)
 | 
					        local_tz = config.get('timezone', 'UTC')
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.tz = pytz.timezone(local_tz)
 | 
					            self.tz = pytz.timezone(local_tz)
 | 
				
			||||||
        except pytz.exceptions.UnknownTimeZoneError as e:
 | 
					        except pytz.exceptions.UnknownTimeZoneError as e:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +0,0 @@
 | 
				
			||||||
''' module defaults '''
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
CONFDIR = '/etc/pgbot'
 | 
					 | 
				
			||||||
CONFIG = CONFDIR + '/pgbot.yml'
 | 
					 | 
				
			||||||
TOKENS = CONFDIR + '/tokens.yml'
 | 
					 | 
				
			||||||
SCHEDULE = CONFDIR + '/sched.yml'
 | 
					 | 
				
			||||||
TZ = 'UTC'
 | 
					 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,6 @@ import telethon
 | 
				
			||||||
import yaml
 | 
					import yaml
 | 
				
			||||||
import pgbotlib.api
 | 
					import pgbotlib.api
 | 
				
			||||||
import pgbotlib.dbstuff
 | 
					import pgbotlib.dbstuff
 | 
				
			||||||
import pgbotlib.defaults
 | 
					 | 
				
			||||||
import pgbotlib.misc
 | 
					import pgbotlib.misc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,9 +30,7 @@ class Responder:
 | 
				
			||||||
        self.enabled = True
 | 
					        self.enabled = True
 | 
				
			||||||
        self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$')
 | 
					        self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$')
 | 
				
			||||||
        self.namegen = pgbotlib.misc.NameGenerator(config, db_connection)
 | 
					        self.namegen = pgbotlib.misc.NameGenerator(config, db_connection)
 | 
				
			||||||
        self.tokens = get_tokens(
 | 
					        self.tokens = get_tokens(config.get('response_tokens', 'tokens.yml'))
 | 
				
			||||||
            config.get('response_tokens', pgbotlib.defaults.TOKENS)
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        self.chats = config['chats']
 | 
					        self.chats = config['chats']
 | 
				
			||||||
        self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection)
 | 
					        self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection)
 | 
				
			||||||
        self.db_connection = db_connection
 | 
					        self.db_connection = db_connection
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue