<commit_before>import subprocess
from subprocess import *
import re
import sqlite3
from contextlib import closing
#-------------------- Funções --------------------------------
# Return the processes that is executing in Windows SO.
def get_processes_running():
	tasks = subprocess.check_output(['tasklist'])#.split("\r\n")
	tasks = str(tasks).split('\\r\\n')
	for i in range (3):
		del tasks[0]
	p = []
	for task in tasks:
		m = re.match("(.+?) +(\d+) (.+?) +(\d+) +(\d+.* K).*",task)
		if m is not None:
			p.append({"image":m.group(1),
				   "pid":m.group(2),
				   "session_name":m.group(3),
				   "session_num":m.group(4),
				   "mem_usage":m.group(5)
				   })
	print("get_processes_running.. OK")
	return p
# Create table 'processos' to put exception list
def criarTabela():
	print("criarTabela...")
	with sqlite3.connect("processos.db") as conexão:
		with closing(conexão.cursor()) as cursor:
			cursor.execute('''CREATE TABLE processos(
				id integer primary key autoincrement,
				image text,
				pid integer,
				sessionName text,
				sessionNum text,
				memUsage text)''')
		conexão.commit()
	print("\tTabela processos.. OK")
# Save obj 'p' on table 'processos'
def gravar(p):
	with sqlite3.connect("processos.db") as conexão:
		with closing(conexão.cursor()) as cursor:
			for x in p:
				cursor.execute('''INSERT into processos(
					image, pid, sessionName, sessionNum, memUsage)
				values(?, ?, ?, ?, ?)
					''',(x['image'], int(x['pid']),
						x['session_name'], x['session_num'],
						x['mem_usage']))
		conexão.commit()
	print("gravar..OK")
# Add the process on table 'processos', that's table of exceptions
def addExcessao(r):
	#r == process that will be added on base 'processos' to exception
	cursor.execute('''INSERT into processos(
		image, pid, sessionName, sessionNum, memUsage)
		values(?, ?, ?, ?, ?)''',(r['image'], int(r['pid']),
			r['session_name'], r['session_num'],
			r['mem_usage']))
	conexao.commit()
	messagebox.showinfo("Informação",
		"%s Adicionado á lista de excessoes.."%(r['image']))
	#print("%s Adicionado á lista de excessoes"%(r['image']))
	# Imprime dados do banco de dados: tabela processos<commit_msg>printing/return data of processes from database (table 'processos')<commit_after>import subprocess
from subprocess import *
import re
import sqlite3
from contextlib import closing
#-------------------- Funções --------------------------------
# Return the processes that is executing in Windows SO.
def get_processes_running():
	tasks = subprocess.check_output(['tasklist'])#.split("\r\n")
	tasks = str(tasks).split('\\r\\n')
	for i in range (3):
		del tasks[0]
	p = []
	for task in tasks:
		m = re.match("(.+?) +(\d+) (.+?) +(\d+) +(\d+.* K).*",task)
		if m is not None:
			p.append({"image":m.group(1),
				   "pid":m.group(2),
				   "session_name":m.group(3),
				   "session_num":m.group(4),
				   "mem_usage":m.group(5)
				   })
	print("get_processes_running.. OK")
	return p
# Create table 'processos' to put exception list
def criarTabela():
	print("criarTabela...")
	with sqlite3.connect("processos.db") as conexão:
		with closing(conexão.cursor()) as cursor:
			cursor.execute('''CREATE TABLE processos(
				id integer primary key autoincrement,
				image text,
				pid integer,
				sessionName text,
				sessionNum text,
				memUsage text)''')
		conexão.commit()
	print("\tTabela processos.. OK")
# Save obj 'p' on table 'processos'
def gravar(p):
	with sqlite3.connect("processos.db") as conexão:
		with closing(conexão.cursor()) as cursor:
			for x in p:
				cursor.execute('''INSERT into processos(
					image, pid, sessionName, sessionNum, memUsage)
				values(?, ?, ?, ?, ?)
					''',(x['image'], int(x['pid']),
						x['session_name'], x['session_num'],
						x['mem_usage']))
		conexão.commit()
	print("gravar..OK")
# Add the process on table 'processos', that's table of exceptions
def addExcessao(r):
	#r == process that will be added on base 'processos' to exception
	cursor.execute('''INSERT into processos(
		image, pid, sessionName, sessionNum, memUsage)
		values(?, ?, ?, ?, ?)''',(r['image'], int(r['pid']),
			r['session_name'], r['session_num'],
			r['mem_usage']))
	conexao.commit()
	messagebox.showinfo("Informação",
		"%s Adicionado á lista de excessoes.."%(r['image']))
	#print("%s Adicionado á lista de excessoes"%(r['image']))
	# Imprime dados do banco de dados: tabela processos
# Print/returns data of processes from database (table 'processos')
def imprProcessos():
	count=0
	tabela = []
	with sqlite3.connect("processos.db") as conexão:
		with closing(conexão.cursor()) as cursor:
			#cursor.execute('''SELECT image,pid from processos''')
			print("%s %s"%("Nome do Processo".rjust(25),"PID".center(5)))
			print("="*78)
			query = ('SELECT image, pid from processos order by pid')
			for registro in cursor.execute(query):
				count +=1
				#image, pid = registro
				tabela.append(registro)
				#print("%s %05d"%(image.rjust(25),pid))
			#print("="*78)
			#print("%02d processos em banco."%(count))
			print("imprProcessos..OK")
			return tabela, count
			#input("...")
{'fraction_non_alphanumeric': 0.19282334384858044, 'fraction_numerical': 0.007097791798107256, 'mean_word_length': 3.7723424270931325, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2869786', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1733, 'n_words': 458}