示例#1
0
def upload():
    fr = FileReader(fileQ, errorReportQ, 1024 * 1024 * 10)
    fr.run()
    s3 = S3FileUpload(
            'us-east-1',
            'RNLJDN0K03B7HHZPZTK3',
            'joayaC6Gw5JfzHDoYTFWcQH0xJT94Bpb5Eroood2',
            'http://192.168.68.113:9000',
            'test'
        )

    while True:
        chunk = fr.chunkQ.get()
        if not chunk:
            break
        [data, filePath, fileSize] = chunk
        # print(filePath)
        key = filePath
        if os.name == 'nt':
            key = '/' + filePath.replace('\\', '/').replace(':', '')
        s3.startFileSend(key, fileSize)
        s3.sendFileData(data)
        while True:
            if not data:
                s3.endFileSend()
                break

            [data, filePath, fileSize] = fr.chunkQ.get()
            s3.sendFileData(data)
示例#2
0
def createDocumentVector(fileObj, tfRawD):
    fileContent = FileReader(fileObj).content
    fileContent = ''.join(map(lambda x: ' ' if x != '.' and ord(x) < 48 or 57 < ord(x) < 65 else x, list(fileContent)))
    words = fileContent.strip().split()
    length = len(words)
    uniqueWordsInDoc = set()
    for word in words:
        word = modify_word(word)
        if word:
            uniqueWordsInDoc.add(word)
            if word not in tfRawD:
                tfRawD[word] = 1
            else:
                tfRawD[word] += 1
    return uniqueWordsInDoc, words, length, tfRawD
示例#3
0
def createTopicVector(fileObj, T, tfRaw):
    fileContent = FileReader(fileObj).content
    fileContent = ''.join(map(lambda x: ' ' if x != '.' and ord(x) < 48 or 57 < ord(x) < 65 else x, list(fileContent)))
    words = fileContent.strip().split()
    length = len(words)
    DVector = set()
    T.extend(words)
    for word in words:
        word = modify_word(word)
        if word:
            DVector.add(word)
            if word not in tfRaw:
                tfRaw[word] = 1
            else:
                tfRaw[word] += 1
    return DVector, length
示例#4
0
        def __init__(self, optionNumber):
            fileReader = FileReader()
            self.chooseFile(optionNumber)
            data1 = fileReader.readDataFile(self.file1)
            self.constraints = fileReader.readClueFile(self.file2)

            domains = []
            for i in range(4):
                copyData1 = copy.deepcopy(data1)
                dict = {
                    copyData1[0][0]: copyData1[0][1:],
                    copyData1[1][0]: copyData1[1][1:],
                    copyData1[2][0]: copyData1[2][1:],
                    copyData1[3][0]: copyData1[3][1:],
                }
                domains.append(dict)

            self.rootNode = Node(domains)
示例#5
0
def createDocumentVector(fileObj, tfRawD):
    fileContent = FileReader(fileObj).content
    fileContent = ''.join(
        map(
            lambda x: ' '
            if x != '.' and ord(x) < 48 or 57 < ord(x) < 65 else x,
            list(fileContent)))
    words = fileContent.strip().split()
    length = len(words)
    uniqueWordsInDoc = set()
    for word in words:
        word = modify_word(word)
        if word:
            uniqueWordsInDoc.add(word)
            if word not in tfRawD:
                tfRawD[word] = 1
            else:
                tfRawD[word] += 1
    return uniqueWordsInDoc, words, length, tfRawD
    def main(self):

        # solicitar nombre del archivo (debe estar en el misma carpeta)
        print('\nWrite the file name with extension (e.g. rules.txt):\n')
        filename = input()

        # obtener direccion absoluta del archivo:
        # https://stackoverflow.com/questions/12201928/python-open-gives-ioerror-errno-2-no-such-file-or-directory
        script_location = Path(__file__).absolute().parent
        file_location = script_location / filename
        # print(file_location)

        # si el archivo existe la ejecución continúa
        # https://stackoverflow.com/questions/82831/how-do-i-check-whether-a-file-exists-without-exceptions
        if (os.path.exists(file_location) == True):

            # leer expresión según el archivo de reglas
            reader = FileReader()
            expression, instruction = reader.readRules(file_location)

            # validar que se haya encontrado expresión e instrucción a realizar
            if (expression == None or instruction == None):
                print("\nThere was a problem with the file text")
            else:

                print("\nExpression to filter: " + expression)

                # hacer lo nuestro
                firewall = Firewall(expression)
                validation = firewall.validateExpression()
                if (validation == "No error"):  # la expresión es correcta
                    if (instruction == "allow"
                        ):  # se permite tráfico específico
                        firewall.allowTraffic()
                    elif (instruction == "block"
                          ):  # se bloquean tráfico especifico
                        firewall.blockTraffic()
                else:  # la expresión es errónea de acuerdo con reglas de librería WinDivert
                    print(
                        "The expression is wrong according to WinDivert rules")

        else:  # si el archivo no existe se termina la ejecución
            print("The file doesn't exist")
