From b4246fff2e9fa5f0c723db10dabe5f0a5f1fd7cc Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Tue, 1 Mar 2016 10:12:20 -0500 Subject: [PATCH] detect user profile folder and improve finding of colors.txt --- chunkymap-regen.py | 12 ++++++++++-- minetestmapper.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/chunkymap-regen.py b/chunkymap-regen.py index 8d23857..a93db5e 100644 --- a/chunkymap-regen.py +++ b/chunkymap-regen.py @@ -353,7 +353,7 @@ class MTChunks: self.refresh_map_enable = True self.refresh_players_enable = True self.chunks = {} - self.username = "owner" + #self.username = "owner" self.website_root="/var/www/html/minetest" self.world_name = "FCAGameAWorld" self.os_name="linux" @@ -380,7 +380,15 @@ class MTChunks: self.profiles_path = "/home" if self.os_name=="windows": self.profiles_path = "C:\\Users" - self.profile_path = os.path.join(self.profiles_path, self.username) + if self.username is not None: + self.profile_path = os.path.join(self.profiles_path, self.username) + else: + if self.os_name=="windows": + self.profiles_path = "C:\\Users" + self.profile_path = os.environ['USERPROFILE'] + else: + self.profile_path = os.environ['HOME'] + #if (not os.path.isdir(self.profile_path)): # self.profile_path = os.path.join(self.profiles_path, "jgustafson") self.dotminetest_path = os.path.join(self.profile_path,".minetest") diff --git a/minetestmapper.py b/minetestmapper.py index 5bc85d0..d9b95f6 100644 --- a/minetestmapper.py +++ b/minetestmapper.py @@ -268,8 +268,38 @@ if path[-1:] != "/" and path[-1:] != "\\": # Load color information for the blocks. colors = {} +colors_path = "colors.txt" + +os_name="linux" +if (os.path.sep!="/"): + os_name="windows" + +profiles_path = "/home" +profile_path = None +if os_name=="windows": + profiles_path = "C:\\Users" + profile_path = os.environ['USERPROFILE'] +else: + profile_path = os.environ['HOME'] + +mt_path = os.path.join( profile_path, "minetest") +mt_util_path = os.path.join( mt_path, "util") +abs_colors_path = os.path.join( mt_util_path, "colors.txt" ) + +if not os.path.isfile(colors_path): + colors_path = abs_colors_path + +if not os.path.isfile(colors_path): + try: + outer_colors_folder_path = os.path.dirname(os.path.dirname(__file__)) + outer_colors_path = os.path.join(outer_colors_folder_path, "colors.txt") + if os.path.isfile(outer_colors_path): + colors_path = outer_colors_path + except: + pass + try: - f = file("colors.txt") + f = file(colors_path) except IOError: f = file(os.path.join(os.path.dirname(__file__), "colors.txt")) for line in f: