def post_impl(self): parser = reqparse.RequestParser() parser.add_argument("subject", type=str) parser.add_argument("body", type=str, required=True) parser.add_argument("board", type=int, required=True) parser.add_argument("tags", type=str) args = parser.parse_args() if "media" not in request.files or not request.files["media"].filename: raise SubmissionError("A file is required to post a thread!", args["board"]) tags = [] if args["tags"]: tag_list = args["tags"].replace(" ", "").split(",") for tag_name in tag_list: tag = db.session.query(Tag).filter( Tag.name == tag_name).one_or_none() if tag is None: tag = Tag(name=tag_name) db.session.add(tag) tags.append(tag) db.session.flush() thread = Thread(board=args["board"], views=0, tags=tags) # FIXME: use one transaction for all of this, the current state defeats # the purpose of having transactions in the first place db.session.add(thread) db.session.commit() NewPost().post(thread_id=thread.id) return thread
def createProc(self, processText): listThread = list() listThreadText = list() processNode = Process() firstThread = True creatingThread = False threadAUX = "" stringAUX = "" vet_proc = processText.splitlines() for item in vet_proc: # Cabecalho do Processo if (item.find('prio=') != -1) and firstThread: firstThread = False processNode.headProc = stringAUX stringAUX = "" # Threads do Processo if (item.find('prio=') != -1) and (not firstThread): listThreadText.append(stringAUX) threadNode = Thread(stringAUX) listThread.append(threadNode) stringAUX = "" stringAUX = stringAUX + item + "\n" # Add last thread of file listThreadText.append(stringAUX) threadNode = Thread(stringAUX) listThread.append(threadNode) processNode.listThreads = listThread return processNode
def extractInformation(self): strAUX = "" for line in self.readLog.splitlines(): strAUX = strAUX + line + "\n" if (line.find('- end') != -1): newProcess = Process() newProcess.processText = strAUX firstThread = True strAUX2 = "" for line2 in newProcess.processText.splitlines(): if (line2.find('----- pid') != -1): newProcess.pid = line2[line2.find('pid') + 4:line2.find('at') - 1] if (line2.find('Cmd line:') != -1): newProcess.name = line2[line2.find('Cmd line:') + 10:] if (line2[0:1] == "\""): if firstThread: firstThread = False newProcess.headProc = strAUX2 strAUX2 = "" else: newThread = Thread(strAUX2) newProcess.listThreads.append(newThread) strAUX2 = "" strAUX2 = strAUX2 + line2 + "\n" newThread = Thread(strAUX2) newProcess.listThreads.append(newThread) strAUX2 = "" self.listProcess.append(newProcess) strAUX = ""
def create_post(thread: Thread, args: dict) -> Post: "Creates a new post from the given data." board_id = thread.board validate_captcha(board_id, args) ip = get_ip_address() poster, flooding = get_or_update_poster(thread.id, ip) update_poster_slip(poster, args) media_id = get_media_id(board_id) post = Post( body=args["body"], subject=args["subject"], thread=thread.id, poster=poster.id, media=media_id, spoiler=args["spoiler"], ) db.session.add(post) db.session.flush() replies = get_replies(post.id, post.body) for reply in replies: db.session.add(reply) if not flooding: # bump the thread if the last poster isn't the same thread.last_updated = post.datetime db.session.add(thread) db.session.flush() db.session.commit() publish_thread(thread, post, replies) invalidate_posts(thread, replies) # import here to prevent a circular import # TODO: fix circular import with NewPost from thread import invalidate_board_cache invalidate_board_cache(board_id) return post
def organizeProcessThreadData(self): for process in self.listProcess: getHeadProcess = True stringAUX = "" for line in process.processText: if (line.find('prio=') != -1) and getHeadProcess: getHeadProcess = False process.headProc = stringAUX stringAUX = "" if ((line.find('prio=') != -1) and not getHeadProcess): newThread = Thread(stringAUX) process.listThreads.append(newThread) stringAUX = "" stringAUX = stringAUX + line + "\n"
def create_thread(args: dict) -> Thread: "Creates a new thread out of the given arguments." if "media" not in request.files or not request.files["media"].filename: raise SubmissionError("A file is required to post a thread!", args["board"]) tags = get_tags(args) for tag in tags: db.session.add(tag) db.session.flush() slide_last_thread(args["board"]) thread = Thread(board=args["board"], views=0, tags=tags) db.session.add(thread) db.session.flush() NewPost().post(thread) publish_new_thread(thread) return thread
def segmentLogByProcess(self): newProcess = Process() processAUX = "" vet_log = self.readLog.splitlines() copyingProcess = False copyingThread = False copyingHead = False firstThread = True for line in vet_log.splitlines(): if (line.find('prio=') != -1): if firstThread: newProcess.headProc = processAUX firstThread = False processAUX = "" else: newThread = Thread(processAUX) newProcess.listThreads.append(newThread) stringAUX = "" processAUX = processAUX + line + "\n"
from model.CreativityGood import CreativityGood from model.Needle import Needle from model.Thread import Thread from model.Tissue import Tissue from model.Type import Type from manager.CreativityManager import CreativityManager creativityGoodNeedle = Needle("Needle", 12, Type.WEAVING, 3) creativityGoodThread = Thread("Thread", 7, Type.WEAVING, 10) creativityGoodTissue = Tissue("Tissue", 10, Type.FISHING, 15, 26) list_creativityGood = [ creativityGoodNeedle, creativityGoodThread, creativityGoodTissue ] manager = CreativityManager(list_creativityGood) manager.print_creativity_good(manager.sort_by_name(list_creativityGood)) manager.print_creativity_good(manager.sort_by_price(list_creativityGood)) manager.print_creativity_good(manager.find_by_type(Type.FISHING))