Pose a dialog to name and clone a workspace.
160105
def clone_workspace(self) -> None:
        

        def clone_clicked(text):
            if text:
                command = Workspace.CloneWorkspaceCommand(self, text)
                command.perform()
                self.document_controller.push_undo_command(command)

        self.pose_get_string_message_box(caption=_("Enter a name for the workspace"), text=self.__workspace.name,
                                         accepted_fn=clone_clicked, accepted_text=_("Clone"),
                                         message_box_id="clone_workspace")
913695
def create_dialog(self):
        """"""
        self.bbox = QDialogButtonBox(QDialogButtonBox.Close)
        self.idx_close = self.bbox.button(QDialogButtonBox.Close)
        self.idx_close.pressed.connect(self.reject)

        btnlayout = QHBoxLayout()
        btnlayout.addStretch(1)
        btnlayout.addWidget(self.bbox)

        layout = QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        layout.addLayout(btnlayout)
        layout.addStretch(1)
        self.setLayout(layout)
1150146
def make_workspace(measurement, channel=None, name=None, silence=False):
    
    context = silence_sout_serr if silence else do_nothing
    with context():
        hist2workspace = ROOT.RooStats.HistFactory.HistoToWorkspaceFactoryFast(
            measurement)
        if channel is not None:
            workspace = hist2workspace.MakeSingleChannelModel(
                measurement, channel)
        else:
            workspace = hist2workspace.MakeCombinedModel(measurement)
    workspace = asrootpy(workspace)
    keepalive(workspace, measurement)
    if name is not None:
        workspace.SetName('workspace_{0}'.format(name))
    return workspace
1102515
def acquire(self, username, password, frontend='headless'):
        """"""
        with self._lock() as root_session:
            for clone in self._clones:
                # Search for a free clone
                session = Session()
                try:
                    clone.lock_machine(session, LockType.write)
                except Exception:
                    continue
                else:
                    try:
                        p = session.machine.restore_snapshot()
                        p.wait_for_completion(60 * 1000)
                    except Exception:
                        pass
                    session.unlock_machine()
                    break
            else:
                # Build a new clone
                machine = root_session.machine
                clone = machine.clone(name="%s Pool" % self.machine_name)
                p = clone.launch_vm_process(type_p=frontend)
                p.wait_for_completion(60 * 1000)
                session = clone.create_session()
                console = session.console
                guest = console.guest
                try:
                    guest_session = guest.create_session(username, password,
                                                         timeout_ms=300 * 1000)
                    idle_count = 0
                    timeout = 60
                    while idle_count < 5 and timeout > 0:
                        act = console.get_device_activity([DeviceType.hard_disk])
                        if act[0] == DeviceActivity.idle:
                            idle_count += 1
                        time.sleep(0.5)
                        timeout -= 0.5
                    guest_session.close()
                    console.pause()
                    p, id_p = console.machine.take_snapshot('initialised',
                                                            'machine pool',
                                                            True)
                    p.wait_for_completion(60 * 1000)
                    self._power_down(session)
                finally:
                    if session.state == SessionState.locked:
                        session.unlock_machine()

            # Launch our clone
            p = clone.launch_vm_process(type_p=frontend)
            p.wait_for_completion(60 * 1000)
            session = clone.create_session()
            return session
305474
def clone(cls, variable, **kwargs):
        
        return cls(variable.name, lb=variable.lb, ub=variable.ub, type=variable.type, **kwargs)
104764
def new_workspace(self, name=None, layout=None, workspace_id=None, index=None) -> WorkspaceLayout.WorkspaceLayout:
        
        workspace = WorkspaceLayout.WorkspaceLayout()
        self.document_model.insert_workspace(index if index is not None else len(self.document_model.workspaces), workspace)
        d = create_image_desc()
        d["selected"] = True
        workspace.layout = layout if layout is not None else d
        workspace.name = name if name is not None else _("Workspace")
        if workspace_id:
            workspace.workspace_id = workspace_id
        return workspace
931769
def workspace_clone(ctx, clobber_mets, download, mets_url, workspace_dir):
    
    workspace = ctx.resolver.workspace_from_url(
        mets_url,
        dst_dir=os.path.abspath(workspace_dir if workspace_dir else mkdtemp(prefix=TMP_PREFIX)),
        mets_basename=ctx.mets_basename,
        clobber_mets=clobber_mets,
        download=download,
    )
    workspace.save_mets()
    print(workspace.directory)
