Пример #1
0
def init_hello_world():
    targets_filepath = 'source/hello_world/targets.json'
    helloworld_filepath = 'source/hello_world/hello_world.cpp'
    critical_error_if_file_exists(helloworld_filepath)
    critical_error_if_file_exists(targets_filepath)
    util.mkdir_p(os.path.dirname(targets_filepath))

    with open(targets_filepath, 'w+') as fd:
        fd.write(util.get_resource('defaults/targets.json'))
    with open(helloworld_filepath, 'w+') as fd:
        fd.write(util.get_resource('defaults/hello_world.cpp'))
Пример #2
0
def init_hello_world():
    targets_filepath = 'source/hello_world/targets.json'
    helloworld_filepath = 'source/hello_world/hello_world.cpp'
    critical_error_if_file_exists(helloworld_filepath)
    critical_error_if_file_exists(targets_filepath)
    util.mkdir_p(os.path.dirname(targets_filepath))

    with open(targets_filepath, 'w+') as  fd:
        fd.write(util.get_resource('defaults/targets.json'))
    with open(helloworld_filepath, 'w+') as  fd:
        fd.write(util.get_resource('defaults/hello_world.cpp'))
Пример #3
0
def generate(targets, settings, compiler, output_dir):
    build_targets = []
    ninja_settings = settings.get('ninja')
    filepath = os.path.join(output_dir, ninja_settings.get('filename', 'build.ninja'))
    with open(filepath, 'w+') as out:
        ninja = Ninja(out)
        if ninja_settings.get('add_default_rules', True):
            ninja.newline()
            out.write(get_resource('defaults/rules.ninja'))
        if ninja_settings.get('include_file', None) is not None:
            ninja.add_include(ninja_settings['include_file'])
        ninja.add_variables(settings.get('variables'))
        ninja.add_variables(compiler.get_global_variables())
        for config in compiler.get_configurations():
            ninja.open_configuration(config.name, config.bin, config.lib, config.obj)
            for target in targets:
                if not target['headers'] and not target['sources']:
                    continue
                target_type = target['type']
                cflags = config.cflags + ' ' + compiler.get_compiler_flags(target.raw)
                if target_type == 'executable':
                    lflags = config.lflags + ' ' + compiler.get_linker_flags(target.raw)
                    btarget = ninja.add_executable(target, cflags.strip(), lflags.strip())
                    build_targets.append(btarget)
                elif target_type == 'static_library':
                    ninja.add_static_library(target, cflags.strip())
                else:
                    logging.warning('Target ignored: type "%s" not implemented', target_type)
        global_targets = ninja.add_global_targets()
    return NinjaTargets(build_targets, global_targets)
Пример #4
0
def obtain_resource(id, filename=None):
    # This function pulls information from a particular resource on a
    # CKAN instance and outputs it to a CSV file.

    # Tests suggest that there are some small differences between this
    # file and the one downloaded directly through the CKAN web
    # interface: 1) the row order is different (this version is ordered
    # by _id (logically) while the downloaded version has the same weird
    # order as that shown in the Data Explorer (which can have an _id
    # sequence like 1,2,3,4,5,6,7,45,8,9,10... for no obvious reason)
    # and 2) weird non-ASCII characters are not being handled optimally,
    # so probably some work on character encoding is in order in the
    # Python script.

    if filename is None:
        filename = "{}.csv".format(id)

    list_of_dicts, fields, success = get_resource(DEFAULT_CKAN_INSTANCE,
                                                  id,
                                                  chunk_size=1000)

    if not success:
        print("Something went wrong and the resource was not obtained.")
    else:

        #Eliminate _id field
        fields.remove("_id")
        print("The resource has the following fields: {}".format(fields))
        write_to_csv(filename, list_of_dicts, fields)
