Exemple #1
0
    def start(self):
        app = LabApp(config=self.config)
        # TODO(@echarles) Fix this...
#        base_url = app.serverapp.base_url
        base_url = '/'
        directory = app.workspaces_dir
        app_url = app.app_url

        if len(self.extra_args) > 1:
            print('Too many arguments were provided for workspace export.')
            self.exit(1)

        workspaces_url = ujoin(app_url, 'workspaces')
        raw = (app_url if not self.extra_args
               else ujoin(workspaces_url, self.extra_args[0]))
        slug = slugify(raw, base_url)
        workspace_path = pjoin(directory, slug + WORKSPACE_EXTENSION)

        if osp.exists(workspace_path):
            with open(workspace_path) as fid:
                try:  # to load the workspace file.
                    print(fid.read())
                except Exception as e:
                    print(json.dumps(dict(data=dict(), metadata=dict(id=raw))))
        else:
            print(json.dumps(dict(data=dict(), metadata=dict(id=raw))))
Exemple #2
0
    def start(self):
        app = LabApp(config=self.config)
        base_url = app.settings.get('base_url', '/')
        directory = app.workspaces_dir
        app_url = app.app_url
        workspaces_url = ujoin(app.app_url, 'workspaces')

        if len(self.extra_args) != 1:
            print('One argument is required for workspace import.')
            self.exit(1)

        workspace = dict()
        with self._smart_open() as fid:
            try:  # to load, parse, and validate the workspace file.
                workspace = self._validate(fid, base_url, app_url,
                                           workspaces_url)
            except Exception as e:
                print('%s is not a valid workspace:\n%s' % (fid.name, e))
                self.exit(1)

        if not osp.exists(directory):
            try:
                os.makedirs(directory)
            except Exception as e:
                print('Workspaces directory could not be created:\n%s' % e)
                self.exit(1)

        slug = slugify(workspace['metadata']['id'], base_url)
        workspace_path = pjoin(directory, slug + WORKSPACE_EXTENSION)

        # Write the workspace data to a file.
        with open(workspace_path, 'w') as fid:
            fid.write(json.dumps(workspace))

        print('Saved workspace: %s' % workspace_path)
Exemple #3
0
    def start(self):
        app = LabApp(config=self.config)
        base_url = app.base_url
        config = load_config(app)
        directory = config.workspaces_dir
        page_url = config.page_url
        workspaces_url = config.workspaces_url

        if len(self.extra_args) != 1:
            print('One argument is required for workspace import.')
            sys.exit(1)

        file_name = self.extra_args[0]
        file_path = os.path.abspath(file_name)

        if not os.path.exists(file_path):
            print('%s does not exist.' % file_name)
            sys.exit(1)

        workspace = dict()
        with open(file_path) as fid:
            try:  # to load, parse, and validate the workspace file.
                workspace = self._validate(fid, base_url, page_url,
                                           workspaces_url)
            except Exception as e:
                print('%s is not a valid workspace:\n%s' % (file_name, e))
                sys.exit(1)

        if not os.path.exists(directory):
            try:
                os.makedirs(directory)
            except Exception as e:
                print('Workspaces directory could not be created:\n%s' % e)
                sys.exit(1)

        slug = slugify(workspace['metadata']['id'], base_url)
        workspace_path = os.path.join(directory, slug + WORKSPACE_EXTENSION)

        # Write the workspace data to a file.
        with open(workspace_path, 'w') as fid:
            fid.write(json.dumps(workspace))

        print('Saved workspace: %s' % workspace_path)
Exemple #4
0
    def start(self):
        app = LabApp(config=self.config)
        base_url = app.base_url
        config = load_config(app)
        directory = config.workspaces_dir
        page_url = config.page_url
        workspaces_url = config.workspaces_url

        if len(self.extra_args) != 1:
            print('One argument is required for workspace import.')
            sys.exit(1)

        file_name = self.extra_args[0]
        file_path = os.path.abspath(file_name)

        if not os.path.exists(file_path):
            print('%s does not exist.' % file_name)
            sys.exit(1)

        workspace = dict()
        with open(file_path) as fid:
            try:  # to load, parse, and validate the workspace file.
                workspace = self._validate(fid, base_url, page_url, workspaces_url)
            except Exception as e:
                print('%s is not a valid workspace:\n%s' % (file_name, e))
                sys.exit(1)

        if not os.path.exists(directory):
            try:
                os.makedirs(directory)
            except Exception as e:
                print('Workspaces directory could not be created:\n%s' % e)
                sys.exit(1)

        slug = slugify(workspace['metadata']['id'], base_url)
        workspace_path = os.path.join(directory, slug + WORKSPACE_EXTENSION)

        # Write the workspace data to a file.
        with open(workspace_path, 'w') as fid:
            fid.write(json.dumps(workspace))

        print('Saved workspace: %s' % workspace_path)
Exemple #5
0
    def start(self):
        app = LabApp(config=self.config)
        base_url = app.base_url
        config = load_config(app)
        directory = config.workspaces_dir
        page_url = config.page_url

        if len(self.extra_args) > 1:
            print('Too many arguments were provided for workspace export.')
            sys.exit(1)

        raw = (page_url if not self.extra_args
               else ujoin(config.workspaces_url, self.extra_args[0]))
        slug = slugify(raw, base_url)
        workspace_path = os.path.join(directory, slug + WORKSPACE_EXTENSION)

        if os.path.exists(workspace_path):
            with open(workspace_path) as fid:
                try:  # to load the workspace file.
                    print(fid.read())
                except Exception as e:
                    print(json.dumps(dict(data=dict(), metadata=dict(id=raw))))
        else:
            print(json.dumps(dict(data=dict(), metadata=dict(id=raw))))
Exemple #6
0
    def start(self):
        app = LabApp()
        base_url = app.base_url
        config = load_config(app)
        directory = config.workspaces_dir
        page_url = config.page_url

        if len(self.extra_args) > 1:
            print('Too many arguments were provided for workspace export.')
            sys.exit(1)

        raw = (page_url if not self.extra_args else ujoin(
            config.workspaces_url, self.extra_args[0]))
        slug = slugify(raw, base_url)
        workspace_path = os.path.join(directory, slug + WORKSPACE_EXTENSION)

        if os.path.exists(workspace_path):
            with open(workspace_path) as fid:
                try:  # to load the workspace file.
                    print(fid.read())
                except Exception as e:
                    print(json.dumps(dict(data=dict(), metadata=dict(id=raw))))
        else:
            print(json.dumps(dict(data=dict(), metadata=dict(id=raw))))