示例#7
0
def createTopicVector(fileObj, T, tfRaw):
    fileContent = FileReader(fileObj).content
    fileContent = ''.join(
        map(
            lambda x: ' '
            if x != '.' and ord(x) < 48 or 57 < ord(x) < 65 else x,
            list(fileContent)))
    words = fileContent.strip().split()
    length = len(words)
    DVector = set()
    T.extend(words)
    for word in words:
        word = modify_word(word)
        if word:
            DVector.add(word)
            if word not in tfRaw:
                tfRaw[word] = 1
            else:
                tfRaw[word] += 1
    return DVector, length
	def __init__(self):
		#importing the client name and raw table name passed as parameters
		clientName = sys.argv[1]
		fileName = sys.argv[2]
		
		#if needed to give filepath and validate a file not in the same folder
		#fileNamewithPath = sys.argv[2]
		#tempfileName = re.findall('[A-Za-z0-9_-\s]+.csv',fileNamewithPath)
		#fileName = tempfileName[0]
		
		fileInfo = FileInfo()
		fileInfo.setFileInfo(fileName)
		sortFileType = SortFileType()
		fileType,rawTableName = sortFileType.getFileType(clientName,fileName)
		#print fileType
		#print rawTableName
		
		fileReader = FileReader(fileName)
		tableMetadata = TableMetadata()
		validation = Validation()
		error = None
		
		fileColumns = fileReader.readHeader()
		dbColumns = tableMetadata.readTableHeader(clientName,rawTableName)
		
		if validation.validateHeaders(dbColumns,fileColumns):
			dataType = tableMetadata.readMetadata(clientName,rawTableName)
			fileRows = fileReader.readRows()
			
			for eachRow in fileRows :	
				self.rowNum = self.rowNum + 1
				if validation.validateRow(dataType,eachRow,self.rowNum) is False:
					error = "Error in dataType"
					break	
		else:
			error =  "Error in header"
		
		if error:
			print error
		else:	
			print"File sucessfully validated"
def main(filename, CID):
        #TODO: AcceptableGeneralSpecializedListVar = deque(ConfigsReaderVar.getAcceptableSpecialysedMismatchList())

        AnalyzerWrapperVar = AnalyzerWrapper(
            FileReader(filename, CID).getDataForAnalysis(),
            deque(ConfigsReaderVar.getAcceptableGeneralMismatchList()),
            list(ConfigsReaderVar.getFIDsNotToBeAnalyzed()),
            CID
        )

        # while 1:
            #TODO: exception for main
            # menu()
            # option = input()
        AnalyzerWrapperVar.execute_option(1)
示例#10
0
###
# Main file of the project. Presents the user a TUI and handles the input
###

from drivers import dc_motor as driver
from fileReader import FileReader
from drivers import pump
from os import walk

fr = FileReader(driver.maxMeasuringPointsXaxis, driver.maxMeasuringPointsYaxis)


