def test_organizeWithFiles(self):
        fields = DocumentFields()
        fields.setField("title", "document about internet")
        d = DocumentFolder()
        d.setDocFields(fields)

        bibfile = File("bibfile.bib")
        bibfile.createFile()
        pdffilename = "pdffile.pdf"
        pdffile = File(pdffilename)
        pdffile.createFile()
        fileList = [bibfile, pdffilename]

        d.create()

        d.organize(fileList)
        self.assertFalse(File("bibfile.bib").exists())
        self.assertFalse(File("pdffile.pdf").exists())

        folderPath = d.getDir().getPath().getAbsolutePath()
        newbibfile = File(folderPath + "/" + "bibfile.bib")
        newpdffile = File(folderPath + "/" + "pdffile.pdf")

        self.assertTrue(newbibfile.exists())
        self.assertTrue(newpdffile.exists())

        d.delete()
Ejemplo n.º 2
0
 def createFile(self, path):
     self.path = path
     tree = etree.Element("documents")
     file = File(path)
     content = etree.tostring(tree, xml_declaration=True, pretty_print=True, encoding="utf-8")
     print(content.decode("utf-8"))
     file.createFile()
     file.writeContent(content.decode("utf-8"))
Ejemplo n.º 3
0
    def writeContent(self, path):

        file = File(path)

        content = {"title": self._title}
        jsonContent = json.dumps(content)

        print("Content : ", jsonContent)
        print("Write to : ", path.path)

        file.writeContent(jsonContent)
Ejemplo n.º 4
0
    def readContent(self, path):

        success = False

        file = File(path)
        jsonContent = file.readContent()

        if jsonContent is not None:

            content = json.loads(jsonContent)
            title = content.get("title")

            if title is not None:
                self._title = title
                success = True

        return success
Ejemplo n.º 5
0
    def organize(self, filesToMoveIn=None):
        self._checkDirectoryExists()

        notesPath = self._path.getAbsolutePath()
        latexNotes = LatexNotes(self._fields)
        latexNotes.createAllContent()
        latexNotes.writeContent(notesPath)
        
        title = self._fields.getField("title")
        infofile = Infofile()
        infofile.title = title
        infofile.writeContent(self.infofilePath())

        if(filesToMoveIn is not None):
            for file in filesToMoveIn:
                f = file
                if(type(file) != File):
                    f = File(file)
                f.moveFile(self._path.getAbsolutePath())
Ejemplo n.º 6
0
 def runCode(
     self,
     inputName,
     code,
 ):
     File.write("jail/std/" + inputName, code)
     scriptFileName = ""
     if inputName == "input.py":
         scriptFileName = "python"
     elif inputName == "input.go":
         scriptFileName = "go"
     os.system("sh ${PWD}/jail/%s" % scriptFileName)
     output = File.read("jail/std/output")
     error = File.read("jail/std/error")
     if output != "" and error == "":
         self.canExit = True
         self.writeMessage("---------- OUTPUT ----------\n")
         self.writeMessage(output)
         self.writeMessage("------------------------------\n")
         self.codeResult = output
     if error != "":
         self.writeMessage("---------- ERROR -----------\n")
         self.writeMessage(error)
         self.writeMessage("------------------------------\n")
Ejemplo n.º 7
0
 def test_containsExtension(self):
     d = Directory("dir")
     f1 = File("dir/text.txt")
     f2 = File("dir/image.png")
     
     d.createDir()
     
     f1.createFile()
     f2.createFile()
     
     self.assertTrue(d.containsFileExtension(".txt"), "Directory contains .txt")
     self.assertTrue(d.containsFileExtension(".png"), "Directory contains .png")
     self.assertFalse(d.containsFileExtension(".pdf"), "Directory does not contain .pdf")
     
     d.removeDir()
Ejemplo n.º 8
0
 def content(self):
     d = Directory("dir")
     d1 = Directory("dir/a/b")
     d2 = Directory("dir/c")
     d3 = Directory("dir/d/e")
     f1 = File("dir/g.txt")
     f2 = File("dir/e.txt")
     
     d1.createTree()
     d2.createTree()
     d3.createTree()
     f1.createFile()
     f2.createFile()
     
     l = d.getFilesList()
     assert (l == {"dir/e.txt", "dir/g.txt"})
     
     l = d.getDirsList()
     assert (l == {"dir/a", "dir/c", "dir/d"})
     
     l = d.getContentList()
     assert (l == {"dir/e.txt", "dir/g.txt", "dir/a", "dir/c", "dir/d"})
     
     d.removeDir()
Ejemplo n.º 9
0
 def create(self): 
     f = File("hello")
     f.createFile()
     assert(f.exists())
     assert(f.isRegularFile())
     assert(not f.isDirectory())
Ejemplo n.º 10
0
    def test_readWrite(self):
        f = File("test_read_write.txt")
        content = "Hello\nI am a file"
        f.writeContent(content)
        readContent = f.readContent()
        self.assertEqual(content, readContent)
        f.removeFile()

        f = File("test_read_write2.txt")
        
        content = "Hello\nI am a file"
        f.writeContent(content)

        content = "This is another content for the file"
        f.writeContent(content)
        
        readContent = f.readContent()
        self.assertEqual(content, readContent)
        f.removeFile()
Ejemplo n.º 11
0
 def writeContent(self, folderPath):
     f = File(folderPath + "/" + self.getFileName())
     f.writeContent(self.getDocumentContent())
Ejemplo n.º 12
0
 def test_remove(self):
     f = File("hello")
     f.removeFile()
     self.assertFalse(f.exists())
Ejemplo n.º 13
0
    def test_move(self):
        f = File("hello")
        f.createFile()
        f.moveFile("newdest")

        self.assertTrue(f.exists())
        self.assertEqual(f.getPath().path, "newdest")

        oldFile = File("hello")
        self.assertFalse(oldFile.exists())

        f.removeFile()
        self.assertFalse(f.exists())
Ejemplo n.º 14
0
 def test_create(self):
     f = File("hello")
     f.createFile()
     self.assertTrue(f.exists())
     self.assertTrue(f.isRegularFile())
     self.assertFalse(f.isDirectory())
Ejemplo n.º 15
0
 def test_notExist(self):
     f = File("hello")
     self.assertFalse(f.exists())
Ejemplo n.º 16
0
 def remove(self): 
     f = File("hello")
     f.removeFile()
     assert(not f.exists())
Ejemplo n.º 17
0
 def writeContent(self, folderPath):
     notesPath = MyPath(folderPath + "/" + self.getFileName())
     notesPath = notesPath.findNotUsedPath()
     f = File(notesPath)
     f.writeContent(self.getDocumentContent())
Ejemplo n.º 18
0
 def notExist(self): 
     f = File("hello")
     assert(not f.exists())