コード例 #1
0
ファイル: MetaDB.py プロジェクト: alpine9000/EWGM
 def load_entry(self, line):
     line = line.strip()
     # path
     pos = line.find(':')
     if pos == -1:
         raise IOError("Invalid xdfmeta file! (no colon in line)")
     path = line[:pos].decode("UTF-8")
     # prot
     line = line[pos + 1:]
     pos = line.find(',')
     if pos == -1:
         raise IOError("Invalid xdfmeta file! (no first comma)")
     prot_str = line[:pos]
     prot = ProtectFlags()
     prot.parse(prot_str)
     # time
     line = line[pos + 1:]
     pos = line.find(',')
     if pos == -1:
         raise IOError("Invalid xdfmeta file! (no second comma)")
     time_str = line[:pos]
     time = TimeStamp()
     time.parse(time_str)
     # comment
     comment = FSString(line[pos + 1:].decode("UTF-8"))
     # meta info
     mi = MetaInfo(protect_flags=prot, mod_ts=time, comment=comment)
     self.set_meta_info(path, mi)
コード例 #2
0
ファイル: ADFSNode.py プロジェクト: cnvogelg/amitools
 def create_meta_info(self):
     comment = self.block.comment
     if self.block.comment_block_id != 0:
         comment_block = CommentBlock(self.blkdev, self.block.comment_block_id)
         comment_block.read()
         comment = comment_block.comment
     self.meta_info = MetaInfo(self.block.protect, self.block.mod_ts, FSString(comment))
コード例 #3
0
ファイル: Imager.py プロジェクト: thorfdbg/amitools
    def pack_entry(self, in_path, parent_node):
        ami_name = self.from_path_str(os.path.basename(in_path))
        # retrieve meta info for path from DB
        if self.meta_db != None:
            ami_path = parent_node.get_node_path_name().get_unicode()
            if ami_path != u"":
                ami_path += u"/" + ami_name
            else:
                ami_path = ami_name
            meta_info = self.meta_db.get_meta_info(ami_path)
        else:
            meta_info = MetaInfo()  # thor mod
            protect = ProtectFlags()
            protect.fromPath(in_path)
            meta_info.set_protect_flags(protect)
            meta_info.set_mod_time(os.path.getmtime(in_path))

        # pack directory
        if os.path.isdir(in_path):
            node = parent_node.create_dir(FSString(ami_name), meta_info, False)
            for name in os.listdir(in_path):
                sub_path = os.path.join(in_path, name)
                self.pack_entry(sub_path, node)
            node.flush()
        # pack file
        elif os.path.isfile(in_path):
            # read file
            fh = open(in_path, "rb")
            data = fh.read()
            fh.close()
            node = parent_node.create_file(FSString(ami_name), data, meta_info,
                                           False)
            node.flush()
            self.total_bytes += len(data)
コード例 #4
0
 def change_mod_ts_by_string(self, tm_str):
     t = TimeStamp()
     t.parse(tm_str)
     self.change_meta_info(MetaInfo(mod_ts=t))
コード例 #5
0
 def change_mod_ts(self, mod_ts):
     self.change_meta_info(MetaInfo(mod_ts=mod_ts))
コード例 #6
0
 def change_protect(self, protect):
     self.change_meta_info(MetaInfo(protect=protect))
コード例 #7
0
 def change_comment(self, comment):
     self.change_meta_info(MetaInfo(comment=comment))
コード例 #8
0
class ADFSNode:
    def __init__(self, volume, parent):
        self.volume = volume
        self.blkdev = volume.blkdev
        self.parent = parent
        self.block_bytes = self.blkdev.block_bytes
        self.block = None
        self.name = None
        self.valid = False
        self.meta_info = None

    def set_block(self, block):
        self.block = block
        self.name = FileName(self.block.name)
        self.valid = True
        self.create_meta_info()

    def create_meta_info(self):
        self.meta_info = MetaInfo(self.block.protect, self.block.mod_ts,
                                  self.block.comment)

    def get_file_name_str(self):
        return self.name.name

    def delete(self, wipe=False, all=False):
        if all:
            self.delete_children(wipe, all)
        self.parent._delete(self, wipe=wipe)

    def delete_children(self, wipe, all):
        pass

    def get_meta_info(self):
        return self.meta_info

    def change_meta_info(self, meta_info):
        dirty = False

        protect = meta_info.get_protect()
        if protect != None and hasattr(self.block, 'protect'):
            self.block.protect = protect
            self.meta_info.set_protect(protect)
            dirty = True

        mod_ts = meta_info.get_mod_ts()
        if mod_ts != None:
            self.block.mod_ts = mod_ts
            self.meta_info.set_mod_ts(mod_ts)
            dirty = True

        comment = meta_info.get_comment()
        if comment != None and hasattr(self.block, "comment"):
            self.block.comment = comment
            self.meta_info.set_comment(comment)
            dirty = True

        if dirty:
            self.block.write()

    def change_comment(self, comment):
        self.change_meta_info(MetaInfo(comment=comment))

    def change_protect(self, protect):
        self.change_meta_info(MetaInfo(protect=protect))

    def change_protect_by_string(self, pr_str):
        p = ProtectFlags()
        p.parse(pr_str)
        self.change_protect(p.mask)

    def change_mod_ts(self, mod_ts):
        self.change_meta_info(MetaInfo(mod_ts=mod_ts))

    def change_mod_ts_by_string(self, tm_str):
        t = TimeStamp()
        t.parse(tm_str)
        self.change_meta_info(MetaInfo(mod_ts=t))

    def list(self, indent=0, all=False):
        istr = "  " * indent
        print "%-40s       %8s  %s" % (
            istr + self.block.name, self.get_size_str(), str(self.meta_info))

    def dump_blocks(self, with_data=False):
        blks = self.get_blocks(with_data)
        for b in blks:
            b.dump()
コード例 #9
0
 def create_meta_info(self):
     self.meta_info = MetaInfo(self.block.protect, self.block.mod_ts,
                               self.block.comment)
コード例 #10
0
ファイル: ADFSNode.py プロジェクト: alpine9000/amiga_examples
class ADFSNode:
  def __init__(self, volume, parent):
    self.volume = volume
    self.blkdev = volume.blkdev
    self.parent = parent
    self.block_bytes = self.blkdev.block_bytes
    self.block = None
    self.name = None
    self.valid = False
    self.meta_info = None
  
  def __str__(self):
    return "%s:'%s'(@%d)" % (self.__class__.__name__, self.get_node_path_name(), self.block.blk_num)
  
  def set_block(self, block):  
    self.block = block
    self.name = FileName(FSString(self.block.name), is_intl=self.volume.is_intl)
    self.valid = True
    self.create_meta_info()
    
  def create_meta_info(self):
    self.meta_info = MetaInfo(self.block.protect, self.block.mod_ts, FSString(self.block.comment))

  def get_file_name(self):
    return self.name

  def delete(self, wipe=False, all=False, update_ts=True):
    if all:
      self.delete_children(wipe, all, update_ts)
    self.parent._delete(self, wipe, update_ts)

  def delete_children(self, wipe, all, update_ts):
    pass

  def get_meta_info(self):
    return self.meta_info

  def change_meta_info(self, meta_info):
    dirty = False

    # dircache?
    rebuild_dircache = False
    if self.volume.is_dircache and self.parent != None:
      record = self.parent.get_dircache_record(self.name.get_ami_str_name())
      if record == None:
        raise FSError(INTERNAL_ERROR, node=self)
    else:
      record = None
        
    # alter protect flags
    protect = meta_info.get_protect()
    if protect != None and hasattr(self.block, 'protect'):
      self.block.protect = protect
      self.meta_info.set_protect(protect)
      dirty = True
      if record != None:
        record.protect = protect

    # alter mod time
    mod_ts = meta_info.get_mod_ts()
    if mod_ts != None:
      self.block.mod_ts = mod_ts
      self.meta_info.set_mod_ts(mod_ts)
      dirty = True
      if record != None:
        record.mod_ts = mod_ts
    
    # alter comment
    comment = meta_info.get_comment()
    if comment != None and hasattr(self.block, "comment"):
      self.block.comment = comment.get_ami_str()
      self.meta_info.set_comment(comment)
      dirty = True
      if record != None:
        rebuild_dircache = len(record.comment) < comment 
        record.comment = comment.get_ami_str()
    
    # really need update?
    if dirty:
      self.block.write()
      # dirache update
      if record != None:
        self.parent.update_dircache_record(record, rebuild_dircache)        
      
  def change_comment(self, comment):
    self.change_meta_info(MetaInfo(comment=comment))
    
  def change_protect(self, protect):
    self.change_meta_info(MetaInfo(protect=protect))
    
  def change_protect_by_string(self, pr_str):
    p = ProtectFlags()
    p.parse(pr_str)
    self.change_protect(p.mask)
    
  def change_mod_ts(self, mod_ts):
    self.change_meta_info(MetaInfo(mod_ts=mod_ts))
    
  def change_mod_ts_by_string(self, tm_str):
    t = TimeStamp()
    t.parse(tm_str)
    self.change_meta_info(MetaInfo(mod_ts=t))

  def get_list_str(self, indent=0, all=False, detail=False):
    istr = u'  ' * indent
    if detail:
      extra = self.get_detail_str()
    else:
      extra = self.meta_info.get_str_line()
    return u'%-40s       %8s  %s' % (istr + self.name.get_unicode_name(), self.get_size_str(), extra)
    
  def list(self, indent=0, all=False, detail=False, encoding="UTF-8"):
    print(self.get_list_str(indent=indent, all=all, detail=detail).encode(encoding))

  def get_size_str(self):
    # re-implemented in derived classes!
    return ""
    
  def get_blocks(self, with_data=False):
    # re-implemented in derived classes!
    return 0

  def get_file_data(self):
    return None

  def dump_blocks(self, with_data=False):
    blks = self.get_blocks(with_data)
    for b in blks:
      b.dump()

  def get_node_path(self, with_vol=False):
    if self.parent != None:
      if not with_vol and self.parent.parent == None:
        r = []
      else:
        r = self.parent.get_node_path()
    else:
      if not with_vol:
        return []
      r = []
    r.append(self.name.get_unicode_name())
    return r

  def get_node_path_name(self, with_vol=False):
    r = self.get_node_path()
    return FSString(u"/".join(r))

  def get_detail_str(self):
    return ""
    
  def get_block_usage(self, all=False, first=True):
    return (0,0)

  def get_file_bytes(self, all=False, first=True):
    return (0,0)

  def is_file(self):
    return False
  
  def is_dir(self):
    return False

  def get_info(self, all=False):
    # block usage: data + fs blocks
    (data,fs) = self.get_block_usage(all=all)
    total = data + fs
    bb = self.blkdev.block_bytes
    btotal = total * bb
    bdata = data * bb
    bfs = fs * bb
    prc_data = 10000 * data / total
    prc_fs = 10000 - prc_data
    res = []
    res.append("sum:    %10d  %s  %12d" % (total, ByteSize.to_byte_size_str(btotal), btotal))
    res.append("data:   %10d  %s  %12d  %5.2f%%" % (data, ByteSize.to_byte_size_str(bdata), bdata, prc_data / 100.0))
    res.append("fs:     %10d  %s  %12d  %5.2f%%" % (fs, ByteSize.to_byte_size_str(bfs), bfs, prc_fs / 100.0))
    return res
コード例 #11
0
ファイル: ADFSNode.py プロジェクト: alpine9000/amiga_examples
 def create_meta_info(self):
   self.meta_info = MetaInfo(self.block.protect, self.block.mod_ts, FSString(self.block.comment))
コード例 #12
0
class ADFSNode:
    def __init__(self, volume, parent):
        self.volume = volume
        self.blkdev = volume.blkdev
        self.parent = parent
        self.block_bytes = self.blkdev.block_bytes
        self.block = None
        self.name = None
        self.valid = False
        self.meta_info = None

    def __str__(self):
        return "%s:'%s'(@%d)" % (self.__class__.__name__,
                                 self.get_node_path_name(), self.block.blk_num)

    def set_block(self, block):
        self.block = block
        self.name = FileName(FSString(self.block.name),
                             is_intl=self.volume.is_intl)
        self.valid = True
        self.create_meta_info()

    def create_meta_info(self):
        self.meta_info = MetaInfo(self.block.protect, self.block.mod_ts,
                                  FSString(self.block.comment))

    def get_file_name(self):
        return self.name

    def delete(self, wipe=False, all=False, update_ts=True):
        if all:
            self.delete_children(wipe, all, update_ts)
        self.parent._delete(self, wipe, update_ts)

    def delete_children(self, wipe, all, update_ts):
        pass

    def get_meta_info(self):
        return self.meta_info

    def change_meta_info(self, meta_info):
        dirty = False

        # dircache?
        rebuild_dircache = False
        if self.volume.is_dircache and self.parent != None:
            record = self.parent.get_dircache_record(
                self.name.get_ami_str_name())
            if record == None:
                raise FSError(INTERNAL_ERROR, node=self)
        else:
            record = None

        # alter protect flags
        protect = meta_info.get_protect()
        if protect != None and hasattr(self.block, 'protect'):
            self.block.protect = protect
            self.meta_info.set_protect(protect)
            dirty = True
            if record != None:
                record.protect = protect

        # alter mod time
        mod_ts = meta_info.get_mod_ts()
        if mod_ts != None:
            self.block.mod_ts = mod_ts
            self.meta_info.set_mod_ts(mod_ts)
            dirty = True
            if record != None:
                record.mod_ts = mod_ts

        # alter comment
        comment = meta_info.get_comment()
        if comment != None and hasattr(self.block, "comment"):
            self.block.comment = comment.get_ami_str()
            self.meta_info.set_comment(comment)
            dirty = True
            if record != None:
                rebuild_dircache = len(record.comment) < comment
                record.comment = comment.get_ami_str()

        # really need update?
        if dirty:
            self.block.write()
            # dirache update
            if record != None:
                self.parent.update_dircache_record(record, rebuild_dircache)

    def change_comment(self, comment):
        self.change_meta_info(MetaInfo(comment=comment))

    def change_protect(self, protect):
        self.change_meta_info(MetaInfo(protect=protect))

    def change_protect_by_string(self, pr_str):
        p = ProtectFlags()
        p.parse(pr_str)
        self.change_protect(p.mask)

    def change_mod_ts(self, mod_ts):
        self.change_meta_info(MetaInfo(mod_ts=mod_ts))

    def change_mod_ts_by_string(self, tm_str):
        t = TimeStamp()
        t.parse(tm_str)
        self.change_meta_info(MetaInfo(mod_ts=t))

    def get_list_str(self, indent=0, all=False, detail=False):
        istr = u'  ' * indent
        if detail:
            extra = self.get_detail_str()
        else:
            extra = self.meta_info.get_str_line()
        return u'%-40s       %8s  %s' % (istr + self.name.get_unicode_name(),
                                         self.get_size_str(), extra)

    def list(self, indent=0, all=False, detail=False, encoding="UTF-8"):
        print(
            self.get_list_str(indent=indent, all=all,
                              detail=detail).encode(encoding))

    def get_size_str(self):
        # re-implemented in derived classes!
        return ""

    def get_blocks(self, with_data=False):
        # re-implemented in derived classes!
        return 0

    def get_file_data(self):
        return None

    def dump_blocks(self, with_data=False):
        blks = self.get_blocks(with_data)
        for b in blks:
            b.dump()

    def get_node_path(self, with_vol=False):
        if self.parent != None:
            if not with_vol and self.parent.parent == None:
                r = []
            else:
                r = self.parent.get_node_path()
        else:
            if not with_vol:
                return []
            r = []
        r.append(self.name.get_unicode_name())
        return r

    def get_node_path_name(self, with_vol=False):
        r = self.get_node_path()
        return FSString(u"/".join(r))

    def get_detail_str(self):
        return ""

    def get_block_usage(self, all=False, first=True):
        return (0, 0)

    def get_file_bytes(self, all=False, first=True):
        return (0, 0)

    def is_file(self):
        return False

    def is_dir(self):
        return False

    def get_info(self, all=False):
        # block usage: data + fs blocks
        (data, fs) = self.get_block_usage(all=all)
        total = data + fs
        bb = self.blkdev.block_bytes
        btotal = total * bb
        bdata = data * bb
        bfs = fs * bb
        prc_data = 10000 * data / total
        prc_fs = 10000 - prc_data
        res = []
        res.append("sum:    %10d  %s  %12d" %
                   (total, ByteSize.to_byte_size_str(btotal), btotal))
        res.append(
            "data:   %10d  %s  %12d  %5.2f%%" %
            (data, ByteSize.to_byte_size_str(bdata), bdata, prc_data / 100.0))
        res.append("fs:     %10d  %s  %12d  %5.2f%%" %
                   (fs, ByteSize.to_byte_size_str(bfs), bfs, prc_fs / 100.0))
        return res