332525
def copy_from(self, other):
        """"""
        self.verbose, self.quiet, self.path, self.name, self.tracing = other.verbose, other.quiet, other.path, other.name, other.tracing
560674
function clone (frame) {
  return make(frame.x, frame.y, frame.width, frame.height);
}
361481
def rename_workspace(self) -> None:
        

        def rename_clicked(text):
            if len(text) > 0:
                command = Workspace.RenameWorkspaceCommand(self, text)
                command.perform()
                self.document_controller.push_undo_command(command)

        self.pose_get_string_message_box(caption=_("Enter new name for workspace"), text=self.__workspace.name,
                                         accepted_fn=rename_clicked, accepted_text=_("Rename"),
                                         message_box_id="rename_workspace")
751335
def clone(self) -> 'ImageBBox':
        ""
        flow = FlowField(self.size, self.flow.flow.clone())
        return self.__class__(flow, scale=False, y_first=False, labels=self.labels, pad_idx=self.pad_idx)
303766
def ensure_workspace(self, name, layout, workspace_id):
        
        workspace = next((workspace for workspace in self.document_model.workspaces if workspace.workspace_id == workspace_id), None)
        if not workspace:
            workspace = self.new_workspace(name=name, layout=layout, workspace_id=workspace_id)
        self._change_workspace(workspace)
1222394
def _set_name(self, name, inplace=False):
        
        inplace = validate_bool_kwarg(inplace, 'inplace')
        ser = self if inplace else self.copy()
        ser.name = name
        return ser
323018
def clone_to(self, target_catalog):
        """"""
        def _clone(obj_id):
            package_name = obj_id.get_identifier_namespace().split('.')[0]
            obj_name = obj_id.get_identifier_namespace().split('.')[1].lower()

            catalogs = {
                'assessment': 'bank',
                'repository': 'repository'
            }

            my_catalog_name = catalogs[package_name.lower()]

            mgr = self.my_osid_object._get_provider_manager(package_name.upper())

            if self.my_osid_object._proxy is not None:
                catalog_lookup_session = getattr(mgr, 'get_' + my_catalog_name + '_lookup_session')(
                    proxy=self.my_osid_object._proxy
                )
            else:
                catalog_lookup_session = getattr(mgr, 'get_' + my_catalog_name + '_lookup_session')()

            catalog = getattr(catalog_lookup_session, 'get_' + my_catalog_name)(target_catalog.ident)

            if self.my_osid_object._proxy is not None:
                admin_session = getattr(mgr, 'get_' + obj_name + '_admin_session_for_' + my_catalog_name)(
                    catalog.ident,
                    proxy=self.my_osid_object._proxy
                )
            else:
                admin_session = getattr(mgr, 'get_' + obj_name + '_admin_session_for_' + my_catalog_name)(catalog.ident)

            new_obj = getattr(admin_session, 'duplicate_' + obj_name)(obj_id)
            try:
                form = getattr(admin_session, 'get_' + obj_name + '_form_for_update')(new_obj.ident)
                form.set_provenance(str(obj_id))
                new_obj = getattr(admin_session, 'update_' + obj_name)(form)
            except AttributeError:
                pass
            return new_obj

        enclosed_object_id = self.get_enclosed_object_id()
        new_enclosed_object = _clone(enclosed_object_id)

        # Let's do the asset here
        enclosure_id = self.my_osid_object.ident
        new_asset = _clone(enclosure_id)
        package_name = enclosure_id.get_identifier_namespace().split('.')[0]
        obj_name = enclosure_id.get_identifier_namespace().split('.')[1].lower()

        catalogs = {
            'assessment': 'bank',
            'repository': 'repository'
        }

        my_catalog_name = catalogs[package_name.lower()]

        mgr = self.my_osid_object._get_provider_manager(package_name.upper())

        if self.my_osid_object._proxy is not None:
            catalog_lookup_session = getattr(mgr, 'get_' + my_catalog_name + '_lookup_session')(
                proxy=self.my_osid_object._proxy
            )
        else:
            catalog_lookup_session = getattr(mgr, 'get_' + my_catalog_name + '_lookup_session')()
        catalog = getattr(catalog_lookup_session, 'get_' + my_catalog_name)(target_catalog.ident)

        if self.my_osid_object._proxy is not None:
            admin_session = getattr(mgr, 'get_' + obj_name + '_admin_session_for_' + my_catalog_name)(
                catalog.ident,
                proxy=self.my_osid_object._proxy
            )
        else:
            admin_session = getattr(mgr, 'get_' + obj_name + '_admin_session_for_' + my_catalog_name)(catalog.ident)

        form = getattr(admin_session, 'get_' + obj_name + '_form_for_update')(new_asset.ident)
        form.set_enclosed_object(new_enclosed_object.ident)
        return getattr(admin_session, 'update_' + obj_name)(form)
