Beispiel #1
0
    def generate(self, device):
        if os.getenv('TINKERFORGE_GENERATE_EXAMPLES_FOR_DEVICE',
                     device.get_name().camel) != device.get_name().camel:
            common.print_verbose('    \033[01;31m- skipped\033[0m')
            return

        examples_dir = self.get_examples_dir(device)
        examples = device.get_examples()

        if len(examples) == 0:
            common.print_verbose('    \033[01;31m- no examples\033[0m')
            return

        if not os.path.exists(examples_dir):
            os.makedirs(examples_dir)

        for example in examples:
            filename = 'example_{0}.py'.format(example.get_name().under)
            filepath = os.path.join(examples_dir, filename)

            if example.is_incomplete():
                if os.path.exists(
                        filepath) and self.skip_existing_incomplete_example:
                    common.print_verbose(
                        '    - ' + filename +
                        ' \033[01;35m(incomplete, skipped)\033[0m')
                    continue
                else:
                    common.print_verbose('    - ' + filename +
                                         ' \033[01;31m(incomplete)\033[0m')
            else:
                common.print_verbose('    - ' + filename)

            with open(filepath, 'w') as f:
                f.write(example.get_python_source())
Beispiel #2
0
    def generate(self, device):
        if os.getenv('TINKERFORGE_GENERATE_EXAMPLES_FOR_DEVICE',
                     device.get_name().camel) != device.get_name().camel:
            common.print_verbose('    \033[01;31m- skipped\033[0m')
            return

        examples_dir = self.get_examples_dir(device)
        examples = device.get_examples()

        if len(examples) == 0:
            common.print_verbose('    \033[01;31m- no examples\033[0m')
            return

        if not os.path.exists(examples_dir):
            os.makedirs(examples_dir)

        for example in examples:
            filename = 'example_{0}.rs'.format(example.get_name().under)
            filepath = os.path.join(examples_dir, filename)

            if example.is_incomplete():
                if os.path.exists(
                        filepath) and self.skip_existing_incomplete_example:
                    common.print_verbose(
                        '    - ' + filename +
                        ' \033[01;35m(incomplete, skipped)\033[0m')
                    continue
                else:
                    common.print_verbose('    - ' + filename +
                                         ' \033[01;31m(incomplete)\033[0m')
            else:
                common.print_verbose('    - ' + filename)

            with open(filepath, 'w') as f:
                f.write(example.get_rust_source())

            version = subprocess.check_output(["rustfmt", "--version"])

            if not 'nightly' in version.decode('utf-8'):
                print(
                    "Please set your rust toolchain to nightly (e.g. with 'rustup default nightly'), as the example generator currently depends on unstable rustfmt features."
                )
                return

            p = subprocess.Popen(
                ["rustfmt", filename, "--config-path", self.root_dir],
                cwd=examples_dir,
                stdout=subprocess.PIPE)
            out, err = p.communicate()  #block until rustfmt has finished

            if len(out) > 0 or err is not None:
                print("Got the following output from rustfmt:")
                print(out)
                print(err)
