예제 #1
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)
예제 #2
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
예제 #3
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