def checkout(self, username): """ Copies the element to the given user's work area in a directory with the following name: {the parent body's name}_{this element's department}_{this element's name} Adds username to the list of checkout users. username -- the username (string) of the user performing this action Returns the absolute filepath to the copied file. If this element has no app file, the returned filepath will not exist. """ checkout_dir = self.get_checkout_dir(username) if not os.path.exists(checkout_dir): pipeline_io.mkdir(checkout_dir) datadict = Checkout.create_new_dict(username, self.get_parent(), self.get_department(), self.get_name()) pipeline_io.writefile( os.path.join(checkout_dir, Checkout.PIPELINE_FILENAME), datadict) checkout = Checkout(checkout_dir) app_file = self.get_app_filepath() checkout_file = pipeline_io.version_file( os.path.join(checkout_dir, self.get_app_filename())) if os.path.exists(app_file): shutil.copyfile(app_file, checkout_file) checkout.add_operation(checkout_file) self.update_checkout_users(username) return checkout_file
def add_operation(self, filepath): """ record the result of a checkout operation. filepath -- the file that was checked out as a result of the operation. """ self._datadict[self.FILES].append(filepath) self._datadict[self.TIMES].append(pipeline_io.timestamp()) pipeline_io.writefile(self._pipeline_file, self._datadict)
def _create_user(self, username): workspace = os.path.join(self._project_dir, os.path.join(self.get_users_dir(), username)) if not os.path.exists(workspace): if not pipeline_io.mkdir(workspace): print("failed to create workspace") user_pipeline_file = os.path.join(workspace, User.PIPELINE_FILENAME) if not os.path.exists(user_pipeline_file): datadict = User.create_new_dict(username) pipeline_io.writefile(user_pipeline_file, datadict)
def _update_pipeline_file(self): pipeline_io.writefile(self._pipeline_file, self._datadict)
def update_fullname(self, new_name): self._datadict[self.NAME] = new_name pipeline_io.writefile(self._pipeline_file, self._datadict)
def update_email(self, new_email): self._datadict[self.EMAIL] = new_email pipeline_io.writefile(self._pipeline_file, self._datadict)