Exemplo n.º 1
0
def getcwd():
    """getcwd() -> path

    Return a string representing the current working directory.
    """
    foo = File(File("foo").getAbsolutePath())
    return foo.getParent()
Exemplo n.º 2
0
def unzip_atp_wallet(wallet_file, location):

    if not os.path.exists(location):
        os.mkdir(location)

    buffer = jarray.zeros(1024, "b")
    fis = FileInputStream(wallet_file)
    zis = ZipInputStream(fis)
    ze = zis.getNextEntry()
    while ze:
        fileName = ze.getName()
        newFile = File(location + File.separator + fileName)
        File(newFile.getParent()).mkdirs()
        fos = FileOutputStream(newFile)
        len = zis.read(buffer)
        while len > 0:
            fos.write(buffer, 0, len)
            len = zis.read(buffer)

        fos.close()
        zis.closeEntry()
        ze = zis.getNextEntry()
    zis.closeEntry()
    zis.close()
    fis.close()
Exemplo n.º 3
0
 def getFile(self, name):
     fname = apply(
         os.path.join,
         tuple([self.outdir] + string.split(name, '.'))) + '.class'
     file = File(fname)
     File(file.getParent()).mkdirs()
     return FileOutputStream(file)
Exemplo n.º 4
0
def getcwd():
    """getcwd() -> path

    Return a string representing the current working directory.
    """
    foo = File(File("foo").getAbsolutePath())
    return foo.getParent()
Exemplo n.º 5
0
def putNecessaryFilesToMember(mconnection, trustStorePath) :
    
    truststoreFile = File(trustStorePath)
    securityPath = truststoreFile.getParent()
    securityFile = File(securityPath)
    resourcesPath = securityFile.getParent()
    
    objectName = ObjectName(FILE_TRANSFER_MBEAN_OBJECT_NAME)
    mconnection.invoke(objectName, "uploadFile",
                      [trustStorePath, memberUsrDir + os.sep + "servers" + os.sep + member + os.sep + "resources" + os.sep + "security" + os.sep + "trust.jks", False],
                      [jstring, jstring, "boolean"])
           
    mconnection.invoke(objectName, "uploadFile",
                      [resourcesPath + os.sep + "collective" + os.sep + "collectiveTrust.jks", memberUsrDir + os.sep + "servers" + os.sep + member + os.sep + "resources" + os.sep + "collective" + os.sep + "collectiveTrust.jks", False],
                      [jstring, jstring, "boolean"])
                      
    mconnection.invoke(objectName, "uploadFile",
                      [resourcesPath + os.sep + "collective" + os.sep + "serverIdentity.jks", memberUsrDir + os.sep + "servers" + os.sep + member + os.sep + "resources" + os.sep + "collective" + os.sep + "serverIdentity.jks", False],
                      [jstring, jstring, "boolean"])
Exemplo n.º 6
0
 def split(path):
   if sys.platform.startswith('java'):
     from java.io import File
     f=File(path)
     d=f.getParent()
     if not d:
       if f.isAbsolute():
         d = path
       else:
         d = ""
     return (d, f.getName())
   else:
     import os
     return os.path.split(path)
from java.nio.file import Paths
from java.nio.file import Path
from java.io import File

p=Paths.get("home","pi","Desktop","jython-prac-prog","stram_jython","file2.txt")

x = p.toFile()

x = File(x.getName())
print (x.isFile())

f = File("image1.png") 
print (f.getName())
print ("length",f.length())
print ("Execute",f.canExecute())
print ("read",f.canRead())
print ("write",f.canWrite())
print ("path",f.getPath())
print ("Directory",f.isDirectory())
print ("parent",f.getParent())

Exemplo n.º 8
0
def getcwd():
    foo = File(File("foo").getAbsolutePath())
    return foo.getParent()
Exemplo n.º 9
0
def getcwd():
    foo = File(File("foo").getAbsolutePath())
    return foo.getParent()
Exemplo n.º 10
0
    def __processRequest(self):
        baseUrl = "http://%s:%s%s/%s" % (request.serverName, serverPort, contextPath, portalId)
        depositUrl = "%s/sword/deposit.post" % baseUrl
        sword = SwordSimpleServer(depositUrl)
        try:
            p =  request.path.split(portalId+"/"+pageName+"/")[1]  # portalPath
        except:
            p = ""
        if p=="post":
            print "\n--- post ---"
            c = sword.getClient()
            c.clearProxy()
            c.clearCredentials()
            postMsg = sword.getPostMessage();
            postMsg.filetype = "application/zip"
            postMsg.filepath = "/home/ward/Desktop/Test.zip"
            depositResponse = c.postFile(postMsg)
            return str(depositResponse)
        elif p=="servicedocument":
            #print "\n--- servicedocument ---"
            sdr = sword.getServiceDocumentRequest()
            sdr.username = formData.get("username", "test")
            sdr.password = formData.get("password", "test")
            if formData.get("test"):
                depositUrl += "?test=1"
            sd = sword.doServiceDocument(sdr)  # get a serviceDocument
            out = response.getPrintWriter("text/xml")
            out.println(str(sd))
            out.close()
            bindings["pageName"] = "-noTemplate-"
            return sd
        elif p=="deposit.post":
            #print "\n--- deposit ---  formData='%s'" % str(formData)
            inputStream = formData.getInputStream()
            headers = {}
            for x in formData.getHeaders().entrySet():
                headers[x.getKey()] = x.getValue()
            deposit = sword.getDeposit()
            noOp = headers.get("X-No-Op") or "false"
            deposit.noOp = (noOp.lower()=="true") or \
                (formData.get("test") is not None)
            contentDisposition = headers.get("Content-Disposition", "")
            filename = ""
            if contentDisposition!="":
                try:
                    filename = contentDisposition.split("filename=")[1]
                    deposit.filename = filename
                except: pass
            slug = headers.get("Slug")
            if slug is not None and slug!="":
                deposit.slug = slug
            #elif filename!="":
            #    deposit.slug = filename

            deposit.username = "******"
            deposit.password = deposit.username
            try:
                file = File.createTempFile("tmptf", ".zip")
                file.deleteOnExit()
                fos = FileOutputStream(file.getAbsolutePath())
                IOUtils.copy(inputStream, fos)
                fos.close()
                print "copied posted data to '%s'" % file.getAbsolutePath()
            except Exception, e:
                print "--- Exception - '%s'" % str(e)
            deposit.contentDisposition = file.getAbsolutePath()         #????
            deposit.file = inputStream
            depositResponse = sword.doDeposit(deposit)
            id = str(depositResponse.getEntry().id)
            try:
                print
                #imsPlugin = PluginManager.getTransformer("ims")
                jsonConfig = JsonConfig()
                #imsPlugin.init(jsonConfig.getSystemFile())
                #harvestClient = HarvestClient(jsonConfig.getSystemFile());
                storagePlugin = PluginManager.getStorage(jsonConfig.get("storage/type"))
                #storagePlugin.init(jsonConfig.getSystemFile())

                setConfigUri = self.__getPortal().getClass().getResource("/swordRule.json").toURI()
                configFile = File(setConfigUri)
                harvestConfig = JsonConfigHelper(configFile);
                tFile = File.createTempFile("harvest", ".json")
                tFile.deleteOnExit()
                harvestConfig.set("configDir", configFile.getParent())
                harvestConfig.set("sourceFile", file.getAbsolutePath())
                harvestConfig.store(FileWriter(tFile))

                zipObject = GenericDigitalObject(id)
                zipObject.addPayload(FilePayload(file, id))
                #digitalObject = imsPlugin.transform(zipObject, file)
                qStorage = QueueStorage(storagePlugin, tFile)
                qStorage.init(jsonConfig.getSystemFile())
                qStorage.addObject(zipObject)
                if deposit.noOp:
                    print "-- Testing noOp='true' --"
                else:
                    # deposit the content
                    pass
            except Exception, e:
                print "---"
                print " -- Exception - '%s'" % str(e)
                print "---"
Exemplo n.º 11
0
	def getFile(self, name):
		fname = apply(os.path.join, tuple([self.outdir]+string.split(name, '.')))+'.class'
		file = File(fname)
		File(file.getParent()).mkdirs()
		return FileOutputStream(file)	
Exemplo n.º 12
0
    def __processRequest(self):
        depositUrl = "%s/sword/deposit.post" % portalPath
        sword = SwordSimpleServer(depositUrl)
        try:
            p = self.vc("request").path.split(
                self.vc("portalId") + "/" + self.vc("pageName") +
                "/")[1]  # portalPath
        except:
            p = ""
        if p == "post":
            print "\n--- post ---"
            c = sword.getClient()
            c.clearProxy()
            c.clearCredentials()
            postMsg = sword.getPostMessage()
            postMsg.filetype = "application/zip"
            postMsg.filepath = "/home/ward/Desktop/Test.zip"
            depositResponse = c.postFile(postMsg)
            return str(depositResponse)
        elif p == "servicedocument":
            #print "\n--- servicedocument ---"
            sdr = sword.getServiceDocumentRequest()
            sdr.username = self.vc("formData").get("username", "test")
            sdr.password = self.vc("formData").get("password", "test")
            if self.vc("formData").get("test"):
                depositUrl += "?test=1"
            sd = sword.doServiceDocument(sdr)  # get a serviceDocument
            out = self.vc("response").getPrintWriter("text/xml; charset=UTF-8")
            out.println(str(sd))
            out.close()
            self.velocityContext["pageName"] = "-noTemplate-"
            return sd
        elif p == "deposit.post":
            #print "\n--- deposit ---  formData='%s'" % str(formData)
            inputStream = self.vc("formData").getInputStream()
            headers = {}
            for x in self.vc("formData").getHeaders().entrySet():
                headers[x.getKey()] = x.getValue()
            deposit = sword.getDeposit()
            noOp = headers.get("X-No-Op") or "false"
            deposit.noOp = (noOp.lower()=="true") or \
                (formData.get("test") is not None)
            contentDisposition = headers.get("Content-Disposition", "")
            filename = ""
            if contentDisposition != "":
                try:
                    filename = contentDisposition.split("filename=")[1]
                    deposit.filename = filename
                except:
                    pass
            slug = headers.get("Slug")
            if slug is not None and slug != "":
                deposit.slug = slug
            #elif filename!="":
            #    deposit.slug = filename

            deposit.username = "******"
            deposit.password = deposit.username
            try:
                file = File.createTempFile("tmptf", ".zip")
                file.deleteOnExit()
                fos = FileOutputStream(file.getAbsolutePath())
                IOUtils.copy(inputStream, fos)
                fos.close()
                print "copied posted data to '%s'" % file.getAbsolutePath()
            except Exception, e:
                print "--- Exception - '%s'" % str(e)
            deposit.contentDisposition = file.getAbsolutePath()  #????
            deposit.file = inputStream
            depositResponse = sword.doDeposit(deposit)
            id = str(depositResponse.getEntry().id)
            try:
                print
                #imsPlugin = PluginManager.getTransformer("ims")
                jsonConfig = JsonConfig()
                #imsPlugin.init(jsonConfig.getSystemFile())
                #harvestClient = HarvestClient(jsonConfig.getSystemFile());
                storagePlugin = PluginManager.getStorage(
                    jsonConfig.get("storage/type"))
                #storagePlugin.init(jsonConfig.getSystemFile())

                setConfigUri = self.__getPortal().getClass().getResource(
                    "/swordRule.json").toURI()
                configFile = File(setConfigUri)
                harvestConfig = JsonConfigHelper(configFile)
                tFile = File.createTempFile("harvest", ".json")
                tFile.deleteOnExit()
                harvestConfig.set("configDir", configFile.getParent())
                harvestConfig.set("sourceFile", file.getAbsolutePath())
                harvestConfig.store(FileWriter(tFile))

                zipObject = GenericDigitalObject(id)
                zipObject.addPayload(FilePayload(file, id))
                #digitalObject = imsPlugin.transform(zipObject, file)
                qStorage = QueueStorage(storagePlugin, tFile)
                qStorage.init(jsonConfig.getSystemFile())
                qStorage.addObject(zipObject)
                if deposit.noOp:
                    print "-- Testing noOp='true' --"
                else:
                    # deposit the content
                    pass
            except Exception, e:
                print "---"
                print " -- Exception - '%s'" % str(e)
                print "---"
Exemplo n.º 13
0
fileToImport = File(fileToImport)

# set the parameters
newAccountSet = False
contextAccount = moneydance_ui.firstMainFrame.getSelectedAccount()

filename = fileToImport.getName()
extension = os.path.splitext(filename)[1].upper()

if moneydance_data is None: raise Exception("ERROR - No data")
wrapper = moneydance_ui.getCurrentAccounts()  # type: AccountBookWrapper
book = moneydance_data

importWasSuccessful = True

dirName = fileToImport.getParent()
try:
    fPath = fileToImport.getAbsolutePath()  # type: str
    fPath = fPath.upper().strip()
    if not moneydance_ui.saveCurrentAccount():
        raise Exception("ERROR Save Failed")
    importer = moneydance_ui.getFileImporter(
        fileToImport)  # type: FileImporter
    if (importer is not None):

        if i_want_popups:
            import_option = JOptionPane.showInputDialog(
                None, "Select Import Type", "IMPORT",
                JOptionPane.INFORMATION_MESSAGE,
                moneydance_ui.getIcon(
                    "/com/moneydance/apps/md/view/gui/glyphs/appicon_64.png"),
Exemplo n.º 14
0
#
def CheckFileLists(lista, listb):
  return
originalParent = ""
imFileNames = MultiFileDialog("Open Image Files")
tempFiles = ArrayList()
ui = nrims.UI()
ui.show()
verbose = 1;
IJ.log("Starting combine nrrds.")
for i in range(len(imFileNames)):
	if i = 0:
		originalParent = imFile.getParent()
	IJ.log("Summing file:" + imFileNames[i])
	imFile = File(imFileNames[i])
	directory = imFile.getParent()
	name = imFile.getName()
	ui.openFile(imFile)
	mimStack = ui.getmimsStackEditing()
	imp = ArrayList()
	images = ui.getOpenMassImages()
	#compress the planes
       	blockSize = images[0].getNSlices()
       	done = mimStack.compressPlanes(blockSize)
       	#force to 32bit
       	massCorrection = nrimsData.massCorrection(ui)
	massCorrection.forceFloatImages(images)
       	
	if done:
		
		nw = nrimsData.Nrrd_Writer(ui)