text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_task(self, ): """Create a task and store it in the self.task :returns: None :rtype: None :raises: None """
depi = self.dep_cb.currentIndex() assert depi >= 0 dep = self.deps[depi] deadline = self.deadline_de.dateTime().toPython() try: task = djadapter.models.Task(department=dep, project=self.element.project, element=self.element, deadline=deadline) task.save() self.task = task self.accept() except: log.exception("Could not create new task")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_ui(self, ): """Create all necessary ui elements for the tool :returns: None :rtype: None :raises: None """
log.debug("Setting up the ui") self.setup_prjs_page() self.setup_prj_page() self.setup_seq_page() self.setup_shot_page() self.setup_atype_page() self.setup_asset_page() self.setup_dep_page() self.setup_task_page() self.setup_users_page() self.setup_user_page()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_prjs_page(self, ): """Create and set the model on the projects page :returns: None :rtype: None :raises: None """
self.prjs_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents) log.debug("Loading projects for projects page.") rootdata = treemodel.ListItemData(['Name', 'Short', 'Path', 'Created', 'Semester', 'Status', 'Resolution', 'FPS', 'Scale']) rootitem = treemodel.TreeItem(rootdata) prjs = djadapter.projects.all() for prj in prjs: prjdata = djitemdata.ProjectItemData(prj) treemodel.TreeItem(prjdata, rootitem) self.prjs_model = treemodel.TreeModel(rootitem) self.prjs_tablev.setModel(self.prjs_model)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_prj_page(self, ): """Create and set the model on the project page :returns: None :rtype: None :raises: None """
self.prj_seq_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.prj_atype_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.prj_dep_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.prj_user_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_shot_page(self, ): """Create and set the model on the shot page :returns: None :rtype: None :raises: None """
self.shot_asset_treev.header().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.shot_task_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_asset_page(self, ): """Create and set the model on the asset page :returns: None :rtype: None :raises: None """
self.asset_asset_treev.header().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.asset_task_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_users_page(self, ): """Create and set the model on the users page :returns: None :rtype: None :raises: None """
self.users_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents) log.debug("Loading users for users page.") rootdata = treemodel.ListItemData(['Username', 'First', 'Last', 'Email']) rootitem = treemodel.TreeItem(rootdata) users = djadapter.users.all() for usr in users: usrdata = djitemdata.UserItemData(usr) treemodel.TreeItem(usrdata, rootitem) self.users_model = treemodel.TreeModel(rootitem) self.users_tablev.setModel(self.users_model)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_user_page(self, ): """Create and set the model on the user page :returns: None :rtype: None :raises: None """
self.user_prj_tablev.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.user_task_treev.header().setResizeMode(QtGui.QHeaderView.ResizeToContents)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_prjs_signals(self, ): """Setup the signals for the projects page :returns: None :rtype: None :raises: None """
log.debug("Setting up projects page signals.") self.prjs_prj_view_pb.clicked.connect(self.prjs_view_prj) self.prjs_prj_create_pb.clicked.connect(self.prjs_create_prj)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_prj_signals(self, ): """Setup the signals for the project page :returns: None :rtype: None :raises: None """
log.debug("Setting up project page signals.") self.prj_seq_view_pb.clicked.connect(self.prj_view_seq) self.prj_seq_create_pb.clicked.connect(self.prj_create_seq) self.prj_atype_view_pb.clicked.connect(self.prj_view_atype) self.prj_atype_add_pb.clicked.connect(self.prj_add_atype) self.prj_atype_create_pb.clicked.connect(self.prj_create_atype) self.prj_dep_view_pb.clicked.connect(self.prj_view_dep) self.prj_dep_add_pb.clicked.connect(self.prj_add_dep) self.prj_dep_create_pb.clicked.connect(self.prj_create_dep) self.prj_user_view_pb.clicked.connect(self.prj_view_user) self.prj_user_add_pb.clicked.connect(self.prj_add_user) self.prj_user_remove_pb.clicked.connect(self.prj_remove_user) self.prj_user_create_pb.clicked.connect(self.prj_create_user) self.prj_path_view_pb.clicked.connect(self.prj_show_path) self.prj_desc_pte.textChanged.connect(self.prj_save) self.prj_semester_le.editingFinished.connect(self.prj_save) self.prj_fps_dsb.valueChanged.connect(self.prj_save) self.prj_res_x_sb.valueChanged.connect(self.prj_save) self.prj_res_y_sb.valueChanged.connect(self.prj_save) self.prj_scale_cb.currentIndexChanged.connect(self.prj_save)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_seq_signals(self, ): """Setup the signals for the sequence page :returns: None :rtype: None :raises: None """
log.debug("Setting up sequence page signals.") self.seq_prj_view_pb.clicked.connect(self.seq_view_prj) self.seq_shot_view_pb.clicked.connect(self.seq_view_shot) self.seq_shot_create_pb.clicked.connect(self.seq_create_shot) self.seq_desc_pte.textChanged.connect(self.seq_save)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_shot_signals(self, ): """Setup the signals for the shot page :returns: None :rtype: None :raises: None """
log.debug("Setting up shot page signals.") self.shot_prj_view_pb.clicked.connect(self.shot_view_prj) self.shot_seq_view_pb.clicked.connect(self.shot_view_seq) self.shot_asset_view_pb.clicked.connect(self.shot_view_asset) self.shot_asset_create_pb.clicked.connect(self.shot_create_asset) self.shot_asset_add_pb.clicked.connect(self.shot_add_asset) self.shot_asset_remove_pb.clicked.connect(self.shot_remove_asset) self.shot_task_view_pb.clicked.connect(self.shot_view_task) self.shot_task_create_pb.clicked.connect(self.shot_create_task) self.shot_start_sb.valueChanged.connect(self.shot_save) self.shot_end_sb.valueChanged.connect(self.shot_save) self.shot_handle_sb.valueChanged.connect(self.shot_save) self.shot_desc_pte.textChanged.connect(self.shot_save)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_atype_signals(self, ): """Setup the signals for the assettype page :returns: None :rtype: None :raises: None """
log.debug("Setting up atype page signals.") self.asset_prj_view_pb.clicked.connect(self.asset_view_prj) self.asset_atype_view_pb.clicked.connect(self.asset_view_atype) self.atype_asset_view_pb.clicked.connect(self.atype_view_asset) self.atype_asset_create_pb.clicked.connect(self.atype_create_asset) self.atype_desc_pte.textChanged.connect(self.atype_save)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_asset_signals(self, ): """Setup the signals for the asset page :returns: None :rtype: None :raises: None """
log.debug("Setting up asset signals.") self.asset_asset_view_pb.clicked.connect(self.asset_view_asset) self.asset_asset_create_pb.clicked.connect(self.asset_create_asset) self.asset_asset_add_pb.clicked.connect(self.asset_add_asset) self.asset_asset_remove_pb.clicked.connect(self.asset_remove_asset) self.asset_task_view_pb.clicked.connect(self.asset_view_task) self.asset_task_create_pb.clicked.connect(self.asset_create_task) self.asset_desc_pte.textChanged.connect(self.asset_save)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_dep_signals(self, ): """Setup the signals for the department page :returns: None :rtype: None :raises: None """
log.debug("Setting up department page signals.") self.dep_prj_view_pb.clicked.connect(self.dep_view_prj) self.dep_prj_add_pb.clicked.connect(self.dep_add_prj) self.dep_prj_remove_pb.clicked.connect(self.dep_remove_prj) self.dep_desc_pte.textChanged.connect(self.dep_save) self.dep_ordervalue_sb.valueChanged.connect(self.dep_save)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_task_signals(self, ): """Setup the signals for the task page :returns: None :rtype: None :raises: None """
log.debug("Setting up task page signals.") self.task_user_view_pb.clicked.connect(self.task_view_user) self.task_user_add_pb.clicked.connect(self.task_add_user) self.task_user_remove_pb.clicked.connect(self.task_remove_user) self.task_dep_view_pb.clicked.connect(self.task_view_dep) self.task_link_view_pb.clicked.connect(self.task_view_link) self.task_deadline_de.dateChanged.connect(self.task_save) self.task_status_cb.currentIndexChanged.connect(self.task_save)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_users_signals(self, ): """Setup the signals for the users page :returns: None :rtype: None :raises: None """
log.debug("Setting up users page signals.") self.users_user_view_pb.clicked.connect(self.users_view_user) self.users_user_create_pb.clicked.connect(self.create_user)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_user_signals(self, ): """Setup the signals for the user page :returns: None :rtype: None :raises: None """
log.debug("Setting up user page signals.") self.user_task_view_pb.clicked.connect(self.user_view_task) self.user_prj_view_pb.clicked.connect(self.user_view_prj) self.user_prj_add_pb.clicked.connect(self.user_add_prj) self.user_prj_remove_pb.clicked.connect(self.user_remove_prj) self.user_username_le.editingFinished.connect(self.user_save) self.user_first_le.editingFinished.connect(self.user_save) self.user_last_le.editingFinished.connect(self.user_save) self.user_email_le.editingFinished.connect(self.user_save)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prjs_view_prj(self, *args, **kwargs): """View the, in the projects table view selected, project. :returns: None :rtype: None :raises: None """
i = self.prjs_tablev.currentIndex() item = i.internalPointer() if item: prj = item.internal_data() self.view_prj(prj)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view_prj(self, prj): """View the given project on the project page :param prj: the project to view :type prj: :class:`jukeboxcore.djadapter.models.Project` :returns: None :rtype: None :raises: None """
log.debug('Viewing project %s', prj.name) self.cur_prj = None self.pages_tabw.setCurrentIndex(1) self.prj_name_le.setText(prj.name) self.prj_short_le.setText(prj.short) self.prj_path_le.setText(prj.path) self.prj_desc_pte.setPlainText(prj.description) self.prj_created_dte.setDateTime(dt_to_qdatetime(prj.date_created)) self.prj_semester_le.setText(prj.semester) self.prj_fps_dsb.setValue(prj.framerate) self.prj_res_x_sb.setValue(prj.resx) self.prj_res_y_sb.setValue(prj.resy) scalemap = {"m": 2, "meter": 2, "mm": 0, "millimeter": 0, "cm": 1, "centimeter": 1, "km": 3, "kilometer": 3, "inch": 4, "foot": 5, "yard": 6, "mile": 7} scaleindex = scalemap.get(prj.scale, -1) log.debug("Setting index of project scale combobox to %s. Scale is %s", scaleindex, prj.scale) self.prj_scale_cb.setCurrentIndex(scaleindex) seqrootdata = treemodel.ListItemData(['Name', "Description"]) seqrootitem = treemodel.TreeItem(seqrootdata) for seq in prj.sequence_set.all(): seqdata = djitemdata.SequenceItemData(seq) treemodel.TreeItem(seqdata, seqrootitem) self.prj_seq_model = treemodel.TreeModel(seqrootitem) self.prj_seq_tablev.setModel(self.prj_seq_model) atyperootdata = treemodel.ListItemData(['Name', "Description"]) atyperootitem = treemodel.TreeItem(atyperootdata) for atype in prj.atype_set.all(): atypedata = djitemdata.AtypeItemData(atype) treemodel.TreeItem(atypedata, atyperootitem) self.prj_atype_model = treemodel.TreeModel(atyperootitem) self.prj_atype_tablev.setModel(self.prj_atype_model) deprootdata = treemodel.ListItemData(['Name', "Description", "Ordervalue"]) deprootitem = treemodel.TreeItem(deprootdata) for dep in prj.department_set.all(): depdata = djitemdata.DepartmentItemData(dep) treemodel.TreeItem(depdata, deprootitem) self.prj_dep_model = treemodel.TreeModel(deprootitem) self.prj_dep_tablev.setModel(self.prj_dep_model) userrootdata = treemodel.ListItemData(['Username', 'First', 'Last', 'Email']) userrootitem = treemodel.TreeItem(userrootdata) for user in prj.users.all(): userdata = djitemdata.UserItemData(user) treemodel.TreeItem(userdata, userrootitem) self.prj_user_model = treemodel.TreeModel(userrootitem) self.prj_user_tablev.setModel(self.prj_user_model) self.cur_prj = prj
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_prj(self, atypes=None, deps=None): """Create and return a new project :param atypes: add the given atypes to the project :type atypes: list | None :param deps: add the given departmetns to the project :type deps: list | None :returns: The created project or None :rtype: None | :class:`jukeboxcore.djadapter.models.Project` :raises: None """
dialog = ProjectCreatorDialog(parent=self) dialog.exec_() prj = dialog.project if prj and atypes: for at in atypes: at.projects.add(prj) at.save() if prj and deps: for dep in deps: dep.projects.add(prj) dep.save() if prj: prjdata = djitemdata.ProjectItemData(prj) treemodel.TreeItem(prjdata, self.prjs_model.root) return prj
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_view_seq(self, *args, **kwargs): """View the, in the prj_seq_tablev selected, sequence. :returns: None :rtype: None :raises: None """
if not self.cur_prj: return i = self.prj_seq_tablev.currentIndex() item = i.internalPointer() if item: seq = item.internal_data() self.view_seq(seq)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_create_seq(self, *args, **kwargs): """Create a new Sequence for the current project :returns: None :rtype: None :raises: None """
if not self.cur_prj: return seq = self.create_seq(project=self.cur_prj) if seq: seqdata = djitemdata.SequenceItemData(seq) treemodel.TreeItem(seqdata, self.prj_seq_model.root)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view_seq(self, seq): """View the given sequence on the sequence page :param seq: the sequence to view :type seq: :class:`jukeboxcore.djadapter.models.Sequence` :returns: None :rtype: None :raises: None """
log.debug('Viewing sequence %s', seq.name) self.cur_seq = None self.pages_tabw.setCurrentIndex(2) self.seq_name_le.setText(seq.name) self.seq_prj_le.setText(seq.project.name) self.seq_desc_pte.setPlainText(seq.description) shotrootdata = treemodel.ListItemData(['Name', "Description", "Duration", "Start", "End"]) shotrootitem = treemodel.TreeItem(shotrootdata) for shot in seq.shot_set.all(): shotdata = djitemdata.ShotItemData(shot) treemodel.TreeItem(shotdata, shotrootitem) self.seq_shot_model = treemodel.TreeModel(shotrootitem) self.seq_shot_tablev.setModel(self.seq_shot_model) self.cur_seq = seq
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_seq(self, project): """Create and return a new sequence :param project: the project for the sequence :type deps: :class:`jukeboxcore.djadapter.models.Project` :returns: The created sequence or None :rtype: None | :class:`jukeboxcore.djadapter.models.Sequence` :raises: None """
dialog = SequenceCreatorDialog(project=project, parent=self) dialog.exec_() seq = dialog.sequence return seq
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_view_atype(self, *args, **kwargs): """View the, in the atype table view selected, assettype. :returns: None :rtype: None :raises: None """
if not self.cur_prj: return i = self.prj_atype_tablev.currentIndex() item = i.internalPointer() if item: atype = item.internal_data() self.view_atype(atype)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_add_atype(self, *args, **kwargs): """Add more assettypes to the project. :returns: None :rtype: None :raises: None """
if not self.cur_prj: return dialog = AtypeAdderDialog(project=self.cur_prj) dialog.exec_() atypes = dialog.atypes for atype in atypes: atypedata = djitemdata.AtypeItemData(atype) treemodel.TreeItem(atypedata, self.prj_atype_model.root)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_atype(self, projects): """Create and return a new atype :param projects: the projects for the atype :type projects: :class:`jukeboxcore.djadapter.models.Project` :returns: The created atype or None :rtype: None | :class:`jukeboxcore.djadapter.models.Atype` :raises: None """
dialog = AtypeCreatorDialog(projects=projects, parent=self) dialog.exec_() atype = dialog.atype return atype
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view_atype(self, atype): """View the given atype on the atype page :param atype: the atype to view :type atype: :class:`jukeboxcore.djadapter.models.Atype` :returns: None :rtype: None :raises: None """
if not self.cur_prj: return log.debug('Viewing atype %s', atype.name) self.cur_atype = None self.pages_tabw.setCurrentIndex(4) self.atype_name_le.setText(atype.name) self.atype_desc_pte.setPlainText(atype.description) assetrootdata = treemodel.ListItemData(['Name', 'Description']) assetrootitem = treemodel.TreeItem(assetrootdata) self.atype_asset_model = treemodel.TreeModel(assetrootitem) self.atype_asset_treev.setModel(self.atype_asset_model) for a in djadapter.assets.filter(project=self.cur_prj, atype=atype): assetdata = djitemdata.AssetItemData(a) treemodel.TreeItem(assetdata, assetrootitem) self.cur_atype = atype
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_view_dep(self, *args, **kwargs): """View the, in the dep table view selected, department. :returns: None :rtype: None :raises: None """
if not self.cur_prj: return i = self.prj_dep_tablev.currentIndex() item = i.internalPointer() if item: dep = item.internal_data() self.view_dep(dep)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_add_dep(self, *args, **kwargs): """Add more departments to the project. :returns: None :rtype: None :raises: None """
if not self.cur_prj: return dialog = DepAdderDialog(project=self.cur_prj) dialog.exec_() deps = dialog.deps for dep in deps: depdata = djitemdata.DepartmentItemData(dep) treemodel.TreeItem(depdata, self.prj_dep_model.root)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_dep(self, projects): """Create and return a new dep :param projects: the projects for the dep :type projects: :class:`jukeboxcore.djadapter.models.Project` :returns: The created dep or None :rtype: None | :class:`jukeboxcore.djadapter.models.Dep` :raises: None """
dialog = DepCreatorDialog(projects=projects, parent=self) dialog.exec_() dep = dialog.dep return dep
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view_dep(self, dep): """View the given department on the department page :param dep: the dep to view :type dep: :class:`jukeboxcore.djadapter.models.Department` :returns: None :rtype: None :raises: None """
log.debug('Viewing department %s', dep.name) self.cur_dep = None self.pages_tabw.setCurrentIndex(6) self.dep_name_le.setText(dep.name) self.dep_short_le.setText(dep.short) self.dep_shot_rb.setChecked(not dep.assetflag) self.dep_asset_rb.setChecked(dep.assetflag) self.dep_ordervalue_sb.setValue(dep.ordervalue) self.dep_desc_pte.setPlainText(dep.description) rootdata = treemodel.ListItemData(['Name', 'Short', 'Path', 'Created', 'Semester', 'Status', 'Resolution', 'FPS', 'Scale']) rootitem = treemodel.TreeItem(rootdata) prjs = dep.projects.all() for prj in prjs: prjdata = djitemdata.ProjectItemData(prj) treemodel.TreeItem(prjdata, rootitem) self.dep_prj_model = treemodel.TreeModel(rootitem) self.dep_prj_tablev.setModel(self.dep_prj_model) self.cur_dep = dep
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_view_user(self, *args, **kwargs): """View the, in the user table view selected, user. :returns: None :rtype: None :raises: None """
if not self.cur_prj: return i = self.prj_user_tablev.currentIndex() item = i.internalPointer() if item: user = item.internal_data() self.view_user(user)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_add_user(self, *args, **kwargs): """Add more users to the project. :returns: None :rtype: None :raises: None """
if not self.cur_prj: return dialog = UserAdderDialog(project=self.cur_prj) dialog.exec_() users = dialog.users for user in users: userdata = djitemdata.UserItemData(user) treemodel.TreeItem(userdata, self.prj_user_model.root) self.cur_prj.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_remove_user(self, *args, **kwargs): """Remove the, in the user table view selected, user. :returns: None :rtype: None :raises: None """
if not self.cur_prj: return i = self.prj_user_tablev.currentIndex() item = i.internalPointer() if item: user = item.internal_data() log.debug("Removing user %s.", user.username) item.set_parent(None) self.cur_prj.users.remove(user)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_user(self, projects=None, tasks=None): """Create and return a new user :param projects: the projects for the user :type projects: list of :class:`jukeboxcore.djadapter.models.Project` :param tasks: the tasks for the user :type tasks: list of :class:`jukeboxcore.djadapter.models.Task` :returns: The created user or None :rtype: None | :class:`jukeboxcore.djadapter.models.User` :raises: None """
projects = projects or [] tasks = tasks or [] dialog = UserCreatorDialog(projects=projects, tasks=tasks, parent=self) dialog.exec_() user = dialog.user if user: userdata = djitemdata.UserItemData(user) treemodel.TreeItem(userdata, self.users_model.root) return user
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_show_path(self, ): """Show the dir in the a filebrowser of the project :returns: None :rtype: None :raises: None """
f = self.prj_path_le.text() osinter = ostool.get_interface() osinter.open_path(f)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prj_save(self): """Save the current project :returns: None :rtype: None :raises: None """
if not self.cur_prj: return desc = self.prj_desc_pte.toPlainText() semester = self.prj_semester_le.text() fps = self.prj_fps_dsb.value() resx = self.prj_res_x_sb.value() resy = self.prj_res_y_sb.value() scale = self.prj_scale_cb.currentText() self.cur_prj.description = desc self.cur_prj.semester = semester self.cur_prj.framerate = fps self.cur_prj.resx = resx self.cur_prj.resy = resy self.cur_prj.scale = scale self.cur_prj.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def seq_save(self): """Save the current sequence :returns: None :rtype: None :raises: None """
if not self.cur_seq: return desc = self.seq_desc_pte.toPlainText() self.cur_seq.description = desc self.cur_seq.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def seq_view_shot(self, ): """View the shot that is selected in the table view of the sequence page :returns: None :rtype: None :raises: None """
if not self.cur_seq: return i = self.seq_shot_tablev.currentIndex() item = i.internalPointer() if item: shot = item.internal_data() self.view_shot(shot)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view_shot(self, shot): """View the given shot :param shot: the shot to view :type shot: :class:`jukeboxcore.djadapter.models.Shot` :returns: None :rtype: None :raises: None """
log.debug('Viewing shot %s', shot.name) self.cur_shot = None self.pages_tabw.setCurrentIndex(3) self.shot_name_le.setText(shot.name) self.shot_prj_le.setText(shot.project.name) self.shot_seq_le.setText(shot.sequence.name) self.shot_start_sb.setValue(shot.startframe) self.shot_end_sb.setValue(shot.endframe) self.shot_handle_sb.setValue(shot.handlesize) self.shot_desc_pte.setPlainText(shot.description) assetsrootdata = treemodel.ListItemData(["Name", "Description"]) assetsrootitem = treemodel.TreeItem(assetsrootdata) self.shot_asset_model = treemodel.TreeModel(assetsrootitem) self.shot_asset_treev.setModel(self.shot_asset_model) atypes = {} assets = shot.assets.all() for a in assets: atype = a.atype atypeitem = atypes.get(atype) if not atypeitem: atypedata = djitemdata.AtypeItemData(atype) atypeitem = treemodel.TreeItem(atypedata, assetsrootitem) atypes[atype] = atypeitem assetdata = djitemdata.AssetItemData(a) treemodel.TreeItem(assetdata, atypeitem) tasksrootdata = treemodel.ListItemData(["Name", "Short"]) tasksrootitem = treemodel.TreeItem(tasksrootdata) self.shot_task_model = treemodel.TreeModel(tasksrootitem) self.shot_task_tablev.setModel(self.shot_task_model) tasks = shot.tasks.all() for t in tasks: tdata = djitemdata.TaskItemData(t) treemodel.TreeItem(tdata, tasksrootitem) self.cur_shot = shot
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_shot(self, sequence): """Create and return a new shot :param sequence: the sequence for the shot :type sequence: :class:`jukeboxcore.djadapter.models.Sequence` :returns: The created shot or None :rtype: None | :class:`jukeboxcore.djadapter.models.Shot` :raises: None """
dialog = ShotCreatorDialog(sequence=sequence, parent=self) dialog.exec_() shot = dialog.shot return shot
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_task(self, element): """Create a new task for the given element :param element: the element for the task :type element: :class:`jukeboxcore.djadapter.models.Shot` | :class:`jukeboxcore.djadapter.models.Asset` :returns: None :rtype: None :raises: None """
dialog = TaskCreatorDialog(element=element, parent=self) dialog.exec_() task = dialog.task return task
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view_asset(self, asset): """View the given asset :param asset: the asset to view :type asset: :class:`jukeboxcore.djadapter.models.Asset` :returns: None :rtype: None :raises: None """
log.debug('Viewing asset %s', asset.name) self.cur_asset = None self.pages_tabw.setCurrentIndex(5) name = asset.name prj = asset.project.name atype = asset.atype.name desc = asset.description self.asset_name_le.setText(name) self.asset_prj_le.setText(prj) self.asset_atype_le.setText(atype) self.asset_desc_pte.setPlainText(desc) assetsrootdata = treemodel.ListItemData(["Name", "Description"]) assetsrootitem = treemodel.TreeItem(assetsrootdata) self.asset_asset_model = treemodel.TreeModel(assetsrootitem) self.asset_asset_treev.setModel(self.asset_asset_model) atypes = {} assets = asset.assets.all() for a in assets: atype = a.atype atypeitem = atypes.get(atype) if not atypeitem: atypedata = djitemdata.AtypeItemData(atype) atypeitem = treemodel.TreeItem(atypedata, assetsrootitem) atypes[atype] = atypeitem assetdata = djitemdata.AssetItemData(a) treemodel.TreeItem(assetdata, atypeitem) tasksrootdata = treemodel.ListItemData(["Name", "Short"]) tasksrootitem = treemodel.TreeItem(tasksrootdata) self.asset_task_model = treemodel.TreeModel(tasksrootitem) self.asset_task_tablev.setModel(self.asset_task_model) tasks = asset.tasks.all() for t in tasks: tdata = djitemdata.TaskItemData(t) treemodel.TreeItem(tdata, tasksrootitem) self.cur_asset = asset
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def shot_add_asset(self, *args, **kwargs): """Add more assets to the shot. :returns: None :rtype: None :raises: None """
if not self.cur_shot: return dialog = AssetAdderDialog(shot=self.cur_shot) dialog.exec_() assets = dialog.assets atypes = {} for c in self.shot_asset_model.root.childItems: atypes[c.internal_data()] = c for asset in assets: atypeitem = atypes.get(asset.atype) if not atypeitem: atypedata = djitemdata.AtypeItemData(asset.atype) atypeitem = treemodel.TreeItem(atypedata, self.shot_asset_model.root) atypes[asset.atype] = atypeitem assetdata = djitemdata.AssetItemData(asset) treemodel.TreeItem(assetdata, atypeitem) self.cur_shot.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_asset(self, project, atype=None, shot=None, asset=None): """Create and return a new asset :param project: the project for the asset :type project: :class:`jukeboxcore.djadapter.models.Project` :param atype: the assettype of the asset :type atype: :class:`jukeboxcore.djadapter.models.Atype` :param shot: the shot to add the asset to :type shot: :class:`jukeboxcore.djadapter.models.Shot` :param asset: the asset to add the new asset to :type asset: :class:`jukeboxcore.djadapter.models.Asset` :returns: The created asset or None :rtype: None | :class:`jukeboxcore.djadapter.models.Asset` :raises: None """
element = shot or asset dialog = AssetCreatorDialog(project=project, atype=atype, parent=self) dialog.exec_() asset = dialog.asset if not atype: element.assets.add(asset) return asset
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view_task(self, task): """View the given task :param task: the task to view :type task: :class:`jukeboxcore.djadapter.models.Task` :returns: None :rtype: None :raises: None """
log.debug('Viewing task %s', task.name) self.cur_task = None self.pages_tabw.setCurrentIndex(7) self.task_dep_le.setText(task.name) statusmap = {"New": 0, "Open": 1, "Done":2} self.task_status_cb.setCurrentIndex(statusmap.get(task.status, -1)) dt = dt_to_qdatetime(task.deadline) if task.deadline else None self.task_deadline_de.setDateTime(dt) self.task_link_le.setText(task.element.name) userrootdata = treemodel.ListItemData(['Username', 'First', 'Last', 'Email']) userrootitem = treemodel.TreeItem(userrootdata) for user in task.users.all(): userdata = djitemdata.UserItemData(user) treemodel.TreeItem(userdata, userrootitem) self.task_user_model = treemodel.TreeModel(userrootitem) self.task_user_tablev.setModel(self.task_user_model) self.cur_task = task
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def shot_save(self, ): """Save the current shot :returns: None :rtype: None :raises: None """
if not self.cur_shot: return desc = self.shot_desc_pte.toPlainText() start = self.shot_start_sb.value() end = self.shot_end_sb.value() handle = self.shot_handle_sb.value() self.cur_shot.description = desc self.cur_shot.startframe = start self.cur_shot.endframe = end self.cur_shot.handlesize = handle self.cur_shot.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def asset_view_prj(self, ): """View the project of the current asset :returns: None :rtype: None :raises: None """
if not self.cur_asset: return prj = self.cur_asset.project self.view_prj(prj)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def asset_view_atype(self, ): """View the project of the current atype :returns: None :rtype: None :raises: None """
if not self.cur_asset: return atype = self.cur_asset.atype self.view_atype(atype)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def atype_view_asset(self, ): """View the project of the current assettype :returns: None :rtype: None :raises: None """
if not self.cur_atype: return i = self.atype_asset_treev.currentIndex() item = i.internalPointer() if item: asset = item.internal_data() if isinstance(asset, djadapter.models.Asset): self.view_asset(asset)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def atype_save(self): """Save the current atype :returns: None :rtype: None :raises: None """
if not self.cur_atype: return desc = self.atype_desc_pte.toPlainText() self.cur_atype.description = desc self.cur_atype.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def asset_add_asset(self, *args, **kwargs): """Add more assets to the asset. :returns: None :rtype: None :raises: None """
if not self.cur_asset: return dialog = AssetAdderDialog(asset=self.cur_asset) dialog.exec_() assets = dialog.assets atypes = {} for c in self.asset_asset_model.root.childItems: atypes[c.internal_data()] = c for asset in assets: atypeitem = atypes.get(asset.atype) if not atypeitem: atypedata = djitemdata.AtypeItemData(asset.atype) atypeitem = treemodel.TreeItem(atypedata, self.asset_asset_model.root) atypes[asset.atype] = atypeitem assetdata = djitemdata.AssetItemData(asset) treemodel.TreeItem(assetdata, atypeitem) self.cur_asset.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def asset_save(self): """Save the current asset :returns: None :rtype: None :raises: None """
if not self.cur_asset: return desc = self.asset_desc_pte.toPlainText() self.cur_asset.description = desc self.cur_asset.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def dep_add_prj(self, *args, **kwargs): """Add projects to the current department :returns: None :rtype: None :raises: None """
if not self.cur_dep: return dialog = ProjectAdderDialog(department=self.cur_dep) dialog.exec_() prjs = dialog.projects for prj in prjs: prjdata = djitemdata.ProjectItemData(prj) treemodel.TreeItem(prjdata, self.dep_prj_model.root)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def dep_remove_prj(self, *args, **kwargs): """Remove the selected project from the department :returns: None :rtype: None :raises: None """
if not self.cur_dep: return i = self.dep_prj_tablev.currentIndex() item = i.internalPointer() if item: prj = item.internal_data() self.cur_dep.projects.remove(prj) item.set_parent(None)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def dep_save(self, ): """Save the current department :returns: None :rtype: None :raises: None """
if not self.cur_dep: return ordervalue = self.dep_ordervalue_sb.value() desc = self.dep_desc_pte.toPlainText() self.cur_dep.ordervalue = ordervalue self.cur_dep.description = desc self.cur_dep.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def task_add_user(self, *args, **kwargs): """Add users to the current task :returns: None :rtype: None :raises: None """
if not self.cur_task: return dialog = UserAdderDialog(task=self.cur_task) dialog.exec_() users = dialog.users for user in users: userdata = djitemdata.UserItemData(user) treemodel.TreeItem(userdata, self.task_user_model.root)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def task_remove_user(self, *args, **kwargs): """Remove the selected user from the task :returns: None :rtype: None :raises: None """
if not self.cur_task: return i = self.task_user_tablev.currentIndex() item = i.internalPointer() if item: user = item.internal_data() self.cur_task.users.remove(user) item.set_parent(None)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def task_view_link(self, ): """View the link of the current task :returns: None :rtype: None :raises: None """
if not self.cur_task: return e = self.cur_task.element if isinstance(e, djadapter.models.Asset): self.view_asset(e) else: self.view_shot(e)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def task_save(self, ): """Save the current task :returns: None :rtype: None :raises: None """
if not self.cur_task: return deadline = self.task_deadline_de.dateTime().toPython() status = self.task_status_cb.currentText() self.cur_task.deadline = deadline self.cur_task.status = status self.cur_task.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def user_view_task(self, ): """View the task that is selected :returns: None :rtype: None :raises: None """
if not self.cur_user: return i = self.user_task_treev.currentIndex() item = i.internalPointer() if item: task = item.internal_data() if isinstance(task, djadapter.models.Task): self.view_task(task)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def user_add_prj(self, *args, **kwargs): """Add projects to the current user :returns: None :rtype: None :raises: None """
if not self.cur_user: return dialog = ProjectAdderDialog(user=self.cur_user) dialog.exec_() prjs = dialog.projects for prj in prjs: prjdata = djitemdata.ProjectItemData(prj) treemodel.TreeItem(prjdata, self.user_prj_model.root)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def user_remove_prj(self, *args, **kwargs): """Remove the selected project from the user :returns: None :rtype: None :raises: None """
if not self.cur_user: return i = self.user_prj_tablev.currentIndex() item = i.internalPointer() if item: prj = item.internal_data() prj.users.remove(self.cur_user) item.set_parent(None)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def user_save(self): """Save the current user :returns: None :rtype: None :raises: None """
if not self.cur_user: return username = self.user_username_le.text() first = self.user_first_le.text() last = self.user_last_le.text() email = self.user_email_le.text() self.cur_user.username = username self.cur_user.first_name = first self.cur_user.last_name = last self.cur_user.email = email self.cur_user.save()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run(self): """Run self on provided screen"""
notice('Starting output thread', self.color) o = Thread(target=self.__output_thread, name='output') o.start() self.threads.append(o) try: notice('Starting input thread', self.color) self.__input_thread() except KeyboardInterrupt: self.__shutdown()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def __get_instructions(self): "Get info from sockets" if self.mode == 'c': c, m = utils.recv(self.__s) inst = [(c, m, self.__s)] else: inst = [] with self.__client_list_lock: for com in self.clients: c, m = utils.recv(com) if c is not None: inst.append((c, m, com)) return inst
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def __process_instructions(self, inst): "Act on instructions recieved" to_send = [] for cmd, msg, com in inst: if cmd not in config.CMDS: # ignore if it is not legal continue if cmd == 'MSG': if self.mode == 's': to_send.append((msg, com)) if self.color: txt = config.Col.BOLD + msg + config.Col.ENDC else: txt = msg print(txt) if self.issue_alert: os.system(self.alert) elif cmd == 'QUIT': if self.mode == 's': # client quit com.close() with self.__client_list_lock: self.clients.remove(com) else: # server quit self.__s.close() self.__make_client() # wait for new server elif cmd == 'ASSUME': if self.mode == 'c': # assume a server role if client self.__s.close() self.__make_server() for msg, sender in to_send: if self.mode == 'c': utils.msg(msg, self.__s) else: with self.__client_list_lock: for com in self.clients: if com == sender: continue utils.msg(msg, com)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def __make_server(self): "Make this node a server" notice('Making server, getting listening socket', self.color) self.mode = 's' sock = utils.get_server_sock() self.__s = sock with self.__client_list_lock: self.clients = deque() self.threads = deque() notice('Making beacon', self.color) b = Thread(target=self.__beacon_thread, name='beacon') b.start() self.threads.append(b) l = Thread(target=self.__listen_thread, name='listen') notice('Starting listen thread', self.color) l.start() self.threads.append(l)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def __make_client(self): "Make this node a client" notice('Making client, getting server connection', self.color) self.mode = 'c' addr = utils.get_existing_server_addr() sock = utils.get_client_sock(addr) self.__s = sock with self.__client_list_lock: self.clients = deque() self.threads = deque()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def erase_lines(n=1): """ Erases n lines from the screen and moves the cursor up to follow """
for _ in range(n): print(codes.cursor["up"], end="") print(codes.cursor["eol"], end="")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def move_cursor(cols=0, rows=0): """ Moves the cursor the given number of columns and rows The cursor is moved right when cols is positive and left when negative. The cursor is moved down when rows is positive and down when negative. """
if cols == 0 and rows == 0: return commands = "" commands += codes.cursor["up" if rows < 0 else "down"] * abs(rows) commands += codes.cursor["left" if cols < 0 else "right"] * abs(cols) if commands: print(commands, end="") stdout.flush()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def style_format(text, style): """ Wraps texts in terminal control sequences Style can be passed as either a collection or space delimited string. Valid styles can be found in the codes module. Invalid or unsuported styles will just be ignored. """
if not style: return text if isinstance(style, str): style = style.split(" ") prefix = "" for s in style: prefix += codes.colours.get(s, "") prefix += codes.highlights.get(s, "") prefix += codes.modes.get(s, "") return prefix + text + codes.modes["reset"]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def style_print(*values, **kwargs): """ A convenience function that applies style_format to text before printing """
style = kwargs.pop("style", None) values = [style_format(value, style) for value in values] print(*values, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def generate(cls, partial_props=None): """ Generate new connection file props from defaults """
partial_props = partial_props or {} props = partial_props.copy() props.update(cls.DEFAULT_PROPERTIES) return cls(props)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def write_file(self): """ Write a new connection file to disk. and return its path """
name = "kernel-{pid}.json".format(pid=os.getpid()) path = os.path.join(jupyter_runtime_dir(), name) # indentation, because why not. connection_json = json.dumps(self.connection_props, indent=2) with open(path, "w") as connection_file: connection_file.write(connection_json) return path
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def gff3_verifier(entries, line=None): """Raises error if invalid GFF3 format detected Args: entries (list): A list of GFF3Entry instances line (int): Line number of first entry Raises: FormatError: Error when GFF3 format incorrect with descriptive message """
regex = r'^[a-zA-Z0-9.:^*$@!+_?-|]+\t.+\t.+\t\d+\t\d+\t' \ + r'\d*\.?\d*\t[+-.]\t[.0-2]\t.+{0}$'.format(os.linesep) delimiter = r'\t' for entry in entries: try: entry_verifier([entry.write()], regex, delimiter) except FormatError as error: # Format info on what entry error came from if line: intro = 'Line {0}'.format(str(line)) elif error.part == 0: intro = 'Entry with source {0}'.format(entry.source) else: intro = 'Entry with Sequence ID {0}'.format(entry.seqid) # Generate error if error.part == 0: msg = '{0} has no Sequence ID'.format(intro) elif error.part == 1: msg = '{0} has no source'.format(intro) elif error.part == 2: msg = '{0} has non-numerical characters in type'.format(intro) elif error.part == 3: msg = '{0} has non-numerical characters in ' \ 'start position'.format(intro) elif error.part == 4: msg = '{0} has non-numerical characters in ' \ 'end position'.format(intro) elif error.part == 5: msg = '{0} has non-numerical characters in score'.format(intro) elif error.part == 6: msg = '{0} strand not in [+-.]'.format(intro) elif error.part == 7: msg = '{0} phase not in [.0-2]'.format(intro) elif error.part == 8: msg = '{0} has no attributes'.format(intro) else: msg = 'Unknown Error: Likely a Bug' raise FormatError(message=msg) if line: line += 1
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def parse(s, return_type=int): ''' Parse time string and return seconds. You can specify the type of return value both int or datetime.timedelta with 'return_type' argument. ''' RE_DAY = r'([0-9]+)d(ay)?' RE_HOUR = r'([0-9]+)h(our)?' RE_MINUTE = r'([0-9]+)m(in(ute)?)?' RE_SECOND = r'([0-9]+)(s(ec(ond)?)?)?' def _parse_time_with_unit(s): retval = 0 md = re.match(RE_DAY, s) mh = re.match(RE_HOUR, s) mm = re.match(RE_MINUTE, s) ms = re.match(RE_SECOND, s) if md: retval = 86400 * int(md.group(1)) elif mh: retval = 3600 * int(mh.group(1)) elif mm: retval = 60 * int(mm.group(1)) elif ms: retval = int(ms.group(1)) return retval if isinstance(s, (type(None), int, float)): return s if s[-1] in '0123456789': s += 's' m = re.match(r'^(%s)?(%s)?(%s)?(%s)?$' % (RE_DAY, RE_HOUR, RE_MINUTE, RE_SECOND), s) if not m: raise ParseError('invalid string: "%s"' % s) times = [x for x in m.groups() if isinstance(x, str) and re.match(r'[0-9]+[a-z]+', x)] seconds = sum(_parse_time_with_unit(z) for z in times) if return_type is int: return seconds elif return_type is timedelta: return timedelta(seconds=seconds) else: raise TypeError('return_type "{}" is not supported.'.format( return_type.__name__))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def path(string): """ Define the 'path' data type that can be used by apps. """
if not os.path.exists(string): msg = "Path %s not found!" % string raise ArgumentTypeError(msg) return string
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_argument(self, *args, **kwargs): """ Add a parameter to this app. """
if not (('action' in kwargs) and (kwargs['action'] == 'help')): # make sure required parameter options were defined try: name = kwargs['dest'] param_type = kwargs['type'] optional = kwargs['optional'] except KeyError as e: detail = "%s option required. " % e raise KeyError(detail) if optional and ('default' not in kwargs): detail = "A default value is required for optional parameters %s." % name raise KeyError(detail) # grab the default and help values default = None if 'default' in kwargs: default = kwargs['default'] param_help = "" if 'help' in kwargs: param_help = kwargs['help'] # set the ArgumentParser's action if param_type not in (str, int, float, bool, ChrisApp.path): detail = "unsupported type: '%s'" % param_type raise ValueError(detail) action = 'store' if param_type == bool: action = 'store_false' if default else 'store_true' del kwargs['default'] # 'default' and 'type' not allowed for boolean actions del kwargs['type'] kwargs['action'] = action # store the parameters internally (param_type.__name__ to enable json serialization) param = {'name': name, 'type': param_type.__name__, 'optional': optional, 'flag': args[0], 'action': action, 'help': param_help, 'default': default} self._parameters.append(param) # add the parameter to the parser del kwargs['optional'] ArgumentParser.add_argument(self, *args, **kwargs)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def save_json_representation(self, dir_path): """ Save the app's JSON representation object to a JSON file. """
file_name = self.__class__.__name__+ '.json' file_path = os.path.join(dir_path, file_name) with open(file_path, 'w') as outfile: json.dump(self.get_json_representation(), outfile)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def launch(self, args=None): """ This method triggers the parsing of arguments. """
self.options = self.parse_args(args) if self.options.saveinputmeta: # save original input options self.save_input_meta() if self.options.inputmeta: # read new options from JSON file self.options = self.get_options_from_file(self.options.inputmeta) self.run(self.options) # if required save meta data for the output after running the plugin app if self.options.saveoutputmeta: self.save_output_meta()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_options_from_file(self, file_path): """ Return the options parsed from a JSON file. """
# read options JSON file with open(file_path) as options_file: options_dict = json.load(options_file) options = [] for opt_name in options_dict: options.append(opt_name) options.append(options_dict[opt_name]) return self.parse_args(options)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def save_output_meta(self): """ Save descriptive output meta data to a JSON file. """
options = self.options file_path = os.path.join(options.outputdir, 'output.meta.json') with open(file_path, 'w') as outfile: json.dump(self.OUTPUT_META_DICT, outfile)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load_output_meta(self): """ Load descriptive output meta data from a JSON file in the input directory. """
options = self.options file_path = os.path.join(options.inputdir, 'output.meta.json') with open(file_path) as infile: return json.load(infile)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def print_app_meta_data(self): """ Print the app's meta data. """
l_metaData = dir(self) l_classVar = [x for x in l_metaData if x.isupper() ] for str_var in l_classVar: str_val = getattr(self, str_var) print("%20s: %s" % (str_var, str_val))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def start(context): """Start application server. """
config = context.obj["config"] daemon = select(config, "application.daemon", False) workspace = select(config, "application.workspace", None) pidfile = select(config, "application.pidfile", DEFAULT_PIDFILE) daemon_start(partial(main, config), pidfile, daemon, workspace)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def stop(context): """Stop application server. """
config = context.obj["config"] pidfile = select(config, "application.pidfile", DEFAULT_PIDFILE) daemon_stop(pidfile)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def register_view(self, view): """This method is called by the view, that calls it when it is ready to register itself. Here we connect the 'pressed' signal of the button with a controller's method. Signal 'destroy' for the main window is handled as well."""
# connects the signals: self.view['main_window'].connect('destroy', gtk.main_quit) # initializes the text of label: self.view.set_text("%d" % self.model.counter) return
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def get_version(svn=False, limit=3): "Returns the version as a human-format string." v = '.'.join([str(i) for i in VERSION[:limit]]) if svn and limit >= 3: from django.utils.version import get_svn_revision import os svn_rev = get_svn_revision(os.path.dirname(__file__)) if svn_rev: v = '%s.%s' % (v, svn_rev) return v
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def format(self, format_spec='f'): u""" Formata o CNPJ. Códigos de formatação: r -> raw f -> formatado '58414462000135' '58.414.462/0001-35' """
if format_spec == '' or format_spec == 'f': cnpj = CNPJ.clean(self._cnpj) return '{0}.{1}.{2}/{3}-{4}'.format(cnpj[0:2], cnpj[2:5], cnpj[5:8], cnpj[8:12], cnpj[12:14]) if format_spec == 'r': return self._cnpj raise ValueError( "Unknown format code '{0}' for object of type '{1}'".format(format_spec, CNPJ.__name__))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def format(self, format_spec='f'): u""" Formata o CPF. Códigos de formatação: r -> raw f -> formatado '58119443659' '581.194.436-59' """
if format_spec == '' or format_spec == 'f': cpf = CPF.clean(self._cpf) return '{0}.{1}.{2}-{3}'.format(cpf[0:3], cpf[3:6], cpf[6:9], cpf[9:11]) if format_spec == 'r': return self._cpf raise ValueError( "Unknown format code '{0}' for object of type '{1}'".format(format_spec, CPF.__name__))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def create_comment_edit(self, ): """Create a text edit for comments :returns: the created text edit :rtype: :class:`jukeboxcore.gui.widgets.textedit.JB_PlainTextEdit` :raises: None """
pte = JB_PlainTextEdit(parent=self) pte.set_placeholder("Enter a comment before saving...") pte.setMaximumHeight(120) return pte
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def release_callback(self, *args, **kwargs): """Create a new release :returns: None :rtype: None :raises: None """
tf = self.browser.get_current_selection() if not tf: self.statusbar.showMessage("Select a file to release, please!") return tfi = TaskFileInfo.create_from_taskfile(tf) checks = self.get_checks() cleanups = self.get_cleanups() comment = self.get_comment() r = Release(tfi, checks, cleanups, comment) self.statusbar.showMessage("Release in progress...") try: success = r.release() except OSError: self.statusbar.showMessage("Could not copy workfile!") return except Exception as e: self.statusbar.showMessage("%s" % e) return if success: self.statusbar.showMessage("Success!") else: self.statusbar.showMessage("Release failed!")
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _do_create(di): """Function that interprets a dictionary and creates objects"""
track = di['track'].strip() artists = di['artist'] if isinstance(artists, StringType): artists = [artists] # todo: handle case where different artists have a song with the same title tracks = Track.objects.filter(title=track, state='published') if tracks: track = tracks[0] track_created = False else: track = Track.objects.create(title=track, state='published') track_created = True last_played = di.get('last_played', None) if last_played and (track.last_played != last_played): track.last_played = last_played track.save() if track_created: track.length = di.get('length', 240) track.sites = Site.objects.all() track.save(set_image=False) for artist in artists: track.create_credit(artist.strip(), 'artist') # Set image last since we need credits set track.set_image()
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_jobs_from_argument(self, raw_job_string): """ return a list of jobs corresponding to the raw_job_string """
jobs = [] if raw_job_string.startswith(":"): job_keys = raw_job_string.strip(" :") jobs.extend([job for job in self.jobs(job_keys)]) # we assume a job code else: assert "/" in raw_job_string, "Job Code {0} is improperly formatted!".format(raw_job_string) host, job_name = raw_job_string.rsplit("/", 1) host_url = self._config_dict.get(host, {}).get('url', host) host = self.get_host(host_url) if host.has_job(job_name): jobs.append(JenksJob(None, host, job_name, lambda: self._get_job_api_instance(host_url, job_name))) else: raise JenksDataException( "Could not find Job {0}/{1}!".format(host, job_name)) return jobs
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def eqdate(y): """ Like eq but compares datetime with y,m,d tuple. Also accepts magic string 'TODAY'. """
y = datetime.date.today() if y == 'TODAY' else datetime.date(*y) return lambda x: x == y
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_grid(start, end, nsteps=100): """ Generates a equal distanced list of float values with nsteps+1 values, begining start and ending with end. :param start: the start value of the generated list. :type float :param end: the end value of the generated list. :type float :param nsteps: optional the number of steps (default=100), i.e. the generated list contains nstep+1 values. :type int """
step = (end-start) / float(nsteps) return [start + i * step for i in xrange(nsteps+1)]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def taskfileinfo_task_data(tfi, role): """Return the data for task :param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data :type tfi: :class:`jukeboxcore.filesys.TaskFileInfo` :param role: item data role :type role: QtCore.Qt.ItemDataRole :returns: data for the task :rtype: depending on role :raises: None """
task = tfi.task if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole: return task.name