当前位置: 首页>>代码示例>>Python>>正文


Python FlagFramework.sane_join方法代码示例

本文整理汇总了Python中pyflag.FlagFramework.sane_join方法的典型用法代码示例。如果您正苦于以下问题:Python FlagFramework.sane_join方法的具体用法?Python FlagFramework.sane_join怎么用?Python FlagFramework.sane_join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyflag.FlagFramework的用法示例。


在下文中一共展示了FlagFramework.sane_join方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: right

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import sane_join [as 别名]
            def right(path, result):
                case = self.defaults.get('case',None)
                dbh = DB.DBO(case)
                tablename = dbh.get_temp()
                dbh.execute("""create table %s (
                `filename` varchar(250) NOT NULL default '.',
                `timestamp` timestamp NOT NULL,
                `size` bigint(11) not null
                )""", tablename)

                ## populate the table:
                full_path=FlagFramework.sane_join(config.UPLOADDIR,path)

                dbh.mass_insert_start(tablename)
                ## List all the files in the directory:
                try:
                    for d in os.listdir(full_path):
                        filename = FlagFramework.sane_join(path,d)
                        full_filename = FlagFramework.sane_join(config.UPLOADDIR, filename)
                        try:
                            if not os.path.isdir(full_filename):
                                s = os.stat(full_filename)
                                dbh.mass_insert(filename = filename,
                                                _timestamp = "from_unixtime(%d)" % s.st_mtime,
                                                size = s.st_size)
                        except OSError:
                            pass
                    dbh.mass_insert_commit()
                except OSError,e:
                    pass
开发者ID:backupManager,项目名称:pyflag,代码行数:32,代码来源:UI.py

示例2: scan

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import sane_join [as 别名]
    def scan(self, fd, scanners, type, mime, cookie, scores=None, **args):
        if 'Filesystem' in type:
            print "Will load %s" % fd.urn.value
            fs = sk.skfs(fd)

            for root, dirs, files in fs.walk('/', unalloc=True, inodes=True):
                for d, dirname in dirs:
                    self.create_map(fd, fs, d, FlagFramework.sane_join(root[1], dirname))

                for f, filename in files:
                    self.create_map(fd, fs, f, FlagFramework.sane_join(root[1], filename))
开发者ID:backupManager,项目名称:pyflag,代码行数:13,代码来源:Partitions.py

示例3: __init__

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import sane_join [as 别名]
    def __init__(self, case, fd, inode):
        File.__init__(self, case, fd, inode)
        # strategy: must determine basepath from parent, get our path
        # from db and then return the file:

        ## Note this _must_ work because we can only ever be called on
        ## a mounted iosource - it is an error otherwise:
        basepath = fd.io.directory

        self.case = case
        dbh = DB.DBO(case)
        dbh.check_index("file", "inode")
        dbh.execute("select path,name from file where inode=%r limit 1", (inode))
        row = dbh.fetch()

        path = row["path"]
        mount_point = fd.io.mount_point
        ## Prune the path down to the mount point:
        if path[: len(mount_point)] != mount_point:
            raise RuntimeError(DB.expand("Something went wrong - %s should be mounted on %s", (path, mount_point)))

        path = path[len(mount_point) :]
        path = basepath + "/" + path + "/" + row["name"]
        if not path.startswith(posixpath.normpath(config.UPLOADDIR)):
            path = FlagFramework.sane_join(config.UPLOADDIR, path)

        if os.path.isdir(path):
            self.fd = StringIO.StringIO("")
        else:
            self.fd = open(path, "r")

        s = os.stat(path)
        self.size = s.st_size
开发者ID:backupManager,项目名称:pyflag,代码行数:35,代码来源:Mounted.py

示例4: create_map

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import sane_join [as 别名]
    def create_map(self, fd, fs, skfs_inode, path):
        block_size = fs.block_size

        if str(skfs_inode) == "0-0-0":
            return 1

        if skfs_inode.alloc:
            status = 'alloc'
        else:
            status = 'deleted'

        ## Add the map under the path
        skfd = fs.open(inode=skfs_inode)
        skfd.seek(0,2)
        size = skfd.tell()

        map = CacheManager.AFF4_MANAGER.create_cache_map(
            fd.case,
            "%s/__inodes__/%s" % (fd.urn.parser.query, skfs_inode),
            size = size, target = fd.urn,
            status=status)

        for block in skfd.blocks():
            map.write_from(fd.urn, block * block_size, block_size)

        ## update the size of the map
        map.size.set(size)

        CacheManager.AFF4_MANAGER.create_link(
            fd.case,
            map.urn, FlagFramework.sane_join(fd.urn.parser.query, path))

        map.close()
开发者ID:backupManager,项目名称:pyflag,代码行数:35,代码来源:Partitions.py

示例5: left

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import sane_join [as 别名]
 def left(path):
     if os.path.basename(path)=='.': return
     path=FlagFramework.sane_join(config.UPLOADDIR,path)
     try:
         for d in os.listdir(path):
             if os.path.isdir(os.path.join(path,d)):
                              yield (d,d,'branch')
     except OSError,e:
         yield ('.', e,'leaf')
开发者ID:backupManager,项目名称:pyflag,代码行数:11,代码来源:UI.py

示例6: left

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import sane_join [as 别名]
 def left(path):
     if os.path.basename(path) == ".":
         return
     path = FlagFramework.sane_join(config.UPLOADDIR, path)
     try:
         for d in os.listdir(path):
             if os.path.isdir(os.path.join(path, d)):
                 yield (d, d, "branch")
     except OSError, e:
         yield (".", e, "leaf")
开发者ID:pombredanne,项目名称:pyflag,代码行数:12,代码来源:UI.py

示例7: glob_filenames

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import sane_join [as 别名]
    def glob_filenames(self, filenames):
        """ Returns the array of files found by globbing filenames on
        numeric suffix
        """
        result = []
        for f in filenames:
            ## Ignore files which are urls
            if re.match("[^:]+://",f): return filenames

            if not f.startswith(os.path.normpath(config.UPLOADDIR)):
                f = FlagFramework.sane_join(config.UPLOADDIR,f)

            ## FIXME - this is of limited value because the user can
            ## just create multiple symlinks for each file
            if 0 and config.FOLLOW_SYMLINKS:
                ## Is it a symlink? This allows us to symlink to a
                ## single file from a fileset using a simple
                ## name. This makes it nice to manage the upload
                ## directory because you can just put a single symlink
                ## (e.g. freds_disk.E01) to the entire evidence set
                ## (could be huge and mounted somewhere different then
                ## the upload directory, e.g. an external driver). It
                ## does pose a security risk if untrusted users are
                ## able to create such a link (it essentially allows
                ## them to fetch files from anywhere on the system.)
                try:
                    link_f = os.readlink(f)
                    if not link_f.startswith("/"):
                        f = posixpath.join(posixpath.dirname(f), link_f)
                    else:
                        f = link_f
                except (OSError, AttributeError):
                    pass

            ## If the filename we were provided with, ends with a
            ## digit we assume that its part of an evidence set.
            m = filename_re.match(f)
            
            if m:
                globbed_filenames = []
                dirname , base = os.path.split(m.group(1))
                for new_f in os.listdir(dirname):
                    if new_f.startswith(base) and filename_re.match(new_f):
                        globbed_filenames.append(FlagFramework.sane_join(dirname, new_f))
    
                if not globbed_filenames:
                    raise IOError("Unable to find file %s" % f)

                ## This list must be sorted on the numeric extension
                ## (Even if its not 0 padded so an alphabetic sort
                ## works - I have seen some cases where the images
                ## were named image.1 image.10 image.100):
                def comp(x,y):
                    m1 = filename_re.match(x)
                    m2 = filename_re.match(y)
                    if not m1 or not m2: return 0
                    return int(m1.group(2)) - int(m2.group(2))

                globbed_filenames.sort(comp)
            else:
                globbed_filenames = [f]

            result.extend(globbed_filenames)

        return result
开发者ID:anarchivist,项目名称:pyflag,代码行数:67,代码来源:Images.py

示例8: load

# 需要导入模块: from pyflag import FlagFramework [as 别名]
# 或者: from pyflag.FlagFramework import sane_join [as 别名]
    def load(self, mount_point, iosource_name, scanners=None, directory=None):
        DBFS.load(self, mount_point, iosource_name)
        iosrc = self.iosource
        path = iosrc.directory
        if not path.startswith(posixpath.normpath(config.UPLOADDIR)):
            path = FlagFramework.sane_join(config.UPLOADDIR, path)

        path = path.encode("ascii", "ignore")
        pyflaglog.log(pyflaglog.DEBUG, "Loading files from directory %s" % path)
        dbh_file = DB.DBO(self.case)
        dbh_file.mass_insert_start("file")

        dbh_inode = DB.DBO(self.case)
        dbh_inode.mass_insert_start("inode")

        if scanners:
            scanner_string = ",".join(scanners)
            pdbh = DB.DBO()
            pdbh.mass_insert_start("jobs")
            cookie = int(time.time())

        ## This deals with a mounted filesystem - we dont get the full
        ## forensic joy, but we can handle more filesystems than
        ## sleuthkit can.  The downside is that the user has to mount
        ## the filesystem first, we also need to be running as root or
        ## we may not be able to stat all the files :-(
        def insert_into_table(mode, root, name):
            rel_root = FlagFramework.normpath(DB.expand("%s/%s/", (mount_point, root[len(path) :])))
            try:
                s = os.lstat(os.path.join(root, name))
            except OSError:
                pyflaglog.log(
                    pyflaglog.WARNING, DB.expand("Unable to stat %s - mount the directory with the uid option", root)
                )
                return

            inode = DB.expand("I%s|M%s", (iosource_name, s.st_ino))
            dbh_inode.insert(
                "inode",
                inode=inode,
                uid=s.st_uid,
                gid=s.st_gid,
                _mtime="from_unixtime(%s)" % s.st_mtime,
                _atime="from_unixtime(%s)" % s.st_atime,
                _ctime="from_unixtime(%s)" % s.st_ctime,
                status="alloc",
                mode=str(oct(s.st_mode)),
                size=s.st_size,
                _fast=True,
            )
            inode_id = dbh_inode.autoincrement()

            dbh_file.mass_insert(inode_id=inode_id, inode=inode, mode=mode, status="alloc", path=rel_root, name=name)

            ## If needed schedule inode for scanning:
            if scanners and mode == "r/r":
                pdbh.mass_insert(command="Scan", arg1=self.case, arg2=inode, arg3=scanner_string, cookie=cookie)

            ## Fixme - handle symlinks
            try:
                link = os.readlink(DB.expand("%s/%s", (root, name)).encode("utf8"))
            except OSError:
                link = ""

        #            dbh.execute("insert into inode_%s set inode='M%s',uid=%r,gid=%r, mtime=%r,atime=%r,ctime=%r,mode=%r,links=%r,link=%r,size=%r",(self.table,s.st_ino,s.st_uid,s.st_gid,s.st_mtime,s.st_atime,s.st_ctime,str(oct(s.st_mode))[1:],s.st_nlink,link,s.st_size))

        ## Just walk over all the files and stat them all building the tables.
        for root, dirs, files in os.walk(path):
            for name in dirs:
                insert_into_table("d/d", root, name)
            for name in files:
                insert_into_table("r/r", root, name)

        dbh_file.mass_insert_commit()
        dbh_inode.mass_insert_commit()
开发者ID:backupManager,项目名称:pyflag,代码行数:77,代码来源:Mounted.py


注:本文中的pyflag.FlagFramework.sane_join方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。