Beispiel #3
0
    def generate(self, device):
        if os.getenv('TINKERFORGE_GENERATE_EXAMPLES_FOR_DEVICE',
                     device.get_name().camel) != device.get_name().camel:
            common.print_verbose('    \033[01;31m- skipped\033[0m')
            return

        examples_dir = self.get_examples_dir(device)
        examples = device.get_examples()

        if len(examples) == 0:
            common.print_verbose('    \033[01;31m- no examples\033[0m')
            return

        if not os.path.exists(examples_dir):
            os.makedirs(examples_dir)

        for example in examples:
            filename = 'example_{0}.go'.format(example.get_name().under)
            filepath = os.path.join(examples_dir, filename)

            if example.is_incomplete():
                if os.path.exists(
                        filepath) and self.skip_existing_incomplete_example:
                    common.print_verbose(
                        '    - ' + filename +
                        ' \033[01;35m(incomplete, skipped)\033[0m')
                    continue
                else:
                    common.print_verbose('    - ' + filename +
                                         ' \033[01;31m(incomplete)\033[0m')
            else:
                common.print_verbose('    - ' + filename)

            with open(filepath, 'w') as f:
                f.write(example.get_go_source())

            p = subprocess.Popen(["go", "fmt", filename],
                                 cwd=examples_dir,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            out, err = p.communicate()  # block until gofmt has finished

            if p.returncode != 0:
                print("Got the following output from go fmt:")
                print(out)
                print(err)
Beispiel #4
0
    def generate(self, device):
        if os.getenv('TINKERFORGE_GENERATE_EXAMPLES_FOR_DEVICE',
                     device.get_name().camel) != device.get_name().camel:
            common.print_verbose('    \033[01;31m- skipped\033[0m')
            return

        examples_dir = self.get_examples_dir(device)
        examples = device.get_examples()

        if len(examples) == 0:
            common.print_verbose('    \033[01;31m- no examples\033[0m')
            return

        if not os.path.exists(examples_dir):
            os.makedirs(examples_dir)

        blacklist = [
            'lcd-16x2-bricklet/unicode', 'lcd-20x4-bricklet/unicode',
            'nfc-bricklet/emulate-ndef', 'nfc-bricklet/scan-for-tags',
            'nfc-bricklet/write-read-type2'
        ]

        for example in examples:
            filename = 'Example{0}.nb.txt'.format(example.get_name().camel)
            filepath = os.path.join(examples_dir, filename)

            if device.get_git_name() + '/' + example.get_name(
            ).dash in blacklist:
                common.print_verbose(
                    '    - ' + filename +
                    ' \033[01;35m(blacklisted, skipped)\033[0m')
                continue

            if example.is_incomplete():
                if os.path.exists(
                        filepath) and self.skip_existing_incomplete_example:
                    common.print_verbose(
                        '    - ' + filename +
                        ' \033[01;35m(incomplete, skipped)\033[0m')
                    continue
                else:
                    common.print_verbose('    - ' + filename +
                                         ' \033[01;31m(incomplete)\033[0m')
            else:
                common.print_verbose('    - ' + filename)

            with open(filepath, 'w') as f:
                f.write(example.get_mathematica_source())

            txt2nb(filepath)
Beispiel #5
0
    def generate(self, device):
        if os.getenv('TINKERFORGE_GENERATE_EXAMPLES_FOR_DEVICE',
                     device.get_name().camel) != device.get_name().camel:
            common.print_verbose('    \033[01;31m- skipped\033[0m')
            return

        examples_dir = self.get_examples_dir(device)
        examples = device.get_examples()

        if len(examples) == 0:
            common.print_verbose('    \033[01;31m- no examples\033[0m')
            return

        if not os.path.exists(examples_dir):
            os.makedirs(examples_dir)

        blacklist = ['lcd-16x2-bricklet/unicode', 'lcd-20x4-bricklet/unicode']

        # matlab
        for example in examples:
            filename = 'matlab_example_{0}.m'.format(example.get_name().under)
            filepath = os.path.join(examples_dir, filename)

            if device.get_git_name() + '/' + example.get_name(
            ).dash in blacklist:
                common.print_verbose(
                    '    - ' + filename +
                    ' \033[01;35m(blacklisted, skipped)\033[0m')
                continue

            if example.is_incomplete():
                if os.path.exists(
                        filepath) and self.skip_existing_incomplete_example:
                    common.print_verbose(
                        '    - ' + filename +
                        ' \033[01;35m(incomplete, skipped)\033[0m')
                    continue
                else:
                    common.print_verbose('    - ' + filename +
                                         ' \033[01;31m(incomplete)\033[0m')
            else:
                common.print_verbose('    - ' + filename)

            with open(os.path.join(examples_dir, filename), 'w') as f:
                f.write(example.get_matlab_source())

        # octave
        for example in examples:
            filename = 'octave_example_{0}.m'.format(example.get_name().under)
            filepath = os.path.join(examples_dir, filename)

            if device.get_git_name() + '/' + example.get_name(
            ).dash in blacklist:
                common.print_verbose(
                    '    - ' + filename +
                    ' \033[01;35m(blacklisted, skipped)\033[0m')
                continue

            if example.is_incomplete():
                if os.path.exists(
                        filepath) and self.skip_existing_incomplete_example:
                    common.print_verbose(
                        '    - ' + filename +
                        ' \033[01;35m(incomplete, skipped)\033[0m')
                    continue
                else:
                    common.print_verbose('    - ' + filename +
                                         ' \033[01;31m(incomplete)\033[0m')
            else:
                common.print_verbose('    - ' + filename)

            with open(filepath, 'w') as f:
                f.write(example.get_octave_source())