Skip to content

Commit

Permalink
Merge pull request #22 from JP-Carr/new_development
Browse files Browse the repository at this point in the history
fixes for v0.9.0
  • Loading branch information
why-keith committed Mar 17, 2021
2 parents d82e6f6 + 65dda8b commit 9fa9bc9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
40 changes: 28 additions & 12 deletions DnD_Time_Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from send2trash import send2trash
from urllib.request import urlopen
from sys import exit
from os import remove
from shutil import copyfile, copytree, rmtree


VERSION="v0.9.0"
Expand Down Expand Up @@ -133,9 +135,8 @@ def update_menu():
return menu_dict

def move_files(target_path):
from os import remove
from shutil import copyfile, copytree, rmtree

deleted=True
try:
copytree("campaigns",abspath(target_path+"/campaigns"))
except Exception as e:
Expand All @@ -144,11 +145,16 @@ def move_files(target_path):

if "campaigns" in listdir(target_path):
print("deleting")
rmtree("campaigns")
try:
rmtree("campaigns")
except Exception as e:
error(e)
deleted=False
else:
error(abspath(target_path+"/campaigns")+" was not moved successfully")
exit()
#------------------------------------------


try:
copyfile("pref.pkl", abspath(target_path+"/pref.pkl"))
except Exception as e:
Expand All @@ -157,34 +163,44 @@ def move_files(target_path):

if "pref.pkl" in listdir(target_path):
print("deleting")
remove("pref.pkl")
try:
remove("pref.pkl")
except Exception as e:
error(e)
deleted=False
else:
error(abspath(target_path+"/pref.pkl")+" was not moved successfully")
exit()
return
return deleted

def end_session():
log=open("{}/{}.txt".format(camp_dir,campaign), "a")
log.write("End of session {} ------------------------------------------------------\n".format(db.session_num))
log.close()
db.session_num+=1
pickler(camp_dir+"/"+campaign+".pkl", db)

def debug_log(text):
file= open("debug.txt","a")
file.write(str(text)+"\n")
file.close()

# Preferences & campaign loading-----------------------------------------------

if DEV_MODE==False:
user_area=abspath(getenv('LOCALAPPDATA')+"/JP-Carr/DnD_Time_Manager")
else:
user_area=abspath(getenv('LOCALAPPDATA')+"/JP-Carr/DnD_Time_Manager_DEV")

if exists(user_area)==False: #creates directory for save data
mkdir(user_area)

if exists("pref.pkl") or exists("campaigns"): #moves files from program install location to user area
if popup.alert_box(text="Moving campaign and preference files to user area\nFiles will be located at:\n"+user_area, window_name="Moving files", theme="Default")==True:
print("moving files...")
move_files(user_area)
if move_files(user_area)==False:
popup.alert_box(text="Unable to delete \"pref.pkl\" and/or \"/campaigns\"\nPlease remove manually")
else:
print(exists("pref.pkl"),exists("campaigns"))
exit()

if "pref.pkl" in listdir(user_area): #Loads pref file or creates new one
Expand All @@ -206,19 +222,19 @@ def end_session():

if "campaigns" not in listdir(user_area):
mkdir(user_area+"/campaigns")

campaign=None
if len(listdir(user_area+"/campaigns"))!=0: #loads most recent possible campaign
for i in pref["last campaign"]:
if i in listdir(user_area+"/campaigns") and exists(user_area+"/campaigns/{}/{}.pkl".format(i, i)):
campaign=i
break

if campaign==None:
for file in listdir(user_area+"/campaigns"):
if exists(user_area+"/campaigns/{}/{}.pkl".format(file, file)):
campaign=file
#print(campaign)

if len(listdir(user_area+"/campaigns"))==0 or campaign==None:
campaign=popup.create_campaign(user_area ,first=True, theme=pref["theme"])

Expand Down
4 changes: 2 additions & 2 deletions database_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from random import choice, randint
import condition_lists as conditions
from error import error
from numpy import array
from os.path import abspath
########################################################

Expand Down Expand Up @@ -155,7 +154,8 @@ def time_comparison(time0, time1):

def time_increment(start_time, increment):

new_time=array(start_time)+array(increment)

new_time=[i+j for i,j in zip(start_time, increment)]
limits=[24, 30, 12, 1e99]
new_time[0]+=1
for i in range(len(new_time)-1):
Expand Down

0 comments on commit 9fa9bc9

Please sign in to comment.