def apply_device_dir(self, device_directory):
        '''
        .. versionchanged:: 2.21
            Use :func:`path_helpers.resource_copytree` to support when copying
            from a module stored in a ``.zip`` archive or ``.egg`` file.
        '''
        app = get_app()

        # if the device directory is empty or None, set a default
        if not device_directory:
            device_directory = (ph.path(app.config.data['data_dir'])
                                .joinpath('devices'))
            self.set_app_values({'device_directory': device_directory})

        if self.previous_device_dir and (device_directory ==
                                         self.previous_device_dir):
            # If the data directory hasn't changed, we do nothing
            return False

        device_directory = ph.path(device_directory)
        if self.previous_device_dir:
            device_directory.makedirs_p()
            if device_directory.listdir():
                result = yesno('Merge?', '''\
Target directory [%s] is not empty.  Merge contents with
current devices [%s] (overwriting common paths in the target
directory)?''' % (device_directory, self.previous_device_dir))
                if not result == gtk.RESPONSE_YES:
                    return False

            original_directory = ph.path(self.previous_device_dir)
            for d in original_directory.dirs():
                copytree(d, device_directory.joinpath(d.name))
            for f in original_directory.files():
                f.copyfile(device_directory.joinpath(f.name))
            original_directory.rmtree()
        elif not device_directory.isdir():
            # if the device directory doesn't exist, copy the skeleton dir
            if device_directory.parent:
                device_directory.parent.makedirs_p()
            # XXX Use `path_helpers.resource_copytree` to support when copying
            # from a module stored in a `.zip` archive or `.egg` file.
            ph.resource_copytree('microdrop', 'devices', device_directory)
        self.previous_device_dir = device_directory
        return True
Ejemplo n.º 2
0
    def apply_device_dir(self, device_directory):
        app = get_app()

        # if the device directory is empty or None, set a default
        if not device_directory:
            device_directory = (ph.path(
                app.config.data['data_dir']).joinpath('devices'))
            self.set_app_values({'device_directory': device_directory})

        if self.previous_device_dir and (device_directory
                                         == self.previous_device_dir):
            # If the data directory hasn't changed, we do nothing
            return False

        device_directory = ph.path(device_directory)
        if self.previous_device_dir:
            device_directory.makedirs_p()
            if device_directory.listdir():
                result = yesno(
                    'Merge?', '''\
Target directory [%s] is not empty.  Merge contents with
current devices [%s] (overwriting common paths in the target
directory)?''' % (device_directory, self.previous_device_dir))
                if not result == gtk.RESPONSE_YES:
                    return False

            original_directory = ph.path(self.previous_device_dir)
            for d in original_directory.dirs():
                copytree(d, device_directory.joinpath(d.name))
            for f in original_directory.files():
                f.copyfile(device_directory.joinpath(f.name))
            original_directory.rmtree()
        elif not device_directory.isdir():
            # if the device directory doesn't exist, copy the skeleton dir
            if device_directory.parent:
                device_directory.parent.makedirs_p()
            base_path().joinpath('devices').copytree(device_directory)
        self.previous_device_dir = device_directory
        return True