コード例 #13
0
 def create_meta_info(self):
   self.meta_info = MetaInfo(mod_ts=self.block.mod_ts)
コード例 #14
0
ファイル: ADFSNode.py プロジェクト: moggen/amitools
class ADFSNode:
  def __init__(self, volume, parent):
    self.volume = volume
    self.blkdev = volume.blkdev
    self.parent = parent
    self.block_bytes = self.blkdev.block_bytes
    self.block = None
    self.name = None
    self.valid = False
    self.meta_info = None
  
  def set_block(self, block):  
    self.block = block
    self.name = FileName(self.block.name)
    self.valid = True
    self.create_meta_info()
    
  def create_meta_info(self):
    self.meta_info = MetaInfo(self.block.protect, self.block.mod_ts, self.block.comment)

  def get_file_name_str(self):
    return self.name.name

  def delete(self, wipe=False, all=False):
    if all:
      self.delete_children(wipe, all)
    self.parent._delete(self, wipe=wipe)

  def delete_children(self, wipe, all):
    pass

  def get_meta_info(self):
    return self.meta_info

  def change_meta_info(self, meta_info):
    dirty = False

    protect = meta_info.get_protect()
    if protect != None and hasattr(self.block, 'protect'):
      self.block.protect = protect
      self.meta_info.set_protect(protect)
      dirty = True

    mod_ts = meta_info.get_mod_ts()
    if mod_ts != None:
      self.block.mod_ts = mod_ts
      self.meta_info.set_mod_ts(mod_ts)
      dirty = True
    
    comment = meta_info.get_comment()
    if comment != None and hasattr(self.block, "comment"):
      self.block.comment = comment
      self.meta_info.set_comment(comment)
      dirty = True
    
    if dirty:
      self.block.write()
      
  def change_comment(self, comment):
    self.change_meta_info(MetaInfo(comment=comment))
    
  def change_protect(self, protect):
    self.change_meta_info(MetaInfo(protect=protect))
    
  def change_protect_by_string(self, pr_str):
    p = ProtectFlags()
    p.parse(pr_str)
    self.change_protect(p.mask)
    
  def change_mod_ts(self, mod_ts):
    self.change_meta_info(MetaInfo(mod_ts=mod_ts))
    
  def change_mod_ts_by_string(self, tm_str):
    t = TimeStamp()
    t.parse(tm_str)
    self.change_meta_info(MetaInfo(mod_ts=t))

  def list(self, indent=0, all=False):
    istr = "  " * indent
    print "%-40s       %8s  %s" % (istr + self.block.name, self.get_size_str(), str(self.meta_info))

  def dump_blocks(self, with_data=False):
    blks = self.get_blocks(with_data)
    for b in blks:
      b.dump()