mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 03:38:03 +01:00
Handle base dir, queue dir in Config class
This commit is contained in:
committed by
Marcin Kulik
parent
2c4217fc10
commit
477d36ea57
@@ -5,24 +5,32 @@ import uuid
|
||||
class Config:
|
||||
|
||||
def __init__(self):
|
||||
self.config_filename = os.path.expanduser('~/.ascii.io/config')
|
||||
self.base_dir_path = os.path.expanduser("~/.ascii.io")
|
||||
self.config_file_path = '%s/config' % self.base_dir_path
|
||||
self.queue_dir_path = '%s/queue' % self.base_dir_path
|
||||
|
||||
self.create_base_dir()
|
||||
self.parse_config_file()
|
||||
|
||||
def create_base_dir(self):
|
||||
if not os.path.isdir(self.base_dir_path):
|
||||
os.mkdir(self.base_dir_path)
|
||||
|
||||
def parse_config_file(self):
|
||||
config = ConfigParser.RawConfigParser()
|
||||
config.add_section('user')
|
||||
config.add_section('api')
|
||||
config.add_section('record')
|
||||
|
||||
try:
|
||||
config.read(self.config_filename)
|
||||
config.read(self.config_file_path)
|
||||
except ConfigParser.ParsingError:
|
||||
print('Config file %s contains syntax errors' % self.config_filename)
|
||||
print('Config file %s contains syntax errors' %
|
||||
self.config_file_path)
|
||||
sys.exit(2)
|
||||
|
||||
self.config = config
|
||||
|
||||
# if not os.path.isdir(BASE_DIR):
|
||||
# os.mkdir(BASE_DIR)
|
||||
|
||||
def api_url(self):
|
||||
try:
|
||||
api_url = self.config.get('api', 'url')
|
||||
@@ -40,7 +48,7 @@ class Config:
|
||||
user_token = str(uuid.uuid1())
|
||||
self.config.set('user', 'token', user_token)
|
||||
|
||||
with open(self.config_filename, 'wb') as configfile:
|
||||
with open(self.config_file_path, 'wb') as configfile:
|
||||
self.config.write(configfile)
|
||||
|
||||
return user_token
|
||||
|
||||
@@ -2,4 +2,3 @@ import os
|
||||
import sys
|
||||
|
||||
SCRIPT_NAME = os.path.basename(sys.argv[0])
|
||||
BASE_DIR = os.path.expanduser("~/.ascii.io")
|
||||
|
||||
Reference in New Issue
Block a user