Ejemplo n.º 3
0
    def apply_device_dir(self, device_directory):
        app = get_app()

        # if the device directory is empty or None, set a default
        if not device_directory:
            device_directory = (ph.path(app.config.data['data_dir'])
                                .joinpath('devices'))
            self.set_app_values({'device_directory': device_directory})

        if self.previous_device_dir and (device_directory ==
                                         self.previous_device_dir):
            # If the data directory hasn't changed, we do nothing
            return False

        device_directory = ph.path(device_directory)
        if self.previous_device_dir:
            device_directory.makedirs_p()
            if device_directory.listdir():
                result = yesno('Merge?', '''\
Target directory [%s] is not empty.  Merge contents with
current devices [%s] (overwriting common paths in the target
directory)?''' % (device_directory, self.previous_device_dir))
                if not result == gtk.RESPONSE_YES:
                    return False

            original_directory = ph.path(self.previous_device_dir)
            for d in original_directory.dirs():
                copytree(d, device_directory.joinpath(d.name))
            for f in original_directory.files():
                f.copyfile(device_directory.joinpath(f.name))
            original_directory.rmtree()
        elif not device_directory.isdir():
            # if the device directory doesn't exist, copy the skeleton dir
            if device_directory.parent:
                device_directory.parent.makedirs_p()
            base_path().joinpath('devices').copytree(device_directory)
        self.previous_device_dir = device_directory
        return True
    def apply_notebook_dir(self, notebook_directory):
        '''
        Set the notebook directory to the specified directory.

        If the specified directory is empty or `None`, use the default
        directory (i.e., in the default Microdrop user directory) as the new
        directory path.

        If no directory was previously set and the specified directory does not
        exist, copy the default set of notebooks from the `microdrop` package
        to the new notebook directory.

        If a directory was previously set, copy the contents of the previous
        directory to the new directory (prompting the user to overwrite if the
        new directory already exists).
        '''
        app = get_app()

        print '[{notebook_directory = "%s"}]' % notebook_directory
        if not notebook_directory:
            # The notebook directory is not set (i.e., empty or `None`), so set
            # a default.
            data_directory = path(app.config.data['data_dir'])
            notebook_directory = data_directory.joinpath( 'notebooks')
            print '[{new notebook_directory = "%s"}]' % notebook_directory
            app_values = self.get_app_values().copy()
            app_values['notebook_directory'] = notebook_directory
            self.set_app_values(app_values)

        if self.previous_notebook_dir and (notebook_directory ==
                                           self.previous_notebook_dir):
            # If the data directory hasn't changed, we do nothing
            return False

        notebook_directory = path(notebook_directory)
        if self.previous_notebook_dir:
            notebook_directory.makedirs_p()
            if notebook_directory.listdir():
                result = yesno('Merge?', '''\
Target directory [%s] is not empty.  Merge contents with
current notebooks [%s] (overwriting common paths in the target
directory)?''' % (notebook_directory, self.previous_notebook_dir))
                if not result == gtk.RESPONSE_YES:
                    return False

            original_directory = path(self.previous_notebook_dir)
            for d in original_directory.dirs():
                copytree(d, notebook_directory.joinpath(d.name))
            for f in original_directory.files():
                f.copyfile(notebook_directory.joinpath(f.name))
            original_directory.rmtree()
        elif not notebook_directory.isdir():
            # if the notebook directory doesn't exist, copy the skeleton dir
            notebook_directory.parent.makedirs_p()
            skeleton_dir = path(pkg_resources.resource_filename('microdrop',
                                                                'static'))
            skeleton_dir.joinpath('notebooks').copytree(notebook_directory)
        self.previous_notebook_dir = notebook_directory
        # Set the default template directory of the IPython notebook manager
        # widget to the notebooks directory.
        self.notebook_manager_view.template_dir = notebook_directory
Ejemplo n.º 5
0
    def apply_notebook_dir(self, notebook_directory):
        '''
        Set the notebook directory to the specified directory.

        If the specified directory is empty or `None`, use the default
        directory (i.e., in the default MicroDrop user directory) as the new
        directory path.

        If no directory was previously set and the specified directory does not
        exist, copy the default set of notebooks from the `microdrop` package
        to the new notebook directory.

        If a directory was previously set, copy the contents of the previous
        directory to the new directory (prompting the user to overwrite if the
        new directory already exists).
        '''
        app = get_app()

        print '[{notebook_directory = "%s"}]' % notebook_directory
        if not notebook_directory:
            # The notebook directory is not set (i.e., empty or `None`), so set
            # a default.
            data_directory = path(app.config.data['data_dir'])
            notebook_directory = data_directory.joinpath('notebooks')
            print '[{new notebook_directory = "%s"}]' % notebook_directory
            app_values = self.get_app_values().copy()
            app_values['notebook_directory'] = notebook_directory
            self.set_app_values(app_values)

        if self.previous_notebook_dir and (notebook_directory
                                           == self.previous_notebook_dir):
            # If the data directory hasn't changed, we do nothing
            return False

        notebook_directory = path(notebook_directory)
        if self.previous_notebook_dir:
            notebook_directory.makedirs_p()
            if notebook_directory.listdir():
                result = yesno(
                    'Merge?', 'Target directory [%s] is not empty.  Merge '
                    'contents with current notebooks [%s] '
                    '(overwriting common paths in the target '
                    'directory)?' %
                    (notebook_directory, self.previous_notebook_dir))
                if not result == gtk.RESPONSE_YES:
                    return False

            original_directory = path(self.previous_notebook_dir)
            for d in original_directory.dirs():
                copytree(d, notebook_directory.joinpath(d.name))
            for f in original_directory.files():
                f.copyfile(notebook_directory.joinpath(f.name))
            original_directory.rmtree()
        elif not notebook_directory.isdir():
            # if the notebook directory doesn't exist, copy the skeleton dir
            if notebook_directory.parent:
                notebook_directory.parent.makedirs_p()
            skeleton_dir = path(
                pkg_resources.resource_filename('microdrop', 'static'))
            skeleton_dir.joinpath('notebooks').copytree(notebook_directory)
        self.previous_notebook_dir = notebook_directory
        # Set the default template directory of the IPython notebook manager
        # widget to the notebooks directory.
        self.notebook_manager_view.template_dir = notebook_directory