예제 #1
0
 def handle_vol(self, vol):
     p = self.opts
     n = len(p)
     if n == 0 or n > 2:
         print "Usage: read <ami_file|dir> [sys_file]"
         return 1
     # determine output name
     out_name = os.path.basename(p[0])
     if n == 2:
         if os.path.isdir(p[1]):
             out_name = os.path.join(p[1], out_name)
         else:
             out_name = p[1]
     # single file operation
     name = make_fsstr(p[0])
     node = vol.get_path_name(name)
     if node == None:
         print "Node not found:", p[0]
         return 2
     # its a file
     if node.is_file():
         data = node.get_file_data()
         # write data to file
         fh = open(out_name, "wb")
         fh.write(data)
         fh.close()
     # its a dir
     elif node.is_dir():
         img = Imager()
         img.unpack_dir(node, out_name)
     node.flush()
     return 0
예제 #2
0
 def handle_vol(self, vol):
   p = self.opts
   n = len(p)
   if n == 0 or n > 2:
     print("Usage: read <ami_file|dir> [sys_file]")
     return 1
   # determine output name
   out_name = os.path.basename(p[0])
   if n == 2:
     if os.path.isdir(p[1]):
       out_name = os.path.join(p[1],out_name)
     else:
       out_name = p[1]
   # single file operation
   name = make_fsstr(p[0])
   node = vol.get_path_name(name)
   if node == None:
     print("Node not found:", p[0])
     return 2
   # its a file
   if node.is_file():
     data = node.get_file_data()
     # write data to file
     fh = open(out_name,"wb")
     fh.write(data)
     fh.close()
   # its a dir
   elif node.is_dir():
     img = Imager()
     img.unpack_dir(node, out_name)
   node.flush()
   return 0
예제 #3
0
 def handle_vol(self, vol):
     n = len(self.opts)
     if n == 0:
         print "Usage: unpack <out_path>"
         return 1
     else:
         out_path = self.opts[0]
         img = Imager()
         img.unpack(vol, out_path)
         if self.args.verbose:
             print "Unpacked %d bytes" % (img.get_total_bytes())
         return 0
예제 #4
0
 def handle_vol(self, vol):
   n = len(self.opts)
   if n == 0:
     print("Usage: unpack <out_path>")
     return 1
   else:
     out_path = self.opts[0]
     img = Imager()
     img.unpack(vol, out_path)
     if self.args.verbose:
       print("Unpacked %d bytes" % (img.get_total_bytes()))
     return 0
예제 #5
0
    def extract(self, name, output):
        path = self.absolutePath(name)
        node = self.volume.get_path_name(make_fsstr(path))

        if node.is_file():
            data = node.get_file_data()
            fh = open(output, 'wb')
            fh.write(data)
            fh.close()
        elif node.is_dir():
            img = Imager(meta_mode=Imager.META_MODE_NONE)
            img.unpack_dir(node, output)
예제 #6
0
 def handle_vol(self, vol):
     n = len(self.opts)
     if n == 0:
         print("Usage: unpack <out_path> [fsuae]")
         return 1
     else:
         meta_mode = Imager.META_MODE_DB
         if 'fsuae' in self.opts:
             meta_mode = Imager.META_MODE_FSUAE
         out_path = self.opts[0]
         img = Imager(meta_mode=meta_mode)
         img.unpack(vol, out_path)
         if self.args.verbose:
             print("Unpacked %d bytes" % (img.get_total_bytes()))
         return 0
예제 #7
0
    def insert(self, input):
        name = os.path.basename(input)

        if os.path.isfile(input):
            fh = open(input, 'rb')
            data = fh.read()
            fh.close()

            self.volume.write_file(data, make_fsstr(self.path),
                                   make_fsstr(name))
        elif os.path.isdir(input):
            parent, name = self.volume.get_create_path_name(
                make_fsstr(self.path), make_fsstr(name))

            node = parent.create_dir(name)
            img = Imager(meta_mode=Imager.META_MODE_NONE)
            img.pack_dir(input, node)

        self.navigate(self.path)
예제 #8
0
class PackCmd(Command):
    def __init__(self, args, opts):
        Command.__init__(self, args, opts, edit=True)
        self.imager = Imager()
        n = len(self.opts)
        if n == 0:
            print "Usage: pack <in_path> [dos_type] [out_size]"
            self.exit_code = 1
        else:
            self.in_path = self.opts[0]
            blkdev_opts = None
            dos_type = None
            if n > 1:
                # is a dostype given?
                dos_str = opts[1]
                dos_type = DosType.parse_dos_type_str(dos_str)
                if dos_type is not None:
                    begin = 2
                else:
                    begin = 1
                # take remainder as blkdev opts
                blkdev_opts = KeyValue.parse_key_value_strings(opts[begin:])
            self.blkdev_opts = blkdev_opts
            self.dos_type = dos_type
            self.imager.pack_begin(self.in_path)

    def init_blkdev(self, image_file):
        return self.imager.pack_create_blkdev(self.in_path,
                                              image_file,
                                              force=self.args.force,
                                              options=self.blkdev_opts)

    def init_vol(self, blkdev):
        return self.imager.pack_create_volume(self.in_path,
                                              blkdev,
                                              dos_type=self.dos_type)

    def handle_vol(self, volume):
        self.imager.pack_root(self.in_path, volume)
        self.imager.pack_end(self.in_path, volume)
        if self.args.verbose:
            print "Packed %d bytes" % (self.imager.get_total_bytes())
        return 0
