From f7420bc7fab1b8211dedbe27f011fd526a9115e1 Mon Sep 17 00:00:00 2001 From: rmotitsuki Date: Wed, 2 Oct 2019 16:27:31 -0300 Subject: [PATCH 1/3] Modify the kytos developer mode to check the configuration files installation. --- setup.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/setup.py b/setup.py index a9d59862e..f01742701 100644 --- a/setup.py +++ b/setup.py @@ -241,8 +241,21 @@ def generate_file_link(file_name): src = os.path.join(os.path.abspath(current_directory), file_name) dst = os.path.join(BASE_ENV, file_name) + print(f"\nCreating symbolic link {dst}.") + + # Unlink path if it already exists. + if os.path.islink(dst): + os.unlink(dst) + if not os.path.exists(dst): os.symlink(src, dst) + else: + # If the file is a real path, print a warning message. + # The user must verify the problem. + # One reason is that the user installed kytos, and then, + # changed to developer mode. + print(f"\033[1;33;40m[WARN] Path specified is a real file." + f" Can´t create symlink '{dst}' \033[0;0m") # We are parsing the metadata file as if it was a text file because if we From 47969e7ee2c25edf439329a29cf258871fa72582 Mon Sep 17 00:00:00 2001 From: rmotitsuki Date: Mon, 7 Oct 2019 15:54:40 -0300 Subject: [PATCH 2/3] Refactor to use the code from of_core to detect symlinks, but checking the realpaths. --- setup.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index f01742701..c2b6de0e0 100644 --- a/setup.py +++ b/setup.py @@ -243,19 +243,28 @@ def generate_file_link(file_name): print(f"\nCreating symbolic link {dst}.") - # Unlink path if it already exists. - if os.path.islink(dst): - os.unlink(dst) - - if not os.path.exists(dst): - os.symlink(src, dst) + symlink_if_different(src, dst) + +def symlink_if_different(src, target): + """Force symlink creation if it points anywhere else.""" + # print(f"symlinking {path} to target: {target}...", end=" ") + + if not os.path.exists(target): + # print(f"path doesn't exist. linking...") + os.symlink(src, target) + elif not os.path.samefile(src, target): + # print(f"path exists, but is different. removing and linking...") + # Exists but points to a different file, so let's replace it + if os.path.islink(target): + os.unlink(target) + os.symlink(src, target) else: # If the file is a real path, print a warning message. # The user must verify the problem. # One reason is that the user installed kytos, and then, # changed to developer mode. print(f"\033[1;33;40m[WARN] Path specified is a real file." - f" Can´t create symlink '{dst}' \033[0;0m") + f" Can´t create symlink '{target}' \033[0;0m") # We are parsing the metadata file as if it was a text file because if we From 7401fd57eb27c9f0e7af4fbf3b2683840dc52c23 Mon Sep 17 00:00:00 2001 From: rmotitsuki Date: Wed, 9 Oct 2019 19:07:12 -0300 Subject: [PATCH 3/3] Revert setup code to check symlink to original of_core code --- setup.py | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index c2b6de0e0..020c78040 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ print('Please install python3-pip and run setup.py again.') exit(-1) -BASE_ENV = os.environ.get('VIRTUAL_ENV', None) or '/' +BASE_ENV = Path(os.environ.get('VIRTUAL_ENV', None)) or Path('/') ETC_FILES = [] TEMPLATE_FILES = ['etc/kytos/kytos.conf.template', 'etc/kytos/logging.ini.template'] @@ -156,7 +156,7 @@ def generate_file_from_template(cls, templates, """ from jinja2 import Template - if kwargs.get('prefix').endswith('/'): + if str(kwargs.get('prefix')).endswith('/'): kwargs['prefix'] = kwargs['prefix'][:-1] cls.create_paths() @@ -238,33 +238,25 @@ def run(self): def generate_file_link(file_name): """Create a symbolic link from a file name.""" current_directory = os.path.dirname(__file__) - src = os.path.join(os.path.abspath(current_directory), file_name) - dst = os.path.join(BASE_ENV, file_name) + src = Path(os.path.join(os.path.abspath(current_directory), file_name)) + dst = Path(os.path.join(BASE_ENV, file_name)) print(f"\nCreating symbolic link {dst}.") symlink_if_different(src, dst) -def symlink_if_different(src, target): + +def symlink_if_different(path, target): """Force symlink creation if it points anywhere else.""" # print(f"symlinking {path} to target: {target}...", end=" ") - - if not os.path.exists(target): + if not path.exists(): # print(f"path doesn't exist. linking...") - os.symlink(src, target) - elif not os.path.samefile(src, target): + path.symlink_to(target) + elif not path.samefile(target): # print(f"path exists, but is different. removing and linking...") # Exists but points to a different file, so let's replace it - if os.path.islink(target): - os.unlink(target) - os.symlink(src, target) - else: - # If the file is a real path, print a warning message. - # The user must verify the problem. - # One reason is that the user installed kytos, and then, - # changed to developer mode. - print(f"\033[1;33;40m[WARN] Path specified is a real file." - f" Can´t create symlink '{target}' \033[0;0m") + path.unlink() + path.symlink_to(target) # We are parsing the metadata file as if it was a text file because if we