Skip to content

Commit

Permalink
added log suppression even when app crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
j4321 committed Feb 3, 2017
1 parent 9df2331 commit 6ffa8e4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
7 changes: 0 additions & 7 deletions BraceletGenerator/bicolore.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
from BraceletGenerator.about import About
from BraceletGenerator.scrollbar import AutoScrollbar as Scrollbar


BICOLOR_LOG = os.path.join(LOCAL_PATH, "Bicolor%i.log")
i = 0
while os.path.exists(BICOLOR_LOG % (i)):
i += 1
BICOLOR_LOG %= i

class Bicolore(Toplevel):
""" classe de l'application éditeur de motif bicolore """
def __init__(self, master, row_nb=10, string_nb=8,
Expand Down
8 changes: 0 additions & 8 deletions BraceletGenerator/bracelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@
from BraceletGenerator.bicolore import Bicolore
from BraceletGenerator.about import About


BRACELET_LOG = os.path.join(LOCAL_PATH, "BraceletGenerator%i.log")
i = 0
while os.path.exists(BRACELET_LOG % (i)):
i += 1
BRACELET_LOG %= i
TMP_PS = os.path.join(LOCAL_PATH,".tmp.ps")

class Bracelet(Tk):
""" patron de bracelet brésilien """

Expand Down
21 changes: 19 additions & 2 deletions BraceletGenerator/constantes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,33 @@
if not os.path.exists(LOCAL_PATH):
os.mkdir(LOCAL_PATH)

# bracelet log file
BRACELET_LOG = os.path.join(LOCAL_PATH, "BraceletGenerator%i.log")
i = 0
while os.path.exists(BRACELET_LOG % (i)):
i += 1
BRACELET_LOG %= i

# temporary file
TMP_PS = os.path.join(LOCAL_PATH,".tmp.ps")

# bicolore log file
BICOLOR_LOG = os.path.join(LOCAL_PATH, "Bicolor%i.log")
i = 0
while os.path.exists(BICOLOR_LOG % (i)):
i += 1
BICOLOR_LOG %= i

PATH_CONFIG = os.path.join(LOCAL_PATH, 'BraceletGenerator.ini')

# configuration file
# configuration file
CONFIG = ConfigParser()
if os.path.exists(PATH_CONFIG):
CONFIG.read(PATH_CONFIG)
LANGUE = CONFIG.get("General","language")
else:
LANGUE = ""

CONFIG.add_section("General")
CONFIG.set("General", "last_path", LOCAL_PATH)
CONFIG.set("General", "recent_files", "")
Expand Down
22 changes: 13 additions & 9 deletions bracelet-generator
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ main

import sys
import os
from BraceletGenerator.constantes import CONFIG
from BraceletGenerator.constantes import CONFIG, BRACELET_LOG, BICOLOR_LOG, save_config
from BraceletGenerator.bracelet import Bracelet

if len(sys.argv) == 1:
Bracelet(string_nb=CONFIG.getint("Bracelet", "string_nb"),
row_nb=CONFIG.getint("Bracelet", "row_nb"),
color=CONFIG.get("Bracelet", "default_color"))
else:
fichier = os.path.realpath(sys.argv[1])
Bracelet(fichier=fichier)

try:
if len(sys.argv) == 1:
Bracelet(string_nb=CONFIG.getint("Bracelet", "string_nb"),
row_nb=CONFIG.getint("Bracelet", "row_nb"),
color=CONFIG.get("Bracelet", "default_color"))
else:
fichier = os.path.realpath(sys.argv[1])
Bracelet(fichier=fichier)
finally: # remove logs even if the app crashed to avoid accumulation
os.remove(BRACELET_LOG)
os.remove(BICOLOR_LOG)
save_config()

0 comments on commit 6ffa8e4

Please sign in to comment.