Пример #5
0
    def __init__(self, *args, **kwargs):
        QtGui.QDialog.__init__(self, *args, **kwargs)
        loadUi(get_resource('dialog_config.ui'), self)

        self.ok_button.released.connect(self.setAttributes)
        self.ok_button.released.connect(self.close)

        self.apply_button.released.connect(self.setAttributes)

        self.vector_color_picker = QtGui.QColorDialog(self)
        self.vector_color_picker.\
            setCurrentColor(QtGui.QColor(*config.vector_color))
        self.vector_color_picker.\
            setOption(self.vector_color_picker.ShowAlphaChannel)
        self.vector_color_picker.colorSelected.connect(self.updateVectorColor)
        self.vector_color_picker.setModal(True)
        self.vector_color.clicked.connect(self.vector_color_picker.show)

        self.vector_color.setValue = self.setButtonColor
        self.vector_color.value = self.getButtonColor

        self.chooseStoreDirButton.released.connect(self.chooseStoreDir)
        self.completer_model.setRootPath('')
        self.completer.setParent(self.default_gf_dir)
        self.default_gf_dir.setCompleter(self.completer)

        self.getAttributes()
Пример #6
0
def generate(ninja_targets, settings):
    project_name = settings.get('project_name')
    working_dir = '$rootdir'

    make_all = BuildSystem('make - ' + project_name, 'make build', working_dir)
    make_all.add_variant('All', 'make all')
    make_all.add_variant('Clean', 'make clean')
    make_all.add_variant('Sublime Text Project', 'make sublime')
    make_all.add_variant('Doxygen Documentation', 'make doxygen')
    ninja_all = BuildSystem('ninja - ' + project_name, 'ninja', working_dir)
    ninja_all.add_variant('All', 'ninja all')
    ninja_all.add_variant('Clean', 'ninja -t clean')
    ninja_all.add_variant('Doxygen Documentation', 'ninja doxygen')

    build_systems = [make_all.data, ninja_all.data]

    for target in ninja_targets.build_targets:
        build_target = BuildSystem(
            target.config + ' - ' + target.name,
            'ninja %s' % target.phony_name,
            working_dir)
        bindir = get_bin(target.config, settings)
        binary = Path.join(working_dir, bindir, target.name)
        build_target.add_variant(
            'Run',
            'ninja %s && %s' % (target.phony_name, binary))
        build_target.add_variant(
            'Clean',
            'ninja -t clean %s' % target.phony_name)
        build_systems.append(build_target.data)

    sublime_settings = settings.get('sublime')

    template_filename = settings.expand_variables(sublime_settings.get('project_template', None))
    if template_filename is not None:
        with open(template_filename, 'r') as fd:
            template = fd.read()
        if not template:
            critical_error('%s seems to be empty', template_filename)
    else:
        template = util.get_resource('defaults/tmpl.sublime-project')

    project = re.sub(
        r'(\$build_systems)',
        json.dumps(build_systems, indent=4, separators=(',', ': ')),
        template)
    project = settings.expand_variables(project)

    filename = settings.expand_variables('$projectsdir/$project_name.sublime-project')
    util.mkdir_p(os.path.dirname(filename))
    with open(filename, 'w+') as out:
        out.write(project)
Пример #7
0
def generate(settings):
    template_filename = settings.get('doxygen').get('doxyfile_template', None)
    template_filename = settings.expand_variables(template_filename)
    if template_filename is not None:
        with open(template_filename, 'r') as fd:
            template = fd.read()
        if not template:
            util.critical_error('%s seems to be empty', template_filename)
    else:
        template = util.get_resource('defaults/Doxyfile')
    doxyfile = settings.expand_variables(template)

    with open(settings.expand_variables('$builddir/Doxyfile'), 'w+') as fd:
        fd.write(doxyfile)
