Пример #1
0
 def save_to_uri(self, bytes, uri, save_metadata=True):
     # Have to use a two-step process to write to the file: open the
     # filesystem, then open the file.  Have to open the filesystem
     # as writeable in case this is a virtual filesystem (like ZipFS),
     # otherwise the write to the actual file will fail with a read-
     # only filesystem error.
     if uri.startswith("file://"):
         # FIXME: workaround to allow opening of file:// URLs with the
         # ! character
         uri = uri.replace("file://", "")
     fs, relpath = opener.parse(uri, writeable=True)
     fh = fs.open(relpath, 'wb')
     log.debug("saving to %s" % uri)
     fh.write(bytes)
     fh.close()
     
     if save_metadata:
         metadata_dict = dict()
         self.get_extra_metadata(metadata_dict)
         if metadata_dict:
             relpath += ".omnivore"
             log.debug("saving extra metadata to %s" % relpath)
             jsonpickle.set_encoder_options("json", sort_keys=True, indent=4)
             bytes = jsonpickle.dumps(metadata_dict)
             text = jsonutil.collapse_json(bytes)
             header = self.get_extra_metadata_header()
             fh = fs.open(relpath, 'wb')
             fh.write(header)
             fh.write(text)
             fh.close()
             self.metadata_dirty = False
     
     fs.close()
Пример #2
0
    def destroy_fs(self, fs):
        """
        Destroy a FS object.

        :param fs: A FS instance previously opened by
            `~fs.test.FSTestCases.make_fs`.

        """
        fs.close()
Пример #3
0
def main():
    fs.init('fs')
    fs.mkdir('a')
    fs.mkdir('b')
    fs.mkdir('a/c')
    fs.create('a/d.txt', 20)
    fs.create('a/c/e.txt', 20)
    fd1 = fs.open('a/d.txt', 'rw')
    fd2 = fs.open('a/c/e.txt', 'rw')
    fs.write(fd1, 'hello\nbye\n')
    fs.write(fd2, 'goodbye\n')
    print fs.read(fd2, 4)
    print fs.readlines(fd1)
    for f in fs.readlines(fd1):
        print(f),
    fs.close(fd1)
    fs.close(fd2)
    fs.suspend()
Пример #4
0
    def save_to_uri(self, uri, editor, saver=None, save_metadata=True):
        # Have to use a two-step process to write to the file: open the
        # filesystem, then open the file.  Have to open the filesystem
        # as writeable in case this is a virtual filesystem (like ZipFS),
        # otherwise the write to the actual file will fail with a read-
        # only filesystem error.
        if saver is None:
            bytes = self.bytes.tostring()
        else:
            bytes = saver(self, editor)

        if uri.startswith("file://"):
            # FIXME: workaround to allow opening of file:// URLs with the
            # ! character
            uri = uri.replace("file://", "")
        fs, relpath = opener.parse(uri, writeable=True)
        fh = fs.open(relpath, 'wb')
        log.debug("saving to %s" % uri)
        fh.write(bytes)
        fh.close()

        if save_metadata:
            mdict = self.init_extra_metadata_dict(editor)
            task_metadata = dict()
            editor.to_metadata_dict(task_metadata, self)
            self.store_task_specific_metadata(editor, mdict, task_metadata)
            if mdict:
                relpath += ".omnivore"
                log.debug("saving extra metadata to %s" % relpath)
                jsonpickle.set_encoder_options("json",
                                               sort_keys=True,
                                               indent=4)
                bytes = jsonpickle.dumps(mdict)
                text = jsonutil.collapse_json(bytes, 8,
                                              self.json_expand_keywords)
                header = editor.get_extra_metadata_header()
                fh = fs.open(relpath, 'wb')
                fh.write(header)
                fh.write(text)
                fh.close()

        fs.close()
Пример #5
0
fs.create('c', 1)
try:
    fs.create('d', 8)
except Exception, e:
    print e
a = fs.open('a', 'wr')
b = fs.open('b', 'wr')
c = fs.open('c', 'wr')
fs.write(a, 'a')
fs.write(b, 'b')
fs.write(c, 'c')
print fs.read(a, 1)
print fs.read(b, 1)
try:
    fs.read(c, 2)
except Exception, e:
    print e
fs.close(a)
fs.close(b)
fs.close(c)
fs.close(fd)

# print 'suspending'
fs.suspend()
fs.resume('myfs.fssave')
print fs.listdir()
print fs.getcwd()
a = fs.open('a0/a', 'wr')
b = fs.open('a0/b', 'wr')
print fs.read(a, 1)
print fs.read(b, 1)
Пример #6
0
if vc.isOpened():  # try to get the first frame
    rval, frame = vc.read()
else:
    rval = False

while rval:
    cv2.imshow("preview", frame)
    cv2.imwrite('./imgCaptured.png', frame)
    rval, frame = vc.read()
    key = cv2.waitKey(20)
    if key == 27:  # exit on ESC
        break
cv2.destroyWindow("preview")

app = ClarifaiApp(api_key='444fb551757f45e0b124892399e5b760')

model = app.models.get('general-v1.3')
image = ClImage(file_obj=open('./imgCaptured.png', 'rb'))

content = json.dumps(model.predict([image]))
strings = json.loads(content)

imageText = "There is a " + strings["outputs"][0]["data"]["concepts"][0][
    "name"] + " ahead!"

print(imageText)

fs = open("textToSpeech.txt", "w")
fs.write(imageText)
fs.close()
Пример #7
0
fs.mkdir('b2')

fs.mkdir('/a/b3')

#now on drectory b3

fs.chdir('b3')

fs.mkdir('/a/b1/c1')
print fs.listdir('/a/b1')

fs.create('/a/b3/fc', 30)
fcd = fs.open('/a/b3/fc', 'w')
fs.write(fcd, '\nnow we needtousegitagain\n')
fs.close(fcd)
fcd1 = fs.open('/a/b3/fc', 'r')
print fs.readlines(fcd1)
print fs.read(fcd1, 5)
fs.seek(fcd1, 5)
print fs.read(fcd1, 10)
fs.close(fcd1)
fs.suspend()
#fs.open('/fa','r')
fs.chdir('..')
#resume is not sure
fs.resume('abc.fssave')
fs.create('fb', 29)
fbd = fs.open('fb', 'w')
fs.write(fbd, 'quizz is so annoying.\n')