def programSelector():
    print(
        "Please enter the name of the file that you would like to print or "
        "the command that you would like to use. \n"
        "Some examples: \n"
        " + \"pan calibrate\" to draw a rectangle showing the reach "
        "of the printer. Useful when you want to know if you've placed the pan "
        "correctly\n"
        " + \"flush tube\" to flush the tube. Useful when you're done printing "
        "and want to Clean the tube with hot water. Default: 10 minutes\n"
        " + \"list\" to show all possible prints\n"
        " + finally, to exit prematurely press \"ctrl + c\"")
    command = input("Please type the image name/command here: ")
    print("")
    if command == "pan calibrate":
        driver.drawingRange()
    elif command == "flush tube":
        pump.flushTube()
    elif command == "list":
示例#11
0
from sys import path
path.append("../src")
from fileReader import FileReader

simulations = FileReader("../input/Simulations.in").simulations
for key in simulations.keys():
    simulations[key].runSimulation()
    simulations[key].writeOutput(key)
示例#12
0
 def __init__(self):
     super().__init__()
     self.fileReader = FileReader()
     self.hasOutput = False
示例#13
0
class MainWindowUIClass(Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.fileReader = FileReader()
        self.hasOutput = False

    def setupUi(self, MW):
        super().setupUi(MW)

    def refreshAll(self):
        selectedFileName = self.fileReader.getFileName()
        links.append(selectedFileName)
        self.lstbox.index += 1
        onlyFileName = selectedFileName.split("/")[-1]
        linkNames.append(str(self.lstbox.index) + ". " + onlyFileName)
        self.lstbox.addItem(str(self.lstbox.index) + ". " + onlyFileName)

    # slot
    def exportSlot(self):
        if self.hasOutput:
            self.exportSelection = exportSelectWidget(self)
            self.exportSelection.show()
        else:
            global messageType
            messageType = 2
            self.systemMessage = PopUpMessageBox()

    # slot
    def importFileSlot(self):
        options = QtWidgets.QFileDialog.Options()
        fileName, _ = QtWidgets.QFileDialog.getOpenFileName(
            None, "File Broswer", "", "JSON Files (*.json)", options=options)
        if fileName:
            self.fileReader.setFileName(fileName)
            self.refreshAll()

    # slot
    def importDirectorySlot(self):
        getExistingDirectory = QFileDialog.getExistingDirectory
        fileName = getExistingDirectory(None, 'Folder Broswer', "")
        if fileName:
            self.fileReader.setFileName(fileName)
            self.refreshAll()

    # slot
    def readFileSlot(self):
        self.message.setText("")
        global messageType
        self.path = QListWidgetItem(self.lstbox.currentItem()).text()
        self.showProgress = PopUpProgressBar()
        if self.path != '':
            self.showProgress.show()
            index = linkNames.index(self.path)
            self.parseData = Parser(str(links[index]))
            pickleName = self.parseData.parse(self.showProgress)
            self.testing = Testing(pickleName)
            self.results = self.testing.analyse(self.showProgress)
            self.outputResult = list()
            for result in self.results:
                self.outputResult.append(result[:-1])
            self.dataFrame = pd.DataFrame(
                self.outputResult, columns=['File', 'Confidence', 'Motion'])
            print(self.dataFrame)
            self.text = ""
            for result in self.results:
                self.text = result[0] + " is " + result[1] + "% " + result[2]
                self.textbox.addItem(self.text)
            self.showProgress.close()
            if self.text == "":
                messageType = 1
                self.systemMessage = PopUpMessageBox()
            else:
                self.hasOutput = True
        else:
            messageType = 2
            self.systemMessage = PopUpMessageBox()

    # slot
    def animationSlot(self):
        try:
            self.message.setText("")
            self.selectedAnimation = QListWidgetItem(
                self.textbox.currentItem()).text().split(" is")[0]
            for result in self.results:
                if result[0] == self.selectedAnimation:
                    self.selectedAnimation = result[3]
                    break
            motion = pickle.load(open(self.selectedAnimation, "rb"))

            v = Viewport(disable_mouse=True, w=700, h=600)
            v.objects.clear()
            v.add_object(
                Mesh(name="cube",
                     primitive_type="skeleton",
                     pos=[-2.5, 0, -5],
                     color=(255, 0, 0),
                     segments=10))
            frame = 0
            frames = 0
            while True:
                v.objects[0].set_skeleton_state(motion[frame % len(motion)], 0,
                                                0, 0)
                v.update(draw_f=True, draw_e=True, draw_v=True)
                if frames % 7 == 0:
                    frame += 1
                frames += 1

        except (FileNotFoundError, IOError, AttributeError):
            global messageType
            messageType = 3
            self.systemMessage = PopUpMessageBox()
        except:
            pass
from fileReader import FileReader

reader = FileReader()

to_find = ["Trademarks and Trade Names."]  # words for searching
complete_path = "v5_signage_bad4.docx"  # complete path to file location, can be pdf or word
# header_only=True means it will return only headings

result = reader.find(path=complete_path, to_find=to_find, headers_only=True)

for line in result:
    print line
示例#15
0
def create_table(filename, clauses):
    reader = FileReader()
    complete_path = filename

    l = []
    name = splitext(filename)[0]
    document = Document()
    document.add_heading('Clause Extraction', 0)
    table = document.add_table(rows=1, cols=6)
    table.style = 'TableGrid'
    hdr_cells = table.rows[0].cells
    hdr_cells = table.rows[0].cells
    hdr_cells[0].text = 'Amended No.'
    hdr_cells[1].text = 'Clause No.'
    hdr_cells[2].text = 'ClauseName'
    hdr_cells[3].text = 'Lease required amendment'
    hdr_cells[4].text = 'Required action'
    hdr_cells[5].text = 'Lessor response to amendment Agreed/Not agreed'
    index = 0
    total_index = 1
    #4 Clauses to Extract
    for clause in clauses:
        t = {}

        t['index'] = total_index
        t['action'] = clause['action']
        t['clausename'] = clause['clause_name']
        t['reason'] = clause['reason']
        t['agree'] = ""
        to_find = [clause['clause_name']]
        row_cells = table.add_row().cells
        row_cells[0].text = str(t['index'])
        row_cells[1].text = ""
        row_cells[2].text = t['clausename']
        row_cells[3].text = t['reason']
        row_cells[5].text = t['agree']
        row_cells[4].text = t['action']
        total_index += 1
        if (clause['text']):
            cleaned_string = ''.join(c for c in clause['text']
                                     if valid_xml_char_ordinal(c))
            f = remove_clause_number(cleaned_string)

            index += 1
            t['keep'] = 0
            clause_no = ""
            # lst = {}
            try:
                temp_no = 0
                clause_no = re.match(
                    r"([0-9]+\.[0-9]+\.[0-9]+|[0-9]+\.[0-9]+|[0-9]+\.)",
                    cleaned_string)
                if (clause_no != None):
                    clause_no = clause_no.group()
                    temp_no = int(clause_no.replace('.', ''))
                else:
                    clause_no = ""
                lst = reader.find_with(clause['text'], [clause['key_text']],
                                       headers_only=False)
                if (len(lst) > 0 and len(lst[0]) > 0):
                    try:
                        if (string.ascii_letters.find(lst[0].replace(
                                "(", "").replace(')',
                                                 '').replace('.',
                                                             '')[:-1]) == 0):
                            clause_no = clause_no + ','.join(lst)
                        elif (int(lst[0].replace("(", "").replace(
                                ')', '').replace('.', '')) != temp_no):
                            clause_no = clause_no + ','.join(lst)
                        else:
                            clause_no = ','.join(lst)
                    except ValueError:
                        clause_no = clause_no + ','.join(lst)

            except Exception as e:
                print e
                print(complete_path)
                result = reader.find(path=complete_path,
                                     to_find=to_find,
                                     headers_only=True)
                print result
                try:
                    clause_no = result[0]
                except:
                    clause_no = ""
                print(clause_no)
            if (clause_no != None and clause_no != ""):
                t['clause_no'] = clause_no
                row_cells[1].text = t['clause_no']
                l.append(t)
        else:
            t['clause_no'] = ""
            t['keep'] = 1
            l.append(t)
    document.add_page_break()

    document.save(settings.BASE_DIR + '/leasingai/ai/temp/' + name + '.docx')
    return l