Esempio n. 1
0
    def iosubsystem(self, field, query):
        """ Check to see that the io subsystem is adequitely filled in

        instantiate an IO object, and try to pass the query to it.
        If the query is ok, we then pass the test, else we fail.
        """
        import pyflag.IO as IO

        try:
            IO.IOFactory(query, subsys=field)
        except (IOError, KeyError, RuntimeError):
            return False
Esempio n. 2
0

def clean_up_tmp_directory(tmp_dir):
    #Recursively remove the tmp directory
    for root, dirs, files in os.walk(tmp_dir, topdown=False):
        for name in files:
            os.remove(join(root, name))
        for name in dirs:
            os.rmdir(join(root, name))


# set up flag io subsystem
query_target = FlagFramework.query_type(())
query_target['subsys'] = 'standard'
query_target['io_filename'] = target
io_target = IO.IOFactory(query_target)
io_source = IO.IOFactory(query_target)

#iterate file copying
image_count = 0
total_image_count = 0
collection_size = 0
for image in Exgrep.process(None, io_target, ("jpg")):
    io_source.seek(image['offset'])
    tmp_image = open(tmp_image_filename, 'w')
    if extracted_length > 0:
        tmp_image.write(io_source.read(extracted_length * 1024))
    else:
        tmp_image.write(io_source.read(image['length']))

    tmp_image.close()
    arg = iter.next()

    try:
        while 1:
            if arg == '-i' or arg == '--subsystem':
                query['subsys'] = iter.next()
            elif arg.startswith('-'):
                try:
                    while 1:
                        opt = iter.next()
                        if opt.startswith('-'):
                            arg = opt
                            continue
                        query["io_%s" % arg[1:]] = opt
                except StopIteration:
                    break

            arg = iter.next()

    except StopIteration:
        pass

    ## We try to instantiate the IO object:
    io = IO.IOFactory(query)

    #Now we create a fuse object with that IO subsystem:
    server = Xmp(io=io)
    server.flags = 0
    server.multithreaded = 1
    server.main()