854774
def _create_options_dialog_action(self):
        """"""
        icon = resources_path('img', 'icons', 'configure-inasafe.svg')
        self.action_options = QAction(
            QIcon(icon),
            self.tr('Options'), self.iface.mainWindow())
        self.action_options.setStatusTip(self.tr(
            'Open InaSAFE options dialog'))
        self.action_options.setWhatsThis(self.tr(
            'Open InaSAFE options dialog'))
        self.action_options.triggered.connect(self.show_options)
        self.add_action(self.action_options, add_to_toolbar=self.full_toolbar)
1290098
def build_gui(self, container):
        """"""

        vbox, sw, orientation = Widgets.get_oriented_box(container)

        captions = (('Channel:', 'label', 'Channel Name', 'combobox',
                     'Modified only', 'checkbutton'), )
        w, b = Widgets.build_info(captions, orientation=orientation)
        self.w.update(b)

        b.channel_name.set_tooltip('Channel for locating images to save')
        b.channel_name.add_callback('activated', self.select_channel_cb)

        mod_only = self.settings.get('modified_only', True)
        b.modified_only.set_state(mod_only)
        b.modified_only.add_callback('activated', lambda *args: self.redo())
        b.modified_only.set_tooltip("Show only locally modified images")

        container.add_widget(w, stretch=0)

        captions = (('Path:', 'llabel', 'OutDir', 'entry', 'Browse', 'button'),
                    ('Suffix:', 'llabel', 'Suffix', 'entry'))
        w, b = Widgets.build_info(captions, orientation=orientation)
        self.w.update(b)

        b.outdir.set_text(self.outdir)
        b.outdir.set_tooltip('Output directory')
        b.outdir.add_callback('activated', lambda w: self.set_outdir())

        b.browse.set_tooltip('Browse for output directory')
        b.browse.add_callback('activated', lambda w: self.browse_outdir())

        b.suffix.set_text(self.suffix)
        b.suffix.set_tooltip('Suffix to append to filename')
        b.suffix.add_callback('activated', lambda w: self.set_suffix())

        container.add_widget(w, stretch=0)

        self.treeview = Widgets.TreeView(auto_expand=True,
                                         sortable=True,
                                         selection='multiple',
                                         use_alt_row_color=True)
        self.treeview.setup_table(self.columns, 1, 'IMAGE')
        self.treeview.add_callback('selected', self.toggle_save_cb)
        container.add_widget(self.treeview, stretch=1)

        captions = (('Status', 'llabel'), )
        w, b = Widgets.build_info(captions, orientation=orientation)
        self.w.update(b)
        b.status.set_text('')
        b.status.set_tooltip('Status message')
        container.add_widget(w, stretch=0)

        btns = Widgets.HBox()
        btns.set_border_width(4)
        btns.set_spacing(3)

        btn = Widgets.Button('Save')
        btn.set_tooltip('Save selected image(s)')
        btn.add_callback('activated', lambda w: self.save_images())
        btn.set_enabled(False)
        btns.add_widget(btn, stretch=0)
        self.w.save = btn

        btn = Widgets.Button('Close')
        btn.add_callback('activated', lambda w: self.close())
        btns.add_widget(btn, stretch=0)
        btn = Widgets.Button("Help")
        btn.add_callback('activated', lambda w: self.help())
        btns.add_widget(btn, stretch=0)
        btns.add_widget(Widgets.Label(''), stretch=1)
        container.add_widget(btns, stretch=0)

        self.gui_up = True

        # Initialize directory selection dialog
        self.dirsel = DirectorySelection(self.fv.w.root.get_widget())

        # Generate initial listing
        self.update_channels()
43194
def add_namespace(self, name, a_namespace):
        """"""
        # save a local copy of the namespace
        self.namespaces[name] = a_namespace
        # iterate through the namespace branding each of the options with the
        # name of the subparser to which they belong
        for k in a_namespace.keys_breadth_first():
            an_option = a_namespace[k]
            if not an_option.foreign_data:
                an_option.foreign_data = DotDict()
            an_option.foreign_data['argparse.owning_subparser_name'] = name