Verified Commit 4eef629d authored by tallero's avatar tallero

Config: fix startup for people who run 1.0a flatpak

parent cefbf922
......@@ -24,7 +24,7 @@
try:
from .util import load, mkdirs, save
from .util import chmod_recursively, load, mkdirs, save
except:
from util import load, mkdirs, save
......@@ -32,9 +32,10 @@ from appdirs import *
from gettext import bindtextdomain, textdomain, translation
from gi.repository.Gio import Resource, ResourceLookupFlags, resource_load
from locale import getdefaultlocale
from os import environ, mkdir, sep
from os import chmod, environ, mkdir, sep
from os.path import abspath, dirname, exists, join
from re import sub
from shutil import rmtree as rm
class Config:
"""Daty configuration class.
......@@ -72,16 +73,6 @@ class Config:
"""
for dir_type, path in self.dirs.items():
mkdirs(path)
#print(type,p)
#if not exists(p):
# split = p.split("/")
# path = split[0] + sep
# for d in split[1:]:
# path = join(path, d)
# try:
# mkdir(path)
# except FileExistsError as e:
# pass
if dir_type == 'config': #and not exists(join(path, 'pywikibot')):
mkdirs(join(path, 'pywikibot'), mode=0o700)
......@@ -136,9 +127,22 @@ class Config:
password_config = sub(u'your_bot_password', bot_password, password_config)
# Write files
with open(config_save_file, 'w') as f:
f.write(config)
f.close()
try:
with open(config_save_file, 'w') as f:
f.write(config)
f.close()
except PermissionError as e:
print(e)
for dir_type, path in self.dirs.items():
try:
print(path)
chmod_recursively(path, mode=0o777)
rm(path)
except Exception as e:
print(e)
print(e.__traceback__)
self.set_dirs()
self.create_pywikibot_config(user, bot_user, bot_password)
with open(password_save_file, 'w') as f:
f.write(password_config)
......
......@@ -67,6 +67,20 @@ def load(path):
f.close()
return variable
def chmod_recursively(path, mode=0o755):
from os import chmod, walk
from os.path import join
chmod(path, mode)
for root, dirs, files in walk(path):
for d in dirs:
current_path = join(root, d)
print(current_path)
chmod(current_path, mode)
for f in files:
current_path = join(root, f)
print(current_path)
chmod(current_path, mode)
def label_color(label, text=None, color='#e5a50a'):
label_text = label.get_text()
try: label.orig == True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment