Пример #1
0
def _format_entry(entry, src):
    if entry is not None:
        result = []
        for x in entry.split(','):
            x = x.strip()
            if os.path.exists(os.path.join(src, x)):
                result.append(relpath(os.path.join(src, x), src))
            elif os.path.exists(x):
                result.append(relpath(os.path.abspath(x), src))
            else:
                raise RuntimeError('No entry script %s found' % x)
        return ','.join(result)
Пример #2
0
def install_loot_api(version, revision, dl_dir, destination_path):
    url = ("https://github.com/loot/loot-api-python/releases/download/"
           "{0}/loot_api_python-{0}-0-g{1}_master-python2.7-win32.7z".format(
               version, revision))
    archive_path = os.path.join(dl_dir, "loot_api.7z")
    seven_zip_folder = os.path.join(MOPY_PATH, "bash", "compiled")
    seven_zip_path = os.path.join(seven_zip_folder, "7z.exe")
    loot_dll = os.path.join(destination_path, "loot.dll")
    loot_api_pyd = os.path.join(destination_path, "loot_api.pyd")
    if os.path.exists(loot_dll):
        os.remove(loot_dll)
    if os.path.exists(loot_api_pyd):
        os.remove(loot_api_pyd)
    LOGGER.info("Downloading LOOT API Python wrapper...")
    LOGGER.debug("Download url: {}".format(url))
    LOGGER.debug(
        "Downloading LOOT API Python wrapper to {}".format(archive_path))
    utils.download_file(url, archive_path)
    LOGGER.info("Extracting LOOT API Python wrapper to " +
                utils.relpath(destination_path))
    command = [
        seven_zip_path,
        "e",
        archive_path,
        "-y",
        "-o" + destination_path,
        "*/loot.dll",
        "*/loot_api.pyd",
    ]
    utils.run_subprocess(command, LOGGER)
    os.remove(archive_path)
Пример #3
0
    def execute(self, args=None):
        prevCwd = os.getcwd()
        noseroot = join(join(join(alePath('recipes_installed'), 'test'), 'pkgs'), 'nose-0.11.0')
        coverageroot = join(join(join(alePath('recipes_installed'), 'test'), 'pkgs'), 'coverage-3.2b3')

        command = join(join(noseroot, 'bin/'), 'nosetests')

        args = [] if not args else args
        args += [
            '--nologcapture',
            '-m',
            'test',
            '-e',
            'lib.*',
            '-e',
            ".*\.ale.*",
            ]

        fullcommandwithargs = [command] + args
        relcommandwithargs = [relpath(command)] + args

        logging.info('Executing %s' % relcommandwithargs)

        pythonpath = ':'.join([noseroot] + getGaeLibs())

        p = Popen(fullcommandwithargs, env={'PYTHONPATH': pythonpath, 'PATH': os.environ['PATH']})  # todo: just yield a generator or get all .py files
        sts = os.waitpid(p.pid, 0)[1]

        return sts
Пример #4
0
def shoot_unit():
    os.system('clear')
    fname = random.choice(fnames)
    path = relpath(fname)
    shoot(
        "%(div)s\n%(name)s\n%(div)s\n" % {
            'div': "-" * len(path),
            'name': path
            },
        color='blue'
        )
    spinning_cursor(random.random()*5)
    with open(path, 'r') as f:
        shoot_file(fname, 'white')
        shoot("\n")
        spinning_cursor(random.random()*5)
        shoot("\n\n")

        if not fname.endswith(".py"):
            return

        for line in f.readlines():
            shoot("[profile] %s" % line.strip())
            spinning_cursor(random.random()*5)
            try:
                cProfile.run('re.compile("%s")' % line.strip())
            except Exception as e:
                shoot("[exception] %s" % e)
            spinning_cursor(random.random()*5)
Пример #5
0
    def _walk_bundle(self, bundle):
        bundle_path = os.path.join(self.repo_path, bundle)
        if not os.path.exists(bundle_path):
            return

        for dirpath, dirnames, filenames in os.walk(bundle_path):
            if self._is_directory_tracked(dirpath):
                continue

            relpath = utils.relpath(bundle_path, dirpath)
            yield dirpath, dirnames, filenames, relpath
Пример #6
0
def _init(args):
    '''Create a project to manage the obfuscated scripts.'''
    path = os.path.normpath(args.project)

    logging.info('Create project in %s ...', path)
    if os.path.exists(os.path.join(path, config_filename)):
        raise RuntimeError('A project already exists in "%s"' % path)
    if not os.path.exists(path):
        logging.info('Make project directory %s', path)
        os.makedirs(path)

    if os.path.isabs(args.src):
        pro_src = src = os.path.normpath(args.src)
    else:
        src = os.path.abspath(args.src)
        pro_src = relpath(src, os.path.abspath(path))
    logging.info('Python scripts base path: %s', src)

    name = os.path.basename(os.path.abspath(path))
    if (args.type == 'pkg') or \
       (args.type == 'auto' and os.path.exists(os.path.join(src,
                                                            '__init__.py'))):
        logging.info('Project is configured as package')
        project = Project(name=name,
                          title=name,
                          src=pro_src,
                          is_package=1,
                          entry=args.entry if args.entry else '__init__.py')
    else:
        logging.info('Project is configured as standalone application.')
        project = Project(name=name, title=name, src=pro_src, entry=args.entry)

    if args.capsule:
        capsule = os.path.abspath(args.capsule)
        logging.info('Set project capsule to %s', capsule)
    else:
        capsule = os.path.abspath(DEFAULT_CAPSULE)
        logging.info('Use global capsule as project capsule: %s', capsule)
    project._update(dict(capsule=capsule))

    logging.info('Create configure file ...')
    filename = os.path.join(path, config_filename)
    project.save(path)
    logging.info('Configure file %s created', filename)

    if sys.argv[0] == 'pyarmor.py':
        logging.info('Create pyarmor command ...')
        platname = sys.platform
        s = make_project_command(platname, sys.executable, sys.argv[0], path)
        logging.info('PyArmor command %s created', s)

    logging.info('Project init successfully.')
Пример #7
0
def setup_parser(parser):
    parser.add_argument(
        "-l",
        "--logfile",
        default=LOGFILE,
        help="Where to store the log. [default: {}]".format(utils.relpath(LOGFILE)),
    )
    parser.add_argument(
        "-mv",
        "--masterlist-version",
        default=MASTERLIST_VERSION,
        help="Which loot masterlist version to "
        "download [default: {}].".format(MASTERLIST_VERSION),
    )
Пример #8
0
def setup_parser(parser):
    parser.add_argument(
        u'-l',
        u'--logfile',
        default=LOGFILE,
        help=u'Where to store the log. '
        u'[default: {}]'.format(utils.relpath(LOGFILE)),
    )
    parser.add_argument(
        u'-mv',
        u'--masterlist-version',
        default=MASTERLIST_VERSION,
        help=u'Which loot masterlist version to download '
        u'[default: {}].'.format(MASTERLIST_VERSION),
    )
Пример #9
0
    def execute(self, args=None):
        modipydroot = join(join(join(alePath('recipes_installed'), 'pyautotest'), 'pkgs'), 'ishikawa-modipyd-1516eeb')

        arg = '.' if not args else args[0]

        command = join(modipydroot, 'bin/pyautotest')
        logging.info('Executing %s %s' % (relpath(command), arg))
        print 'Modify a source file to trigger any dependent tests to re-execute'

        commandwithargs = [command, arg] if arg else [command]

        pythonpath = ':'.join([modipydroot] + ['.'] + ['lib'] + getGaeLibs())

        p = Popen(commandwithargs, env={'PATH':os.environ['PATH'], 'PYTHONPATH': pythonpath})  # todo: just yield a generator or get all .py files
        sts = os.waitpid(p.pid, 0)[1]

        return sts
Пример #10
0
    def execute(self, args=None):
        ipythonroot = join(join(join(alePath('recipes_installed'), 'shell'), 'pkgs'), 'ipython-0.10')

        command = join(ipythonroot, 'ipython.py')
        logging.info('%s' % command)

        logging.info('Executing %s %s' % (relpath(command), args))

        commandwithargs = [command] + args if args else [command]
        
        commandwithargs += ['-ipythondir', join(ipythonroot, 'UserConfig')]
        commandwithargs += ['-color_info']

        pythonpath = ':'.join(['.'] + ['lib'] + getGaeLibs())

        p = Popen(commandwithargs, env={'PATH':os.environ['PATH'], 'PYTHONPATH': pythonpath, 'HOME': os.environ['HOME']})
        sts = os.waitpid(p.pid, 0)[1]

        return sts
Пример #11
0
 def countFolder(self, folder):
     for root, dirs, files in os.walk(folder):
         for file_name in files:
             (any, ext) = os.path.splitext(file_name)
             extension = ext.lower().strip()
             if extension == '':
                 continue
             counter = self.getCounter(extension)
             if not counter:
                 continue
             '''
                             if not counter :
                                     if (extension  not in ignores) and (extension not in errors):
                                             errors.append(extension)
                                     continue
                             '''
             relatedpath = utils.relpath(root, folder)
             real_file = os.path.join(relatedpath, file_name)
             info = counter.doCount(real_file)
             self.appendCountInfo(info)
Пример #12
0
 def countFolder(self, folder) :
         for root, dirs, files in os.walk(folder):
                 for file_name in files:
                         (any , ext) = os.path.splitext(file_name)
                         extension = ext.lower().strip()
                         if extension == '':
                                 continue
                         counter = self.getCounter(extension)
                         if not counter :
                                 continue
                         '''
                         if not counter :
                                 if (extension  not in ignores) and (extension not in errors):
                                         errors.append(extension)
                                 continue
                         '''
                         relatedpath = utils.relpath(root, folder)  
                         real_file = os.path.join(relatedpath, file_name)
                         info = counter.doCount(real_file)
                         self.appendCountInfo(info)
Пример #13
0
    def track(self, path, bundle=None):
        """Track a file or a directory."""
        # We don't use kwarg default, because None represents default to
        # callers
        bundle = bundle or 'Default'
        src_path = utils.truepath(path)
        is_directory = os.path.isdir(src_path)

        if self.root_path not in src_path:
            raise Exception('Cannot track files outside of root path')

        bundle_path = os.path.join(self.repo_path, bundle)
        dst_path = os.path.join(
            bundle_path, utils.relpath(self.root_path, src_path))

        undo_log = []

        dst_dir = os.path.dirname(dst_path)
        if not os.path.exists(dst_dir):
            utils.makedirs(dst_dir, dry_run=self.dry_run, undo_log=undo_log)

        try:
            utils.rename(src_path, dst_path, dry_run=self.dry_run,
                         undo_log=undo_log)
            try:
                utils.symlink(dst_path, src_path, dry_run=self.dry_run)
            except:
                utils.undo_operations(undo_log)
                raise
        except:
            utils.undo_operations(undo_log)
            raise

        self.git.add(dst_path)

        if is_directory:
            marker = self._track_directory(dst_path)
            self.git.add(marker)

        self.git.commit(message="Tracking '%s'" % path)
Пример #14
0
def _config(args):
    '''Update project settings.'''
    for x in ('obf-module-mode', 'obf-code-mode', 'disable-restrict-mode'):
        if getattr(args, x.replace('-', '_')) is not None:
            logging.warning('Option --%s has been deprecated', x)

    project = Project()
    project.open(args.project)
    logging.info('Update project %s ...', args.project)

    if args.src is not None:
        src = os.path.abspath(args.src)
        if os.path.abspath(args.src):
            args.src = src
        else:
            args.src = relpath(src, project._path)
        logging.info('Format src to %s', args.src)
    if args.capsule is not None:
        args.capsule = os.path.abspath(args.capsule)
        logging.info('Change capsule to absolute path: %s', args.capsule)
    if args.plugins is not None:
        # plugins = project.get('plugins', [])
        if 'clear' in args.plugins:
            logging.info('Clear all plugins')
            args.plugins = []
    if args.disable_restrict_mode is not None:
        if args.restrict_mode is not None:
            logging.warning('Option --disable_restrict_mode is ignored')
        else:
            args.restrict_mode = 0 if args.disable_restrict_mode else 1
    keys = project._update(dict(args._get_kwargs()))
    for k in keys:
        logging.info('Change project %s to "%s"', k, getattr(project, k))

    if keys:
        project.save(args.project)
        logging.info('Update project OK.')
    else:
        logging.info('Nothing changed.')
Пример #15
0
    download_dir = tempfile.mkdtemp()
    # if url is given in command line, always dl and install
    if not is_msvc_redist_installed(14, 15,
                                    26429) or args.loot_msvc is not None:
        install_msvc_redist(download_dir, args.loot_msvc)
    if is_loot_api_installed(args.loot_version, args.loot_revision):
        LOGGER.info("Found LOOT API wrapper version {}.{}".format(
            args.loot_version, args.loot_revision))
    else:
        install_loot_api(args.loot_version, args.loot_revision, download_dir,
                         MOPY_PATH)
    os.rmdir(download_dir)


if __name__ == "__main__":
    argparser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    utils.setup_common_parser(argparser)
    argparser.add_argument(
        "-l",
        "--logfile",
        default=LOGFILE,
        help="Where to store the log. [default: {}]".format(
            utils.relpath(LOGFILE)),
    )
    setup_parser(argparser)
    parsed_args = argparser.parse_args()
    open(parsed_args.logfile, "w").close()
    main(parsed_args)
Пример #16
0
 def _relpath(p):
     return p if os.path.isabs(p) \
         else relpath(os.path.abspath(p), project._path)
Пример #17
0
# -*- coding: utf-8 -*-
import os
import time

from utils import shoot, shoot_file, shoot_table, \
                  weighted_choice, random, spinning_cursor
from utils import relpath

fname = relpath('osceleton.trace')
with open(fname, 'r+') as f:
    lines = f.readlines()
    f.close()

i = 0
while True:
    freeze = random.random() * 0.3
    try:
        shoot(lines[i])
        i += 1
    except IndexError:
        i = 0
        # clear output each time the whole trace file is out
        os.system('clear')
        spinning_cursor(random.random())

    # occasionally output line breaks
    if weighted_choice([(True, 1), (False, 9)]):
        shoot('\n')

    # occasionally output table
    if weighted_choice([(True, 0.5), (False, 9.5)]):
Пример #18
0
def _build(args):
    '''Build project, obfuscate all scripts in the project.'''
    project = Project()
    project.open(args.project)
    logging.info('Build project %s ...', args.project)

    logging.info('Check project')
    project.check()

    suffix = get_name_suffix() if project.get('enable_suffix', 0) else ''
    capsule = project.get('capsule', DEFAULT_CAPSULE)
    logging.info('Use capsule: %s', capsule)

    output = project.output if args.output is None \
        else os.path.normpath(args.output)
    logging.info('Output path is: %s', output)

    if args.platforms:
        platforms = [] if '' in args.platforms else args.platforms
    elif project.get('platform'):
        platforms = project.get('platform').split(',')
    else:
        platforms = []
    if platforms:
        platforms = compatible_platform_names(platforms)
        logging.info('Taget platforms: %s', platforms)
        if check_cross_platform(platforms) is not False:
            return

    restrict = project.get('restrict_mode',
                           0 if project.get('disable_restrict_mode') else 1)

    if not args.only_runtime:
        src = project.src
        if os.path.abspath(output).startswith(src):
            excludes = ['prune %s' % os.path.abspath(output)[len(src)+1:]]
        else:
            excludes = []

        files = project.get_build_files(args.force, excludes=excludes)
        soutput = os.path.join(output, os.path.basename(src)) \
            if project.get('is_package') else output

        logging.info('Save obfuscated scripts to "%s"', soutput)
        if not os.path.exists(soutput):
            os.makedirs(soutput)

        logging.info('Read public key from capsule')
        prokey = get_product_key(capsule)

        logging.info('%s increment build',
                     'Disable' if args.force else 'Enable')
        logging.info('Search scripts from %s', src)

        logging.info('Obfuscate scripts with mode:')
        if hasattr(project, 'obf_mod'):
            obf_mod = project.obf_mod
        else:
            obf_mod = project.obf_module_mode == 'des'
        if hasattr(project, 'wrap_mode'):
            wrap_mode = project.wrap_mode
            obf_code = project.obf_code
        elif project.obf_code_mode == 'wrap':
            wrap_mode = 1
            obf_code = 1
        else:
            wrap_mode = 0
            obf_code = 0 if project.obf_code_mode == 'none' else 1

        adv_mode = (1 if project.advanced_mode else 0) \
            if hasattr(project, 'advanced_mode') else 0

        def v(t):
            return 'on' if t else 'off'
        logging.info('Obfuscating the whole module is %s', v(obf_mod))
        logging.info('Obfuscating each function is %s', v(obf_code))
        logging.info('Autowrap each code object mode is %s', v(wrap_mode))
        logging.info('Advanced mode is %s', v(adv_mode))
        logging.info('Restrict mode is %s', restrict)

        entries = [build_path(s.strip(), project.src)
                   for s in project.entry.split(',')] if project.entry else []
        protection = project.cross_protection \
            if hasattr(project, 'cross_protection') else 1

        for x in sorted(files):
            a, b = os.path.join(src, x), os.path.join(soutput, x)
            logging.info('\t%s -> %s', x, relpath(b))

            d = os.path.dirname(b)
            if not os.path.exists(d):
                os.makedirs(d)

            if hasattr(project, 'plugins'):
                plugins = search_plugins(project.plugins)
            else:
                plugins = None

            if entries and (os.path.abspath(a) in entries):
                vmode = adv_mode | 8
                pcode = protection
            else:
                vmode = adv_mode
                pcode = 0

            encrypt_script(prokey, a, b, obf_code=obf_code, obf_mod=obf_mod,
                           wrap_mode=wrap_mode, adv_mode=vmode,
                           rest_mode=restrict, protection=pcode,
                           platforms=platforms, plugins=plugins,
                           rpath=project.runtime_path, suffix=suffix)

        logging.info('%d scripts has been obfuscated', len(files))
        project['build_time'] = time.time()
        project.save(args.project)

        if project.entry and project.get('bootstrap_code', 1):
            soutput = os.path.join(output, os.path.basename(project.src)) \
                if project.get('is_package') else output
            n = project.get('bootstrap_code', 1)
            relative = True if n == 3 else \
                False if (n == 2 or (args.no_runtime and n == 1)) else None
            make_entry(project.entry, project.src, soutput,
                       rpath=project.runtime_path, relative=relative,
                       suffix=suffix)

    if not args.no_runtime:
        routput = output if args.output is not None and args.only_runtime \
            else os.path.join(output, os.path.basename(project.src)) \
            if project.get('is_package') else output
        if not os.path.exists(routput):
            logging.info('Make path: %s', routput)
            os.mkdir(routput)

        package = project.get('package_runtime', 0) \
            if args.package_runtime is None else args.package_runtime
        make_runtime(capsule, routput, platforms=platforms, package=package,
                     suffix=suffix)

        licfile = project.license_file
        if licfile:
            logging.info('Project has customized license file: %s', licfile)
            licpath = os.path.join(routput, 'pytransform' + suffix) \
                if package else routput
            logging.info('Copy project license file to %s', licpath)
            shutil.copy(licfile, licpath)
        elif not restrict:
            licode = '*FLAGS:%c*CODE:PyArmor-Project' % chr(1)
            licpath = os.path.join(routput, 'pytransform' + suffix) \
                if package else routput
            licfile = os.path.join(licpath, license_filename)
            logging.info('Generate no restrict mode license file: %s', licfile)
            make_license_key(capsule, licode, licfile)

    logging.info('Build project OK.')
Пример #19
0
 def save_game(self):
     dt = str(datetime.now()).replace(':', '-')
     fn = relpath(f'saves/{dt}.txt')
     game.save(fn)
Пример #20
0
def _obfuscate(args):
    '''Obfuscate scripts without project.'''
    platforms = compatible_platform_names(args.platforms)
    if platforms:
        logging.info('Target platforms: %s', platforms)
        if check_cross_platform(platforms) is not False:
            return

    for x in ('entry', 'cross-protection'):
        if getattr(args, x.replace('-', '_')) is not None:
            logging.warning('Option --%s has been deprecated', x)

    if args.src is None:
        if args.scripts[0].lower().endswith('.py'):
            path = os.path.abspath(os.path.dirname(args.scripts[0]))
        else:
            path = os.path.abspath(args.scripts[0])
            args.src = path
            if len(args.scripts) > 1:
                raise RuntimeError('Only one path is allowed')
            args.scripts = []
    else:
        for s in args.scripts:
            if not s.lower().endswith('.py'):
                raise RuntimeError('Only one path is allowed')
        path = os.path.abspath(args.src)
    if not args.exact and len(args.scripts) > 1:
        raise RuntimeError('Two many entry scripts, only one is allowed')
    if not os.path.exists(path):
        raise RuntimeError('Not found source path: %s' % path)
    logging.info('Source path is "%s"', path)

    entries = [args.entry] if args.entry else args.scripts
    logging.info('Entry scripts are %s', entries)

    capsule = args.capsule if args.capsule else DEFAULT_CAPSULE
    if os.path.exists(capsule):
        logging.info('Use cached capsule %s', capsule)
    else:
        logging.info('Generate capsule %s', capsule)
        make_capsule(capsule)

    output = args.output
    if os.path.abspath(output) == path:
        raise RuntimeError('Output path can not be same as src')

    suffix = get_name_suffix() if args.enable_suffix else ''

    if args.recursive:
        logging.info('Recursive mode is on')
        pats = ['global-include *.py']

        if args.exclude:
            for item in args.exclude:
                for x in item.split(','):
                    if x.endswith('.py'):
                        logging.info('Exclude pattern "%s"', x)
                        pats.append('exclude %s' % x)
                    else:
                        logging.info('Exclude path "%s"', x)
                        pats.append('prune %s' % x)

        if os.path.abspath(output).startswith(path):
            x = os.path.abspath(output)[len(path):].strip('/\\')
            pats.append('prune %s' % x)
            logging.info('Auto exclude output path "%s"', x)

        if hasattr('', 'decode'):
            pats = [p.decode() for p in pats]

        files = Project.build_manifest(pats, path)

    elif args.exact:
        logging.info('Exact mode is on')
        files = [os.path.abspath(x) for x in args.scripts]

    else:
        logging.info('Normal mode is on')
        files = Project.build_globfiles(['*.py'], path)

    logging.info('Save obfuscated scripts to "%s"', output)
    if not os.path.exists(output):
        os.makedirs(output)

    logging.info('Read public key from capsule')
    prokey = get_product_key(capsule)

    logging.info('Obfuscate scripts with default mode')
    cross_protection = 0 if args.no_cross_protection else \
        1 if args.cross_protection is None else args.cross_protection

    advanced = 1 if args.advanced else 0
    logging.info('Advanced mode is %d', advanced)

    restrict = args.restrict
    logging.info('Restrict mode is %d', restrict)

    n = args.bootstrap_code
    relative = True if n == 3 else False if n == 2 else None
    bootstrap = (not args.no_bootstrap) and n
    elist = [os.path.abspath(x) for x in entries]
    for x in sorted(files):
        if os.path.isabs(x):
            a, b = x, os.path.join(output, os.path.basename(x))
        else:
            a, b = os.path.join(path, x), os.path.join(output, x)
        logging.info('\t%s -> %s', x, relpath(b))
        is_entry = os.path.abspath(a) in elist
        protection = is_entry and cross_protection
        plugins = search_plugins(args.plugins)

        d = os.path.dirname(b)
        if not os.path.exists(d):
            os.makedirs(d)

        vmode = advanced | (8 if is_entry else 0)
        encrypt_script(prokey, a, b, adv_mode=vmode, rest_mode=restrict,
                       protection=protection, platforms=platforms,
                       plugins=plugins, suffix=suffix)

        if is_entry and bootstrap:
            name = os.path.abspath(a)[len(path)+1:]
            make_entry(name, path, output, relative=relative, suffix=suffix)

    logging.info('%d scripts have been obfuscated', len(files))

    if args.no_runtime:
        logging.info('Obfuscate %d scripts OK.', len(files))
        return

    package = args.package_runtime
    make_runtime(capsule, output, platforms=platforms,
                 package=package, suffix=suffix)

    logging.info('Obfuscate scripts with restrict mode %s',
                 'on' if args.restrict else 'off')
    if not args.restrict:
        licode = '*FLAGS:%c*CODE:PyArmor-Project' % chr(1)
        licpath = (os.path.join(output, 'pytransform' + suffix) if package
                   else output)
        licfile = os.path.join(licpath, license_filename)
        logging.info('Generate no restrict mode license file: %s', licfile)
        make_license_key(capsule, licode, licfile)

    logging.info('Obfuscate %d scripts OK.', len(files))
Пример #21
0
#!/usr/bin/env python
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '../python'))

from testjob import TestJob
from utils import relpath
import logging

TestJob.inpath = relpath('../data/sampleB')
TestJob.outfile = relpath('./output/contrast.tif')
logging.basicConfig(level=logging.DEBUG,
                    filename='tests.log', filemode='w',
                    format='%(name)s %(levelname)s %(message)s')

job = TestJob('piv-contrast')

job.profiling = False
job.deviceCPU = True
job.parser.add_argument('--c1', type=float, default=-0.5)
job.parser.add_argument('--c2', type=float, default=10.0)
job.parser.add_argument('--c3', type=float, default=3.0)
job.parser.add_argument('--c4', type=float, default=1.5)

t0 = job.run()
print "Running Test:", t0, "(s)"

 def save(self, fn):
     json.dump\
     ({
         'player': self.player.to_data(),
         'level': self.level.name
     }, open(relpath(fn), 'w'))
Пример #23
0
#!/usr/bin/env python
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '../python'))

from testjob import TestJob
from utils import relpath
import logging

TestJob.inpath = relpath('../data/sampleC')
TestJob.outfile = relpath('./output/denoise.tif')
logging.basicConfig(level=logging.DEBUG, filename='tests.log', filemode='w',
                    format='%(name)s %(levelname)s %(message)s')

job = TestJob('denoise')
job.profiling = False
job.deviceCPU = False

t0 = job.run()
print "Running Test:", t0, "(s)"

Пример #24
0
#!/usr/bin/env python
from ufojob import UfoJob
from ddict import DotDict
import argparse
import sys, os
from inspect import stack
from utils import relpath, LogMixin

default_inpath  = relpath('../data/sampleB')
default_outfile = relpath('../data/res.tif')

class TestJob(UfoJob, LogMixin):
    inpath = default_inpath
    outfile = default_outfile

    def __init__(self, filtername=None, **parms):
        super(TestJob, self).__init__(profiling=False, schedfixed=True, deviceCPU=False)

        self.filter = filtername
        self.filter_parms = DotDict(parms)

        self.parser = argparse.ArgumentParser()
        self.parser.add_argument('-i', '--inpath')
        self.parser.add_argument('-o', '--outfile')
        self.parser.add_argument('-n', '--number', type=int)
        self.parser.add_argument('-p', '--profiling', action='store_true', default=None)
        self.parser.add_argument('-c', '--cpu', action='store_true', default=False)
        self.args, self.extra_args = self.parser.parse_known_args()
        self.logger.debug(self.args)
        self.logger.debug("extra arguments: %s" % self.extra_args)
 def load(self, fn):
     with open(relpath(fn), 'r') as file:
         data = json.load(file)
     self.player = Player.load(data['player'])
     self.level = Level.load(data['level'])
Пример #26
0
def handler(req, args):
        session_id = utils.get_cookie(req, "session").strip()

        if session_id == "":
		logging.warning('Unathorized attempt to access %s from %s' % (req.the_request, req.connection.remote_ip))
                return {"Location":"login.html", "error_msg":"Authorization required!"}

        notice_message = ""
        if args.has_key("notice_msg"):
                notice_message = args["notice_msg"]

        error_message = ""
        if args.has_key("error_msg"):
                error_message = args["error_msg"]

        filter = ""
        if args.has_key("q"):
                filter = args["q"]
	

        con = MySQLdb.connect(  host = settings.database_settings["host"],
                                user = settings.database_settings["login"],
                                passwd = settings.database_settings["password"],
                                db = settings.database_settings["database"])

        cur = con.cursor()
        try:
                expired, user_id = utils.is_expired(cur, session_id)
                if expired:
                        return {"Location":"login.html", "error_msg":"You session has expired. Please log in"}

		#construct user home
		user_home = utils.get_user_home(user_id)

		file_list = os.popen("ls -l %s" % os.path.join(user_home, "*%s*" % filter)).read().split(os.linesep)

		title = "<h2>List of Your files</h2>"
		if len(filter) > 0:
			title = "<h2>Search results for: %s</h2>" % filter

		contents = '''<table width="100%%" cellspacing="3" cellpadding="3">
					<tr>
					<td align="left" width = "50%%">%s</td>
					<td align="right" width="50%%">
					<form action="files.html" method="GET">
					Search files: <input type="text" name="q" value="%s">
					<input type="submit" value="Search">
					</form>
					</td>
					</tr>
				</table>
				''' % (title, filter) + os.linesep
		
		contents = contents + "<table width=\"100%\" border=\"1\" cellspacing=\"3\" cellpadding=\"3\">" + os.linesep
		contents = contents + "<form action=\"deletefiles.html\" method=\"POST\" >" + os.linesep
		contents = contents + "<tr>"  + os.linesep
		contents = contents + "<td align=\"center\" colspan=\"2\">Name</td>"  + os.linesep
		contents = contents + "<td align=\"center\" width=\"200\" >Size (bytes)</td>"  + os.linesep
		contents = contents + "<td align=\"center\" width=\"200\">Uploaded</td>"  + os.linesep
		contents = contents + "</tr>"  + os.linesep
		
		n_files = 0
		for file_entry in file_list:
			if file_entry.strip() == "":
				break

			file_attrs = file_entry.split(" ")
			i = 0
			while i < len(file_attrs):
				if len(file_attrs[i].strip()) == 0:
					del file_attrs[i]
				else:
					i = i + 1
			
			try:
				file_perm = file_attrs[0]
				file_id = file_attrs[1]
				file_owner = file_attrs[2]
				file_grp = file_attrs[3]
				file_size = file_attrs[4]
				file_date = file_attrs[5]
				file_time = file_attrs[6]
				file_name = os.path.basename(file_attrs[7])
			except KeyError:
				break

			contents = contents + "<tr>" + os.linesep
			contents = contents + "<td width=\"30\">" + os.linesep
			contents = contents + "<input type=\"checkbox\" name=\"%s\">" % (file_name, ) + os.linesep
			contents = contents + "</td>" + os.linesep
			
			contents = contents + "<td>" + os.linesep
			file_relative = utils.relpath(os.path.dirname(template_path), os.path.join(user_home, file_name))
			contents = contents + "<a target=\"_blank\" href=\"showfile.html?file=%s\">%s</a>" % (file_name, file_name) + os.linesep
			contents = contents + "</td>" + os.linesep
			
			contents = contents + "<td align=\"center\">" + os.linesep
			contents = contents + file_size + os.linesep
			contents = contents + "</td>" + os.linesep
			
			contents = contents + "<td align=\"center\">" + os.linesep
			contents = contents + file_date + " " + file_time + os.linesep
			contents = contents + "</td>" + os.linesep
			contents = contents + "</tr>" + os.linesep

			n_files = n_files + 1

		contents = contents + "<tr>" + os.linesep
		contents = contents + "<td colspan=\"4\" align=\"center\">" + os.linesep
		if n_files > 0:
			contents = contents + "<input type=\"submit\" value=\"Delete files\">" + os.linesep
		contents = contents + "</td>" + os.linesep
		contents = contents + "</tr>" + os.linesep
		contents = contents + "</form>" + os.linesep
		contents = contents + "</table>" + os.linesep

		contents = contents + "<p align=\"right\">" + os.linesep
		contents = contents + "<b><i>Add more files:</i></b><br>" + os.linesep
		contents = contents + "<form action=\"addfiles.html\" method=\"POST\" ENCTYPE=\"multipart/form-data\">" + os.linesep
		contents = contents + "<input type=\"file\" name=\"upload\">" + os.linesep
		contents = contents + "<input type=\"submit\"  value=\"Upload file\">" + os.linesep
		contents = contents + "</form>" + os.linesep
		contents = contents + "</p>" + os.linesep
        finally:
                con.commit()
                cur.close()
                con.close()

        contents = const.html_template.replace("%contents%", contents)
        contents = contents.replace(const.notice_pattern, const.notice_message % notice_message)
        contents = contents.replace(const.error_pattern, const.error_message % error_message)
        return contents