Пример #8
0
def init_settings_file(filepath):
    critical_error_if_file_exists(filepath)

    if util.which('ninja') is None:
        logging.warning('cannot find ninja')

    varlist = {
        'project_name': os.path.basename(os.getcwd()),
        'sourcedir': 'source',
        'cxx': get_compiler()
    }

    template = util.get_resource('defaults/configure.yaml')

    for key, value in varlist.items():
        template = re.sub(r'(%%%s%%)' % key, value, template)

    with open(filepath, 'w+') as fd:
        fd.write(template)
Пример #9
0
def init_settings_file(filepath):
    critical_error_if_file_exists(filepath)

    if util.which('ninja') is None:
        logging.warning('cannot find ninja')

    varlist = {
        'project_name': os.path.basename(os.getcwd()),
        'sourcedir': 'source',
        'cxx': get_compiler()
    }

    template = util.get_resource('defaults/configure.yaml')

    for key, value in varlist.items():
        template = re.sub(r'(%%%s%%)' % key, value, template)

    with open(filepath, 'w+') as  fd:
        fd.write(template)
Пример #10
0
def generate(targets, settings, compiler, output_dir):
    build_targets = []
    ninja_settings = settings.get('ninja')
    filepath = os.path.join(output_dir,
                            ninja_settings.get('filename', 'build.ninja'))
    with open(filepath, 'w+') as out:
        ninja = Ninja(out)
        if ninja_settings.get('add_default_rules', True):
            ninja.newline()
            out.write(get_resource('defaults/rules.ninja'))
        if ninja_settings.get('include_file', None) is not None:
            ninja.add_include(ninja_settings['include_file'])
        ninja.add_variables(settings.get('variables'))
        ninja.add_variables(compiler.get_global_variables())
        for config in compiler.get_configurations():
            ninja.open_configuration(config.name, config.bin, config.lib,
                                     config.obj)
            for target in targets:
                if not target['headers'] and not target['sources']:
                    continue
                target_type = target['type']
                cflags = config.cflags + ' ' + compiler.get_compiler_flags(
                    target.raw)
                if target_type == 'executable':
                    lflags = config.lflags + ' ' + compiler.get_linker_flags(
                        target.raw)
                    btarget = ninja.add_executable(target, cflags.strip(),
                                                   lflags.strip())
                    build_targets.append(btarget)
                elif target_type == 'static_library':
                    ninja.add_static_library(target, cflags.strip())
                else:
                    logging.warning(
                        'Target ignored: type "%s" not implemented',
                        target_type)
        global_targets = ninja.add_global_targets()
    return NinjaTargets(build_targets, global_targets)
Пример #11
0
import boto3
import sys
import util

table_name = 's3_object_list'
object_name = sys.argv[1]

Item = {
    'object_name': object_name,
    'in_processing': 'n',
    'processing_completed': 'n'
}

dynamodb = util.get_resource('dynamodb')

table = dynamodb.Table(table_name)

