def __init__(self): self.open_files_table = {} self.process_files_table = {} self.users = set() self.system_user = User() self.users.add(self.system_user) self.root_file_system = FileSystem()
def setUp(self): self.__testDir = "tempTestDir" self.fs = FileSystem(self.__testDir) self.removeDirectory(self.__testDir) assert(os.path.exists(self.__testDir)==False) try: os.mkdir(self.__testDir) except: pass
def testInit(self): from file_system import FileSystem from system import System, system fileSystem = FileSystem() print IceCommon.openOfficeName IceCommon.setup(system, fileSystem)
def setup_db_and_file_system(self, app): # SETUP THE DATABASE AND FILE SYSTEM ENVIRONMENTS self.database = Database() self.mysql_database = MySQLDatabase() self.file_system = FileSystem() app = self.database.setup_db(app) app = self.mysql_database.setup_mysql_db(app) app = self.file_system.setup_file_system(app) return app
def __init__(self, conf_file): self.pidfile = "/tmp/hermes.pid" self.conf_file = conf_file self.conf_data = self.__read_conf() # Initiate objects self.file_system = FileSystem(self.conf_data['archive_path']) self.mail = SendEmail(self.conf_data['mail'])
def test_find(self): with FileSystem(":memory:", self.matryoshka) as fs: with File.create(fs, Path("folder1", "file"), self.example_file): pass with File.create(fs, Path("folder2", "file"), self.example_file): pass files = File.find(fs, Path("folder*", "file")) self.assertEqual(len(files), 2)
def setUp(self): self.file_system = FileSystem() drive = self.file_system.get_root_node() self.test_folder = self.file_system.create(2, 'test_folder', drive.path) self.test_folder2 = self.file_system.create(2, 'test_folder2', drive.path) self.text_file1 = self.file_system.create(3, 'text_file1', self.test_folder.path) self.text_file2 = self.file_system.create(3, 'text_file2', self.test_folder.path) self.text_file3 = self.file_system.create(3, 'text_file3', self.test_folder2.path) self.zip_file1 = self.file_system.create(4, 'zip_file1', self.test_folder2.path) self.text_file4 = self.file_system.create(3, 'text_file4', self.zip_file1.path)
def test_right_format_and_filename(self): form_number = "form_number" directory = "/directory" year = 2000 irs_tax = IrsTax(form_number, "", year, "#") pattern = f"{directory}/{form_number} - {year}.pdf" file_system = FileSystem(directory) file_path = irs_tax.format_and_return_filename( file_system.base_directory) self.assertEqual(file_path, pattern)
def test_savetax(self): form_number = "form_number" base_directory = constants.BASE_DIR + "/tests_files" year = 2000 url = "https://www.irs.gov/pub/irs-prior/p1--2017.pdf" irs_tax = IrsTax(form_number, "", year, url) file_system = FileSystem(base_directory) file_system.save_tax(irs_tax) directory = "{}/{}".format(file_system.base_directory, irs_tax.form_number) self.assertTrue( os.path.isfile(irs_tax.format_and_return_filename(directory)))
def test_load(self): output_file = Path(self.temp_directory.name, "loaded_example_file") example_path = Path("folder1", "file") with FileSystem(":memory:", self.matryoshka) as fs: with File.create(fs, example_path, self.example_file): pass with File(fs, example_path) as file: file.pull(output_file) with output_file.open("rb") as output: self.assertEqual(output.read(), b"1234") output_file.unlink()
def testHasTransparency2(self): testFormula = "testData/1_a.gif" import Image from cStringIO import StringIO #use image directly im = Image.open(testFormula) #Make it transparent first before convert to L (grayscale) s = StringIO() newSize = (212, 45) im.save(s, "GIF") data = s.getvalue() iceImage = IceImage(data, ".gif") data = iceImage.bwResizeImage(newSize) fs = FileSystem() fs.writeFile("testData/iceImage1.gif", data)
def main(argv=None): if argv is None: argv = sys.argv try: try: opts, args = getopt.getopt(argv[1:], "h", ["help"]) inputFile = args[0] outputFile = args[1] fs = FileSystem('.') HtmlToOdt.HtmlParser = HtmlCleanup h2o = HtmlToOdt(fs) h2o.convert(inputFile, outputFile) except getopt.error, msg: raise Usage(msg) # more code, unchanged except Usage, err: print >>sys.stderr, err.msg print >>sys.stderr, "for help use --help" return 2
def testInit(self): fs = FileSystem("tempTest") path = "." sClient = MockSimpleClient(path=None, fs=fs, create=True) print "rev#", sClient.rootRevisionNumber fs.writeFile("one.txt", "testing one") sClient.addFile("one.txt") print sClient.list() sClient.commit(paths=["one.txt"], logMessage="Commit Test") print sClient.list() fs.writeFile("one.txt", "testing one modified") print sClient.list() print "---" sClient = MockSimpleClient(path=None, fs=fs) print sClient.list() sClient.commit(paths=["one.txt"], logMessage="2nd commit") print sClient.list() print sClient.logFile("one.txt") fs.writeFile("one.txt", "testing one modified2") print sClient.list() sClient.revertFile("one.txt") print sClient.list()
except Exception, e: pass import os import time import types from cStringIO import StringIO #from unittest import TestCase from oxml2xhtml import Oxml2xhtml currentPluginPath = os.getcwd() sys.path.append("../../../utils") from file_system import FileSystem fs = FileSystem() class Context(object): def __init__(self): self.fs = fs testFile = "test*.docx" # "test*.docx" for all test*.docx files testData = "testData/" testOutput = "testData/testOutput/" testExpectedResults = "testData/expected/" def getListOfTestFiles(): tFiles = [] testDataFullPath = fs.join(fs.absolutePath(currentPluginPath), testData); for rootDir, dirs, files in os.walk(testDataFullPath):
def testInitCreate(self): path = "." MockSimpleClient(path=None, fs=FileSystem("tempTest"), create=True)
def test_create(self): example_path = Path("folder1", "file") with FileSystem(":memory:", self.matryoshka) as fs: with File.create(fs, example_path, self.example_file) as file: self.assertEqual(file.size, 4) self.assertEqual(str(file), "/".join(example_path.parts))
from flask import Flask, jsonify from file_system import FileSystem import datetime app = Flask(__name__, static_url_path='') file_system = FileSystem() @app.route('/files/<path>/<name>/<file_type>/<writer_user>/<read_user>', methods=['POST']) def createFile(path, name, file_type, writer_user, read_user): read_user = '******'.join(set(writer_user.split('_') + read_user.split('_'))) return str(file_system.createFile(path, name, file_type, writer_user, read_user)) @app.route('/files/<path>/<user>', methods=['GET']) def getCurFiles(path, user): fcb_list = file_system.getFileChildren(path) result = {} for index, fcb in enumerate(fcb_list): if file_system.dictionary.fcb_list[fcb].checkReadRight(user): result[index] = { 'name': file_system.dictionary.fcb_list[fcb].name, 'type': file_system.dictionary.fcb_list[fcb].type } return jsonify(result) @app.route('/file_right/<path>/<user>/<file_type>', methods=['GET']) def getFileRight(path, user, file_type): fcb = file_system.getCurFile(path, file_type)
testResizeOdtFile = "testData/resize/test.odt" testLargeResizeOdtFile = "testData/largeResize/test.odt" testTransResizeOdtFile = "testData/transResize/test.odt" testAnimResizeOdtFile = "testData/animResize/test.odt" testExcessImagesOdtFile = "testData/excessImages/test.odt" import relative_linker getRelativeLinkMethod = relative_linker.relativeLinker( "http://localhost:8000/").getRelativeLink sys.path.append("../utils") from file_system import FileSystem from system import system fs = FileSystem(".") class odtConverterTests(TestCase): def setUp(self): pass def tearDown(self): pass # Constructor # __init__(getRelativeLinkMethod, oooConverterMethod, xslt="./ooo2xhtml.xsl") # Properties: # # Methods: # renderMethod(file, absFile, rep=None, oooConverterMethod=None) -> convertedData object
class MockSimpleClient(object): __fs = FileSystem() def __init__(self, path=None, fs=None, create=False): if fs is not None: self.__fs = fs else: self.__fs = self.__fs.clone() if path is None: path = self.__fs.absolutePath(".") self.__path = path self.__infosObjs = {} # file = file|path list def add(self, file, recurse=True): pass def commit(self, file, recurse=True): pass def delete(self, file, recurse=True): pass #def info(self, file, recurse=False): # pass def list(self, file, recurse=False): pass def status(self, file, recurse=False): pass #def mkdir(self, file): # pass def revert(self, file, recurse=True): pass def update(self, file, recurse=True): pass #def export(self, file, recurse=True): # # copy - but do not copy the .mockSvn directories # pass def log(self, file, limit=10): # can give log for only one item pass #def copy(self, src, dest): # pass #def move(self, src, dest): # self.copy(src, dest) # self.delete([src]) def flush(self): def __getNameAndPath(self, file): path, name = self.__fs.split(file) return path, name def __getInfosObject(self, path): absPath = self.__fs.absolutePath(path) infos = self.__infosObjs.get(absPath, None) if infos is None: infos = MockSvnInfos.load(path=absPath, fs=self.__fs) self.__infosObjs[absPath] = infos return infos if __name__=="__main__": args = list(sys.argv) args.pop(0) print "args = '%s'" % str(args)
""" Defines the view presented by the single HTML page that constitutes the application """ from app import app from flask import render_template, request, jsonify import config from file_system import FileSystem, mount, copy_files, get_copy_status, delete_files, create_dir, unmount, delete_folder from async_task import get_failed_job, get_background_status import json file_system = dict() file_system['source'] = FileSystem(config.source) file_system['destination'] = FileSystem(config.destination) conf = {'source': config.source, 'destination': config.destination} @app.route('/') @app.route('/index') def index(): """ brief: return the index page. """ return render_template("main.html") @app.route('/select_file', methods=['POST']) def select_file(): """ brief: Select a file in the side current folder. """
def setUp(self): self.__fs = FileSystem(".")
class MockSvnInfos(object): # FileSystem (fs) usage: # join() # readFile() # writeFile() # absolutePath() # isFile() # split() infosFilename = "__infos__" __fs = FileSystem() @staticmethod def load(path, fs): absPath = fs.absolutePath(path) filePath = fs.join(absPath, MOCK_SVN_DIRNAME, MockSvnInfos.infosFilename) data = fs.readFile(filePath) obj = loads(data) obj.__fs = fs obj.__rootObject = MockSvnRootObject.load(obj.__rootAbsPath, obj.__fs) obj.__absPath = absPath return obj def __init__(self, path, fs, rootObject=None): absPath = fs.absolutePath(path) if rootObject is None: rootObject = MockSvnRootObject(rootAbsPath=absPath) self.__rootAbsPath = rootObject.rootAbsPath self.__rootObject = rootObject # do not persist self.__relPathFromRoot = "" # for checking self.__infos = {} self.__fs = fs self.__absPath = absPath self.__changed = True def list(self): keys = self.__infos.keys() keys.sort() return [self.__infos[key] for key in keys] def _get(self, name): return self.__infos.get(name) def add(self, name): if self.__infos.has_key(name): info = self.__infos.get(name) if info.status != MockSvnStatus.DELETED: raise Exception("Item already under version control!") else: info.status = MockSvnStatus.REPLACED else: isFile = self.__fs.isFile(self.__fs.join(self.__absPath, name)) if not isFile: raise Exception("Currently can only add files!") info = MockSvnItemInfo(name, isFile) self.__copySource(name) info.status = MockSvnStatus.ADDED self.__infos[name] = info self.__changed = True def commit(self, name, user, logMessage, rev=None): ## NORMAL = "normal" ## ADDED = "added" ## MISSING = "missing" ## DELETED = "deleted" ## REPLACED = "replaced" ## MODIFIED = "modified" ## MERGED = "merged" # ## CONFLICTED = "conflicted" # ## IGNORED = "ignored" # info = self.__infos.get(name) if info is None: raise Exception("Item not under version control!") if rev is None: rev = self.__rootObject.createNextRevision(user, logMessage) self.status(name) # get the latest status # decide what to do based on status if info.status==MockSvnStatus.ADDED or \ info.status==MockSvnStatus.MODIFIED or \ info.status==MockSvnStatus.REPLACED: self.__copySource(name) info.setLastChangedRevision(rev) info.status = MockSvnStatus.NORMAL elif info.status == MockSvnStatus.NORMAL: pass # it does not need commiting elif info.status == MockSvnStatus.DELETED: del self.__infos[name] info.status = MockSvnStatus.NORMAL self.__fs.delete( self.__fs.join(self.__absPath, MOCK_SVN_DIRNAME, name)) elif info.status == MockSvnStatus.MISSING: raise Exception("File is missing.") self.__changed = True def update(self, name): info = self.__infos.get(name) if info is None: raise Exception("Item not under version control!") # Update current revision number info.setCurrentRevision(self.__rootObject.revisions.head) self.__changed = True def delete(self, name): info = self.__infos.get(name) if not self.__infos.has_key(name): raise Exception("Item is not under version control!") isFile = self.__fs.isFile(self.__fs.join(self.__absPath, name)) if isFile == False: raise Exception("Currently can only delete files!") if info.status != MockSvnStatus.NORMAL: raise Exception("'%s' has changed since last commit" % name) info.status = MockSvnStatus.DELETED self.__fs.delete(name) self.__infos[name] = info self.__changed = True def status(self, name): info = self.__infos.get(name) absPath = self.__fs.join(self.__absPath, name) status = "" if self.__isModified(name) and info.status != MockSvnStatus.REPLACED: if info.status == MockSvnStatus.DELETED: info.status = MockSvnStatus.REPLACED else: info.status = MockSvnStatus.MODIFIED if not self.__fs.exists( absPath) and info.status != MockSvnStatus.DELETED: info.status = MockSvnStatus.MISSING return info.status def revert(self): pass def save(self): if self.__changed: absPath = self.__absPath filePath = self.__fs.join(absPath, MOCK_SVN_DIRNAME, self.infosFilename) rootObject = self.__rootObject self.__rootObject = None fs = self.__fs self.__fs = None self.__changed = False data = dumps(self, -1) self.__rootObject = rootObject self.__fs = fs self.__fs.writeFile(filePath, data) self.__rootObject.save(self.__fs) def __copySource(self, name): srcFile = self.__fs.join(self.__absPath, name) destFile = self.__fs.join(self.__absPath, MOCK_SVN_DIRNAME, name) self.__fs.copy(srcFile, destFile) def __isModified(self, name): srcFile = self.__fs.join(self.__absPath, name) copiedFile = self.__fs.join(self.__absPath, MOCK_SVN_DIRNAME, name) srcData = self.__fs.readFile(srcFile) copiedData = self.__fs.readFile(copiedFile) return srcData != copiedData