예제 #9
0
    def handle_vol(self, vol):
        n = len(self.opts)
        if n == 0 or n > 2:
            print "Usage: write <sys_file|dir> [ami_path]"
            return 1
        # get file_name and ami_path
        sys_file = self.opts[0]
        file_name = os.path.basename(sys_file)
        if n > 1:
            ami_path = self.opts[1]
        else:
            ami_path = os.path.basename(sys_file)
        # check sys path
        if not os.path.exists(sys_file):
            print "File not found:", sys_file
            return 2

        ami_path = make_fsstr(ami_path)
        file_name = make_fsstr(file_name)
        # handle file
        if os.path.isfile(sys_file):
            fh = open(sys_file, "rb")
            data = fh.read()
            fh.close()
            vol.write_file(data, ami_path, file_name)
        # handle dir
        elif os.path.isdir(sys_file):
            parent_node, dir_name = vol.get_create_path_name(
                ami_path, file_name)
            if parent_node == None:
                print "Invalid path", ami_path
                return 2
            node = parent_node.create_dir(dir_name)
            img = Imager()
            img.pack_dir(sys_file, node)

        return 0
예제 #10
0
 def __init__(self, args, opts):
     Command.__init__(self, args, opts, edit=True)
     self.imager = Imager()
     n = len(self.opts)
     if n == 0:
         print "Usage: pack <in_path> [dos_type] [out_size]"
         self.exit_code = 1
     else:
         self.in_path = self.opts[0]
         blkdev_opts = None
         dos_type = None
         if n > 1:
             # is a dostype given?
             dos_str = opts[1]
             dos_type = DosType.parse_dos_type_str(dos_str)
             if dos_type is not None:
                 begin = 2
             else:
                 begin = 1
             # take remainder as blkdev opts
             blkdev_opts = KeyValue.parse_key_value_strings(opts[begin:])
         self.blkdev_opts = blkdev_opts
         self.dos_type = dos_type
         self.imager.pack_begin(self.in_path)
예제 #11
0
  def handle_vol(self, vol):
    n = len(self.opts)
    if n == 0 or n > 2:
      print("Usage: write <sys_file|dir> [ami_path]")
      return 1
    # get file_name and ami_path
    sys_file = self.opts[0]
    file_name = os.path.basename(sys_file)
    if n > 1:
        ami_path = self.opts[1]
    else:
        ami_path = os.path.basename(sys_file)
    # check sys path
    if not os.path.exists(sys_file):
      print("File not found:", sys_file)
      return 2

    ami_path = make_fsstr(ami_path)
    file_name = make_fsstr(file_name)
    # handle file
    if os.path.isfile(sys_file):
      fh = open(sys_file,"rb")
      data = fh.read()
      fh.close()
      vol.write_file(data, ami_path, file_name)
    # handle dir
    elif os.path.isdir(sys_file):
      parent_node, dir_name = vol.get_create_path_name(ami_path,file_name)
      if parent_node == None:
        print("Invalid path", ami_path)
        return 2
      node = parent_node.create_dir(dir_name)
      img = Imager()
      img.pack_dir(sys_file, node)

    return 0
예제 #12
0
class PackCmd(Command):
  def __init__(self, args, opts):
    Command.__init__(self, args, opts, edit=True)
    self.imager = Imager()
    n = len(self.opts)
    if n == 0:
      print("Usage: pack <in_path> [dos_type] [out_size]")
      self.exit_code = 1
    else:
      self.in_path = self.opts[0]
      blkdev_opts = None
      dos_type = None
      if n > 1:
        # is a dostype given?
        dos_str = opts[1]
        dos_type = DosType.parse_dos_type_str(dos_str)
        if dos_type is not None:
          begin = 2
        else:
          begin = 1
        # take remainder as blkdev opts
        blkdev_opts = KeyValue.parse_key_value_strings(opts[begin:])
      self.blkdev_opts = blkdev_opts
      self.dos_type = dos_type
      self.imager.pack_begin(self.in_path)

  def init_blkdev(self, image_file):
    return self.imager.pack_create_blkdev(self.in_path, image_file, force=self.args.force, options=self.blkdev_opts)

  def init_vol(self, blkdev):
    return self.imager.pack_create_volume(self.in_path, blkdev, dos_type=self.dos_type)

  def handle_vol(self, volume):
    self.imager.pack_root(self.in_path, volume)
    self.imager.pack_end(self.in_path, volume)
    if self.args.verbose:
      print("Packed %d bytes" % (self.imager.get_total_bytes()))
    return 0
예제 #13
0
 def __init__(self, args, opts):
   Command.__init__(self, args, opts, edit=True)
   self.imager = Imager()
   n = len(self.opts)
   if n == 0:
     print("Usage: pack <in_path> [dos_type] [out_size]")
     self.exit_code = 1
   else:
     self.in_path = self.opts[0]
     blkdev_opts = None
     dos_type = None
     if n > 1:
       # is a dostype given?
       dos_str = opts[1]
       dos_type = DosType.parse_dos_type_str(dos_str)
       if dos_type is not None:
         begin = 2
       else:
         begin = 1
       # take remainder as blkdev opts
       blkdev_opts = KeyValue.parse_key_value_strings(opts[begin:])
     self.blkdev_opts = blkdev_opts
     self.dos_type = dos_type
     self.imager.pack_begin(self.in_path)