table.put_item(Item=Item)
Пример #12
0
def main():
    argparser = argparse.ArgumentParser(description=__doc__)
    argparser.add_argument(
        '-v', '--version',
        action='version',
        version='%(prog)s ' + util.get_resource('version.txt'))
    argparser.add_argument(
        '-d', '--debug',
        action='store_true',
        help='print debug information')
    argparser.add_argument(
        '--targets',
        action='store_true',
        help='write out targets (for debugging purposes)')
    argparser.add_argument(
        '--hello-world',
        action='store_true',
        dest='init_hello_world',
        help='initialize this folder with a "hello world" project')
    settings_file_group = argparser.add_argument_group('configuration file')
    default_settings = util.get_default_settings_file()
    settings_file_group.add_argument(
        '-f',
        metavar='FILE',
        dest='settings_file',
        default=default_settings,
        help='path to an existing config file, defaults to %s' % default_settings)
    settings_file_group.add_argument(
        '-g',
        action='store_true',
        dest='init_settings_file',
        help='generate a default %s file' % default_settings)
    generators_group = argparser.add_argument_group('generators')
    help_gatherer = HelpGatherer(generators_group)
    generators_group.add_argument(
        '--embed',
        action='store_true',
        help='embed resources (experimental)')
    generators_group.add_argument(
        '--ninja',
        action='store_true',
        help='generate build.ninja')
    generators_group.add_argument(
        '--makefile',
        action='store_true',
        help='generate Makefile')
    generators_group.add_argument(
        '--doxyfile',
        action='store_true',
        help='generate doxygen\'s Doxyfile')
    generators_group.add_argument(
        '--sublime',
        action='store_true',
        help='generate Sublime Text project')
    generators_group.add_argument(
        '--codeblocks',
        action='store_true',
        help='generate CodeBlocks projects (experimental)')
    args = argparser.parse_args()

    loglevel = logging.DEBUG if args.debug else logging.WARNING
    logging.basicConfig(format='%(levelname)s: %(message)s', level=loglevel)

    try:
      builtin_open = __builtin__.open
      def open_hook(*args, **kwargs):
          logging.debug('Open file: %s', args[0])
          try:
              return builtin_open(*args, **kwargs)
          except Exception as exception:
              critical_error(exception)
      __builtin__.open = open_hook
    except Exception as exception:
        logging.warning('Hook to open failed: %s', exception)

    if args.init_settings_file or args.init_hello_world:
        print_out('Generate %s.' % args.settings_file)
        import init
        init.init_settings_file(args.settings_file)
    if args.init_hello_world:
        print_out('Generate "Hello World" code.')
        init.init_hello_world()
        args.makefile = True

    if args.settings_file is None:
        print_out('Missing settings.')
        argparser.print_usage()
        return

    actions = ['targets', 'embed', 'ninja', 'makefile', 'doxyfile', 'sublime', 'codeblocks']
    action_count = sum(getattr(args, x) for x in actions)

    if action_count == 0:
        print_out('Nothing to be done.')
        argparser.print_usage()
        return

    Settings.load(args.settings_file)

    targets = [x for x in iterate_targets(Settings.get('sourcedir'))]
    logging.info('%i targets found', len(targets))

    if args.targets:
        data = {'targets': [x.raw for x in targets]}
        targets_file = os.path.join(Settings.get('builddir'), 'targets.json')
        util.mkdir_p(os.path.dirname(targets_file))
        with open(targets_file, 'w+') as out:
            out.write(json.dumps(data, indent=2))
        print_out('Targets saved to %s.' % targets_file)
        if action_count == 1:
            return

    if args.embed:
        print_out(help_gatherer.command_help['--embed'])
        import embedder
        embedder.embed(targets, Settings.get('sourcedir'))
        print_out("Targets may have changed, re-run configure.pyz to update.")
        return

    compiler = Compiler(Settings)

    if args.doxyfile:
        print_out(help_gatherer.command_help['--doxyfile'])
        import doxygen
        doxygen.generate(Settings)

    if args.ninja or args.makefile or args.sublime:
        print_out(help_gatherer.command_help['--ninja'])
        import ninja
        ninja_targets = ninja.generate(targets, Settings, compiler, '.')

        if args.makefile:
            print_out(help_gatherer.command_help['--makefile'])
            import makefile
            this = Path.clean(os.path.relpath(sys.argv[0]))
            command_call = [this, '-f', args.settings_file]
            makefile.generate(command_call, ninja_targets, actions, Settings, '.')

        if args.sublime:
            print_out(help_gatherer.command_help['--sublime'])
            import sublime
            sublime.generate(ninja_targets, Settings)

    if args.codeblocks:
        print_out(help_gatherer.command_help['--codeblocks'])
        import codeblocks
        codeblocks.generate(targets, Settings, compiler)
Пример #13
0
 def _load_template(self):
     with open(get_resource('template.yaml')) as f:
         yaml_document_all = yaml.safe_load_all(f)
         for yaml_document in yaml_document_all:
             return yaml_document