示例#1
0
def install_dir(source_dir, target_dir):
    for root, dirs, files in walk(source_dir):
        for filename in files:
            s = np(join(source_dir, filename))
            t = np(join(target_dir, 'local-%s'%filename))

            if exists(t):                
                print "%8s %s" % ("[exists]", t)
                if not islink(t):
                    print "%s%s" % (" "*9, "Cannot override the file at this location.")
            else:
                # TODO: it would be much nicer we we could create
                # a proper relative link. It should be able to handle
                # two arbitrary paths though.
                ln(np(abspath(s)), t)
                print "%8s %s" % ("[mklink]", t)
    def parsePOSIXRename(self, syscall: str, content: str):
        """Process a POSIX rename() system call."""

        # FIXME DEBUG
        if syscall in (
                'renameat',
                'renameat2',
        ):
            print("CHECK SYNTAX: ", syscall, content)  # TODO
            sys.exit(1)

        # Process the event's content
        res = Event.posixRenameRe.match(content)

        try:
            g = res.groups()
        except (AttributeError) as e:
            print("Error: POSIX rename system call was not logged "
                  "properly: %s" % content,
                  file=sys.stderr)
            self.markInvalid()
            return
        else:
            # Check the syscall was well formed and we have everything we need
            if len(g) != 6:
                print("Error: POSIX rename system call was not logged "
                      "properly: %s" % content,
                      file=sys.stderr)
                self.markInvalid()
                return

            # Assign relevant variables
            func = (str, str, str, int, int, str)
            (old, ocwd, new, flags, error, ncwd) = map(lambda f, d: f(d), func,
                                                       g)

        # Don't log failed syscalls, but inform the reader
        if error < 0:
            self._rejectError(syscall, None, 0, error)
            return

        # Build paths to be used by simulator, and save the corresponding File
        oldpath = old if old.startswith('/') else np(ocwd + '/' + old)
        newpath = new if new.startswith('/') else np(ncwd + '/' + new)

        self.evflags |= EventFileFlags.copy
        self.setDataSyscallFilesDual(oldpath, newpath)
    def parsePOSIXFopen(self, syscall: str, content: str):
        """Process a POSIX fopen() or freopen() system call."""
        # Process the event's content
        res = Event.posixFopenRe.match(content)
        try:
            g = res.groups()
        except (AttributeError) as e:
            print("Error: POSIX fopen/freopen system call was not logged "
                  "properly: %s" % content,
                  file=sys.stderr)
            self.markInvalid()
            return
        else:
            # Check the syscall was well formed and we have everything we need
            if len(g) != 5:
                print("Error: POSIX fopen/freopen system call was not logged "
                      "properly: %s" % content,
                      file=sys.stderr)
                self.markInvalid()
                return

            # Assign relevant variables
            func = (str, int16, int, int, str)
            (filename, fd, flags, error, cwd) = map(lambda f, d: f(d), func, g)

        # Ignore abstract sockets
        if filename.startswith('@/'):
            # print("Info: opening of abstract socket '%s' will be ignored." %
            #       filename)
            self.markInvalid()
            return

        # Build path to be used by simulator, and save the corresponding File
        path = filename if filename.startswith('/') else np(cwd + '/' +
                                                            filename)

        # Don't log failed syscalls, but inform the reader
        if error < 0 or fd == -1:
            self._rejectError(syscall, path, flags, error)
            return

        # Set paths once we know the call succeeded
        self.setDataSyscallFile(path)
        self.setDataSyscallFD(fd, path, FD_OPEN)

        # Parse flags
        self._openFopenParseFlags(flags)
    def parsePOSIXUnlink(self, syscall: str, content: str):
        """Process a POSIX unlink() system call."""
        # Process the event's content
        res = Event.posixUnlinkRe.match(content)
        try:
            g = res.groups()
        except (AttributeError) as e:
            print("Error: POSIX unlink system call was not logged "
                  "properly: %s" % content,
                  file=sys.stderr)
            self.markInvalid()
            return
        else:
            # Check the syscall was well formed and we have everything we need
            if len(g) != 3:
                print("Error: POSIX unlink system call was not logged "
                      "properly: %s" % content,
                      file=sys.stderr)
                self.markInvalid()
                return

            # Assign relevant variables
            func = (str, int, str)
            (filename, error, cwd) = map(lambda f, d: f(d), func, g)

        # Build path to be used by simulator, and save the corresponding File
        path = filename if filename.startswith('/') else np(cwd + '/' +
                                                            filename)
        if syscall in ('rmdir', ):
            self.setDataSyscallFile(path, 'inode/directory')
        else:
            self.setDataSyscallFile(path)

        # Don't log failed syscalls, but inform the reader
        if error != 0:
            if syscall in ('rmdir', ) and error == 39:
                return  # silently, ENOTEMPTY happens all the time
            elif syscall in ('unlink', ) and error == 2:
                return  # silently, ENOENT happens often with cache cleanups
            else:
                self._rejectError(syscall, path, 0, error)
                return

        self.evflags |= EventFileFlags.write
        self.evflags |= EventFileFlags.destroy
    def parsePOSIXOpendir(self, syscall: str, content: str):
        """Process a POSIX opendir() system call."""
        # Process the event's content
        res = Event.posixOpendirRe.match(content)
        try:
            g = res.groups()
        except (AttributeError) as e:
            print("Error: POSIX opendir system call was not logged "
                  "properly: %s" % content,
                  file=sys.stderr)
            self.markInvalid()
            return
        else:
            # Check the syscall was well formed and we have everything we need
            if len(g) != 4:
                print("Error: POSIX opendir system call was not logged "
                      "properly: %s" % content,
                      file=sys.stderr)
                self.markInvalid()
                return

            # Assign relevant variables
            func = (str, int16, int, str)
            (filename, fd, error, cwd) = map(lambda f, d: f(d), func, g)

        # Build path to be used by simulator, and save the corresponding File
        path = filename if filename.startswith('/') else np(cwd + '/' +
                                                            filename)

        # Opendir requires the directory to exist, and is a read access
        flags = O_RDONLY

        # Don't log failed syscalls, but inform the reader
        if error < 0 or fd == -1:
            self._rejectError(syscall, path, flags, error)
            return

        # Set paths once we know the call succeeded
        self.setDataSyscallFile(path, 'inode/directory')
        self.setDataSyscallFD(fd, path, FD_OPEN)

        # Parse flags
        self._openFopenParseFlags(flags)
示例#6
0
文件: test.py 项目: tkern0/misc
from os import system as cmd
from os import chdir as cd
from os.path import join
from os.path import normcase as nc
from os.path import normpath as np
path = "C:\\"
cd(path)
while True:
    i = input('> ')
    if i.startswith('cd ') and not i == 'cd ':
        path = nc(np(join(path, i[3:])))
        cd(path)
    else:
        cmd(i)
示例#7
0
#!/usr/bin/env python

from os import walk, symlink as ln
from os.path import dirname, join, normpath as np, exists, islink, abspath


our_dir = np(dirname(__file__))
logcheck_dir = np(join(our_dir, '../'))


def install_dir(source_dir, target_dir):
    for root, dirs, files in walk(source_dir):
        for filename in files:
            s = np(join(source_dir, filename))
            t = np(join(target_dir, 'local-%s'%filename))

            if exists(t):                
                print "%8s %s" % ("[exists]", t)
                if not islink(t):
                    print "%s%s" % (" "*9, "Cannot override the file at this location.")
            else:
                # TODO: it would be much nicer we we could create
                # a proper relative link. It should be able to handle
                # two arbitrary paths though.
                ln(np(abspath(s)), t)
                print "%8s %s" % ("[mklink]", t)


# install system level rules
source_dir = join(our_dir, 'ignore.d')
for td in ('server', 'workstation', 'paranoid'):
    def parsePOSIXOpen(self, syscall: str, content: str):
        """Process a POSIX open() or similar system call."""
        # Process the event's content
        res = Event.posixOpenRe.match(content)
        try:
            g = res.groups()
        except (AttributeError) as e:
            if syscall not in ('openat', 'openat64', 'mkdirat'):
                print("Error: POSIX open* system call was not logged "
                      "properly: %s" % content,
                      file=sys.stderr)
                self.markInvalid()
                return
            else:
                print("TODO: find RE parser for: ", syscall, "***", content)
                print("TODO: init @fdref@ with fd value")
                sys.exit(1)  # TODO
        else:
            # Check the syscall was well formed and we have everything we need
            if len(g) != 5:
                print("Error: POSIX open* system call was not logged "
                      "properly: %s" % content,
                      file=sys.stderr)
                self.markInvalid()
                return

            # Assign relevant variables
            func = (str, int, int, int, str)
            (filename, fd, flags, error, cwd) = map(lambda f, d: f(d), func, g)

        # Build path to be used by simulator
        path = filename if filename.startswith('/') else np(cwd + '/' +
                                                            filename)

        # Inject reference to system call if relevant, but as openat is
        # sometimes open with a NULL fd parameter, it can happen that fdref is
        # not defined, and that's fine.
        if syscall in ('openat', 'openat64', 'mkdirat'):
            try:
                path = ("@fdref:%d@appref:%s@" %
                        (fdref, self.getActor().uid())) + path
            except NameError:
                pass

        # Don't log failed syscalls, but inform the reader
        if error < 0 or fd == -1:
            self._rejectError(syscall, path, flags, error)
            return

        # Now, save the File that will be processed by the simulator
        if syscall in ('mkdirat', 'mkdir') or flags & O_DIRECTORY:
            self.setDataSyscallFile(path, 'inode/directory')
        else:
            self.setDataSyscallFile(path)
        self.setDataSyscallFD(fd, path, FD_OPEN)

        # creat() is a specialised open(), and mkdir() also 'creates' a file
        if syscall in ('creat', 'mkdir'):
            flags = O_WRONLY | O_CREAT | O_TRUNC

        # Parse flags
        self._openFopenParseFlags(flags)
示例#9
0
def get_dataset_params(name, model_type='', train_type='', test_type=''):

    p = {
        'name': name,
        'model_type': model_type,
        'train_type': train_type,
        'test_type': test_type
    }

    if name == 'hinterstoisser':
        p['obj_count'] = 3
        p['scene_count'] = 3
        p['test_im_size'] = (640, 480)
        p['base_path'] = np('/local/datasets/tlod/hinterstoisser/')
        p['im_id_pad'] = 4
        p['model_texture_mpath'] = None

    elif name == 'rutgers':
        p['obj_count'] = 14
        p['scene_count'] = 14
        p['test_im_size'] = (640, 480)
        p['base_path'] = np('/local/datasets/tlod/rutgers/')
        p['im_id_pad'] = 4
        p['model_texture_mpath'] = p['base_path'] + 'models/obj_{:02d}.png'

    elif name == 'tejani':
        p['obj_count'] = 6
        p['scene_count'] = 6
        p['test_im_size'] = (640, 480)
        p['base_path'] = np('/local/datasets/tlod/imperial/tejani/')
        p['im_id_pad'] = 4
        p['model_texture_mpath'] = None

    elif name == 'tless':
        p['obj_count'] = 30
        p['scene_count'] = 20

        p['base_path'] = np('/local/datasets/tlod/t-less/t-less_v2/')
        p['im_id_pad'] = 4
        p['model_texture_mpath'] = None

        if p['model_type'] == '': p['model_type'] = 'cad'
        if p['train_type'] == '': p['train_type'] = 'primesense'
        if p['test_type'] == '': p['test_type'] = 'primesense'

        if p['test_type'] in ['primesense', 'kinect']:
            p['test_im_size'] = (720, 540)
        elif p['test_type'] == 'canon':
            p['test_im_size'] = (2560, 1920)

    elif name == 'tudlight':
        p['obj_count'] = 3
        p['scene_count'] = 3
        p['test_im_size'] = (640, 480)
        p['base_path'] = np('/local/datasets/tlod/dresden/tudlight/')
        p['im_id_pad'] = 5
        p['model_texture_mpath'] = None

        if p['train_type'] == '': p['train_type'] = 'real'

    models_dir = 'models' if p[
        'model_type'] == '' else 'models_' + p['model_type']
    train_dir = 'train' if p['train_type'] == '' else 'train_' + p['train_type']
    test_dir = 'test' if p['test_type'] == '' else 'test_' + p['test_type']

    # Image ID format
    im_id_f = '{:' + p['im_id_pad'].zfill(2) + 'd}'

    # Path masks
    p['model_mpath'] = np(p['base_path'] + models_dir + '/obj_{:02d}.ply')
    p['obj_info_mpath'] = np(p['base_path'] + train_dir + '/{:02d}/info.yml')
    p['obj_gt_mpath'] = np(p['base_path'] + train_dir + '/{:02d}/gt.yml')
    p['train_rgb_mpath'] = np(p['base_path'] + train_dir + '/{:02d}/rgb/' +
                              im_id_f + '.png')
    p['train_depth_mpath'] = np(p['base_path'] + train_dir + '/{:02d}/depth/' +
                                im_id_f + '.png')

    p['scene_info_mpath'] = np(p['base_path'] + test_dir + '/{:02d}/info.yml')
    p['scene_gt_mpath'] = np(p['base_path'] + test_dir + '/{:02d}/gt.yml')
    p['test_rgb_mpath'] = np(p['base_path'] + test_dir + '/{:02d}/rgb/' +
                             im_id_f + '.png')
    p['test_depth_mpath'] = np(p['base_path'] + test_dir + '/{:02d}/depth/' +
                               im_id_f + '.png')

    p['cam_params_path'] = np(p['base_path'] + 'camera.yml')
    p['cam'] = inout.load_cam_params(p['cam_params_path'])

    return p