Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #206 from hdiogenes/fix-etc-skel
Browse files Browse the repository at this point in the history
Fix NApp creation from skel dir (fix #190)
  • Loading branch information
hdiogenes authored Jan 23, 2019
2 parents 6c62dba + abb1d43 commit f41d565
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
7 changes: 3 additions & 4 deletions kytos/utils/napps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from kytos.utils.client import NAppsClient
from kytos.utils.config import KytosConfig
from kytos.utils.openapi import OpenAPI
from kytos.utils.settings import BASE_ENV
from kytos.utils.settings import SKEL_PATH

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -343,8 +343,7 @@ def create_napp(cls, meta_package=False):
This will create, on the current folder, a clean structure of a NAPP,
filling some contents on this structure.
"""
templates_path = os.path.join(BASE_ENV, 'etc', 'skel', 'kytos',
'napp-structure', 'username', 'napp')
templates_path = SKEL_PATH / 'napp-structure/username/napp'

ui_templates_path = os.path.join(templates_path, 'ui')

Expand Down Expand Up @@ -538,7 +537,7 @@ def prepare(cls):
"""Prepare NApp to be uploaded by creating openAPI skeleton."""
if cls._ask_openapi():
napp_path = Path()
tpl_path = BASE_ENV / 'etc/skel/kytos/napp-structure/username/napp'
tpl_path = SKEL_PATH / 'napp-structure/username/napp'
OpenAPI(napp_path, tpl_path).render_template()
print('Please, update your openapi.yml file.')
sys.exit()
Expand Down
1 change: 1 addition & 0 deletions kytos/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from pathlib import Path

BASE_ENV = Path(os.environ.get('VIRTUAL_ENV', '/'))
SKEL_PATH = BASE_ENV / Path('etc/kytos/skel')
22 changes: 13 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
else:
BASE_ENV = '/'

ETC_KYTOS = 'etc/kytos'
KYTOS_SKEL_PATH = 'etc/kytos/skel'
USERNAME_PATH = os.path.join(KYTOS_SKEL_PATH, 'napp-structure/username')
NAPP_PATH = os.path.join(USERNAME_PATH, 'napp')
Expand Down Expand Up @@ -121,20 +122,23 @@ def _create_data_files_directory(symlink=False):
"""Install data_files in the /etc directory."""
current_directory = os.path.abspath(os.path.dirname(__file__))

etc_dir = os.path.join(BASE_ENV, 'etc')
etc_kytos = os.path.join(BASE_ENV, ETC_KYTOS)

if not os.path.exists(etc_dir):
os.makedirs(etc_dir)

dst_dir = os.path.join(BASE_ENV, KYTOS_SKEL_PATH)
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
if not os.path.exists(etc_kytos):
os.makedirs(etc_kytos)

src = os.path.join(current_directory, KYTOS_SKEL_PATH)
dst = os.path.join(BASE_ENV, KYTOS_SKEL_PATH)

if not os.path.exists(dst):
if symlink is True:
if os.path.exists(dst):
if not os.listdir(dst):
# Path already exists but it's empty, so we'll populate it
# We remove it first to avoid an exception from copytree
os.rmdir(dst)
shutil.copytree(src, dst)
else:
# It doesn't exist yet, so we should symlink or copy contents
if symlink:
os.symlink(src, dst)
else:
shutil.copytree(src, dst)
Expand Down

0 comments on commit f41d565

Please sign in to comment.