Пример #1
0
 def _wait_for_qemu(self):
     logger.info("Waiting for the firmware to boot.")
     for i in range(20):
         time.sleep(0.2)
         try:
             s = socket.create_connection(
                 ('localhost', self.qemu_serial_port))
         except socket.error:
             logger.debug("QEMU not ready yet.")
             pass
         else:
             break
     else:
         post_event("qemu_launched",
                    success=False,
                    reason="qemu_launch_timeout")
         raise ToolError("Emulator launch timed out.")
     received = b''
     while True:
         try:
             received += s.recv(256)
         except socket.error as e:
             # Ignore "Interrupted system call"
             if e.errno != errno.EINTR:
                 raise
         if b"<SDK Home>" in received or b"<Launcher>" in received or b"Ready for communication" in received:
             break
     s.close()
     post_event("qemu_launched", success=True)
     logger.info("Firmware booted.")
Пример #2
0
    def __call__(self, args):
        super(NewProjectCommand, self).__call__(args)

        project_path = args.name
        project_name = os.path.split(project_path)[1]
        sdk2 = self.sdk == "2.9" or (self.sdk is None
                                     and sdk_version() == "2.9")

        template_paths = [
            os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates',
                         'app'),
            os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates'),
            os.path.join(os.path.dirname(__file__), '..', '..', 'sdk',
                         'templates'),
        ]
        file_list = [('gitignore', '.gitignore'),
                     ('simple.c' if args.simple else 'main.c',
                      'src/{}.c'.format(project_name)),
                     ('wscript_sdk2' if sdk2 else 'wscript', 'wscript')]
        if args.javascript:
            file_list.extend([('app.js', 'src/js/app.js'),
                              ('pebble-js-app.js', 'src/js/pebble-js-app.js')])
        if args.worker:
            file_list.append(
                ('worker.c', 'worker/{}_worker.c'.format(project_name)))

        _copy_template(args.name, template_paths,
                       ['package.json', 'appinfo.json'], file_list,
                       ['resources'])

        post_event("sdk_create_project",
                   javascript=args.javascript,
                   worker=args.worker)
        print("Created new project {}".format(args.name))
Пример #3
0
    def __call__(self, args):
        super(NewProjectCommand, self).__call__(args)

        project_path = args.name
        project_name = os.path.split(project_path)[1]
        sdk2 = self.sdk == "2.9" or (self.sdk is None and sdk_version() == "2.9")

        template_paths = [
            os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates', 'app'),
            os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates'),
            os.path.join(os.path.dirname(__file__), '..', '..', 'sdk', 'templates'),
        ]
        file_list = [
            ('gitignore', '.gitignore'),
            ('simple.c' if args.simple else 'main.c', 'src/{}.c'.format(project_name)),
            ('wscript_sdk2' if sdk2 else 'wscript', 'wscript')
        ]
        if args.javascript:
            file_list.extend([('app.js', 'src/js/app.js'), ('pebble-js-app.js', 'src/js/pebble-js-app.js')])
        if args.worker:
            file_list.append(('worker.c', 'worker/{}_worker.c'.format(project_name)))

        _copy_template(args.name, template_paths, ['package.json', 'appinfo.json'], file_list, ['resources'])

        post_event("sdk_create_project", javascript=args.javascript, worker=args.worker)
        print("Created new project {}".format(args.name))
Пример #4
0
    def __call__(self, args):
        super(NewPackageCommand, self).__call__(args)

        package_path = args.name
        package_name = os.path.split(package_path)[1]

        template_paths = [
            os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates',
                         'lib'),
        ]
        file_list = [
            ('gitignore', '.gitignore'),
            ('lib.c', 'src/c/{}.c'.format(package_name)),
            ('lib.h', 'include/{}.h'.format(package_name)),
            'wscript',
        ]
        dir_list = ['src/resources']
        if args.javascript:
            file_list.append(('lib.js', 'src/js/index.js'))

        _copy_template(args.name, template_paths, ['package.json'], file_list,
                       dir_list)

        post_event("sdk_create_package", javascript=args.javascript)
        print("Created new package {}".format(args.name))
Пример #5
0
 def _wait_for_qemu(self):
     logger.info("Waiting for the firmware to boot.")
     for i in range(20):
         time.sleep(0.2)
         try:
             s = socket.create_connection(('localhost', self.qemu_serial_port))
         except socket.error:
             logger.debug("QEMU not ready yet.")
             pass
         else:
             break
     else:
         post_event("qemu_launched", success=False, reason="qemu_launch_timeout")
         raise ToolError("Emulator launch timed out.")
     received = b''
     while True:
         try:
             received += s.recv(256)
         except socket.error as e:
             # Ignore "Interrupted system call"
             if e.errno != errno.EINTR:
                 raise
         # PBL-21275: we'll add less hacky solutions for this to the firmware.
         if b"<SDK Home>" in received or b"<Launcher>" in received:
             break
     s.close()
     post_event("qemu_launched", success=True)
     logger.info("Firmware booted.")
Пример #6
0
    def __call__(self, args):
        super(NewProjectCommand, self).__call__(args)

        # User can give a path to a new project dir
        project_path = args.name
        project_name = os.path.split(project_path)[1]
        project_root = os.path.join(os.getcwd(), project_path)

        project_src = os.path.join(project_root, "src")

        # Create directories
        try:
            os.makedirs(project_root)
            os.makedirs(os.path.join(project_root, "resources"))
            os.makedirs(project_src)
        except OSError as e:
            if e.errno == errno.EEXIST:
                raise ToolError("A directory called '{}' already exists.".format(args.name))
            raise

        # Create main .c file
        with open(os.path.join(project_src, "{}.c".format(project_name)), "w") as f:
            f.write(FILE_SIMPLE_MAIN if args.simple else FILE_DUMMY_MAIN)

        # Add appinfo.json file
        appinfo_dummy = DICT_DUMMY_APPINFO.copy()
        appinfo_dummy['uuid'] = str(uuid.uuid4())
        appinfo_dummy['project_name'] = project_name
        with open(os.path.join(project_root, "appinfo.json"), "w") as f:
            f.write(FILE_DUMMY_APPINFO.substitute(**appinfo_dummy))

        # Add .gitignore file
        with open(os.path.join(project_root, ".gitignore"), "w") as f:
            f.write(FILE_GITIGNORE)

        # Add javascript files if applicable
        if args.javascript:
            project_js_src = os.path.join(project_src, "js")
            os.makedirs(project_js_src)

            with open(os.path.join(project_js_src, "pebble-js-app.js"), "w") as f:
                f.write(FILE_DUMMY_JAVASCRIPT_SRC)

        # Add background worker files if applicable
        if args.worker:
            project_worker_src = os.path.join(project_root, "worker_src")
            os.makedirs(project_worker_src)
            # Add simple source file
            with open(os.path.join(project_worker_src, "{}_worker.c".format(project_name)), "w") as f:
                f.write(FILE_DUMMY_WORKER)

        # Add wscript file
        with open(os.path.join(project_root, "wscript"), "w") as f:
            f.write(FILE_WSCRIPT)

        post_event("sdk_create_project", javascript=args.javascript, worker=args.worker)
        print("Created new project {}".format(args.name))
Пример #7
0
 def __call__(self, args):
     super(SDKProjectCommand, self).__call__(args)
     try:
         self.project = PebbleProject()
     except PebbleProjectException as e:
         event_map = {
             InvalidProjectException: "sdk_run_without_project",
             InvalidJSONException: "sdk_json_error",
             OutdatedProjectException: "sdk_json_error",
         }
         if type(e) in event_map:
             post_event(event_map[type(e)])
         raise
Пример #8
0
 def __call__(self, args):
     super(BuildCommand, self).__call__(args)
     start_time = time.time()
     if len(self.project.dependencies) > 0:
         post_event('app_build_with_npm_deps')
         try:
             npm.invoke_npm(["install"])
             npm.invoke_npm(["dedupe"])
         except subprocess.CalledProcessError:
             post_event("app_build_failed_npm")
             raise BuildError("npm failed.")
     try:
         waf = list(args.args)
         try:
             waf.remove('--')
         except ValueError:
             pass
         extra_env = {}
         if args.debug:
             extra_env = {'CFLAGS': os.environ.get('CFLAGS', '') + ' -O0'}
         self._waf("configure", extra_env=extra_env, args=waf)
         self._waf("build", args=waf)
     except subprocess.CalledProcessError:
         duration = time.time() - start_time
         post_event("app_build_failed", build_time=duration)
         raise BuildError("Build failed.")
     else:
         duration = time.time() - start_time
         has_js = os.path.exists(os.path.join('src', 'js'))
         post_event("app_build_succeeded",
                    has_js=has_js,
                    line_counts=self._get_line_counts(),
                    build_time=duration)
Пример #9
0
 def __call__(self, args):
     super(BuildCommand, self).__call__(args)
     start_time = time.time()
     if len(self.project.dependencies) > 0:
         post_event('app_build_with_npm_deps')
         try:
             npm.invoke_npm(["install"])
             npm.invoke_npm(["dedupe"])
         except subprocess.CalledProcessError:
             post_event("app_build_failed_npm")
             raise BuildError("npm failed.")
     try:
         waf = list(args.args)
         try:
             waf.remove('--')
         except ValueError:
             pass
         extra_env = {}
         if args.debug:
             extra_env = {'CFLAGS': os.environ.get('CFLAGS', '') + ' -O0'}
         self._waf("configure", extra_env=extra_env, args=waf)
         self._waf("build", args=waf)
     except subprocess.CalledProcessError:
         duration = time.time() - start_time
         post_event("app_build_failed", build_time=duration)
         raise BuildError("Build failed.")
     else:
         duration = time.time() - start_time
         has_js = os.path.exists(os.path.join('src', 'js'))
         post_event("app_build_succeeded", has_js=has_js, line_counts=self._get_line_counts(), build_time=duration)
Пример #10
0
    def __call__(self, args):
        super(NewProjectCommand, self).__call__(args)

        template_paths = [
            os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates'),
            os.path.join(os.path.dirname(__file__), '..', '..', 'sdk',
                         'templates')
        ]

        sdk = self.sdk or sdk_version()
        sdk2 = (sdk == "2.9")

        if args.rocky:
            if sdk2:
                raise ToolError("--rocky is not compatible with SDK 2.9")
            if args.simple or args.worker:
                raise ToolError(
                    "--rocky is incompatible with --simple and --worker")
            options = ['rocky']
        else:
            options = ['app']
            if args.javascript:
                options.append('javascript')
            if args.simple:
                options.append('simple')
            if args.worker:
                options.append('worker')

        # Hack for old SDKs that need an appinfo, because the declarative system can't
        # handle "this, but only if not that." For "tintin" SDKs and unparseble
        # versions, assume this hack is not needed.
        version_number = version_to_key(sdk)
        if version_number[:5] != (0, 0, 0, 0, 0) and \
           version_number < (3, 13, 0):
            options.append('appinfo')

        with open(
                extant_path(
                    os.path.join(x, "templates.json")
                    for x in template_paths)) as f:
            template_layout = json.load(f)

        _copy_from_template(template_layout, extant_path(template_paths),
                            args.name, options)

        post_event("sdk_create_project",
                   javascript=args.javascript or args.rocky,
                   worker=args.worker,
                   rocky=args.rocky)
        print("Created new project {}".format(args.name))
Пример #11
0
 def __call__(self, args):
     super(SDKCommand, self).__call__(args)
     self.sdk = args.sdk
     try:
         self.project = PebbleProject()
     except PebbleProjectException as e:
         event_map = {
             InvalidProjectException: "sdk_run_without_project",
             InvalidJSONException: "sdk_json_error",
             OutdatedProjectException: "sdk_json_error",
         }
         if type(e) in event_map:
             post_event(event_map[type(e)])
         raise
     self._fix_python()
     self.add_arm_tools_to_path()
Пример #12
0
    def __call__(self, args):
        super(NewPackageCommand, self).__call__(args)

        template_path = os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates')
        control_path = extant_path([
            os.path.join(template_path, 'templates.json'),
            os.path.join(os.path.dirname(__file__), '..', '..', 'sdk', 'templates', 'templates.json'),
        ])
        with open(control_path) as f:
            template_layout = json.load(f)

        options = ["lib"]
        if args.javascript:
            options.append("javascript")

        _copy_from_template(template_layout, template_path, args.name, options)

        post_event("sdk_create_package", javascript=args.javascript)
        print("Created new package {}".format(args.name))
Пример #13
0
 def __call__(self, args):
     super(BuildCommand, self).__call__(args)
     start_time = time.time()
     try:
         waf = list(args.args)
         try:
             waf.remove('--')
         except ValueError:
             pass
         self._waf("configure")
         self._waf("build", *waf)
     except subprocess.CalledProcessError:
         duration = time.time() - start_time
         post_event("app_build_failed", build_time=duration)
         raise BuildError("Build failed.")
     else:
         duration = time.time() - start_time
         has_js = os.path.exists(os.path.join('src', 'js'))
         post_event("app_build_succeeded", has_js=has_js, line_counts=self._get_line_counts(), build_time=duration)
Пример #14
0
    def __call__(self, args):
        super(NewProjectCommand, self).__call__(args)

        template_paths = [
            os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates'),
            os.path.join(os.path.dirname(__file__), '..', '..', 'sdk', 'templates')
        ]

        sdk = self.sdk or sdk_version()
        sdk2 = (sdk == "2.9")

        if args.rocky:
            if sdk2:
                raise ToolError("--rocky is not compatible with SDK 2.9")
            if args.simple or args.worker:
                raise ToolError("--rocky is incompatible with --simple and --worker")
            options = ['rocky']
        else:
            options = ['app']
            if args.javascript:
                options.append('javascript')
            if args.simple:
                options.append('simple')
            if args.worker:
                options.append('worker')

        # Hack for old SDKs that need an appinfo, because the declarative system can't
        # handle "this, but only if not that." For "tintin" SDKs and unparseble
        # versions, assume this hack is not needed.
        version_number = version_to_key(sdk)
        if version_number[:5] != (0, 0, 0, 0, 0) and \
           version_number < (3, 13, 0):
            options.append('appinfo')

        with open(extant_path(os.path.join(x, "templates.json") for x in template_paths)) as f:
            template_layout = json.load(f)

        _copy_from_template(template_layout, extant_path(template_paths), args.name, options)

        post_event("sdk_create_project", javascript=args.javascript or args.rocky, worker=args.worker, rocky=args.rocky)
        print("Created new project {}".format(args.name))
Пример #15
0
    def __call__(self, args):
        super(NewPackageCommand, self).__call__(args)

        template_path = os.path.join(self.get_sdk_path(), 'pebble', 'common',
                                     'templates')
        control_path = extant_path([
            os.path.join(template_path, 'templates.json'),
            os.path.join(os.path.dirname(__file__), '..', '..', 'sdk',
                         'templates', 'templates.json'),
        ])
        with open(control_path) as f:
            template_layout = json.load(f)

        options = ["lib"]
        if args.javascript:
            options.append("javascript")

        _copy_from_template(template_layout, template_path, args.name, options)

        post_event("sdk_create_package", javascript=args.javascript)
        print("Created new package {}".format(args.name))
Пример #16
0
 def __call__(self, args):
     super(BuildCommand, self).__call__(args)
     start_time = time.time()
     try:
         waf = list(args.args)
         try:
             waf.remove('--')
         except ValueError:
             pass
         self._waf("configure")
         self._waf("build", *waf)
     except subprocess.CalledProcessError:
         duration = time.time() - start_time
         post_event("app_build_failed", build_time=duration)
         raise BuildError("Build failed.")
     else:
         duration = time.time() - start_time
         has_js = os.path.exists(os.path.join('src', 'js'))
         post_event("app_build_succeeded",
                    has_js=has_js,
                    line_counts=self._get_line_counts(),
                    build_time=duration)
Пример #17
0
    def __call__(self, args):
        super(NewPackageCommand, self).__call__(args)

        package_path = args.name
        package_name = os.path.split(package_path)[1]

        template_paths = [
            os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates', 'lib'),
        ]
        file_list = [
            ('gitignore', '.gitignore'),
            ('lib.c', 'src/c/{}.c'.format(package_name)),
            ('lib.h', 'include/{}.h'.format(package_name)),
            'wscript',
        ]
        dir_list = ['src/resources']
        if args.javascript:
            file_list.append(('lib.js', 'src/js/index.js'))

        _copy_template(args.name, template_paths, ['package.json'], file_list, dir_list)

        post_event("sdk_create_package", javascript=args.javascript)
        print("Created new package {}".format(args.name))
Пример #18
0
 def __call__(self, args):
     self._set_debugging(args.v)
     post_event("invoke_command_{}".format(self.command))
Пример #19
0
 def __call__(self, args):
     self._set_debugging(args.v)
     post_event("invoke_command_{}".format(self.command))
Пример #20
0
    def __call__(self, args):
        super(NewProjectCommand, self).__call__(args)

        # User can give a path to a new project dir
        project_path = args.name
        project_name = os.path.split(project_path)[1]
        project_root = os.path.join(os.getcwd(), project_path)

        project_src = os.path.join(project_root, "src")

        # Create directories
        try:
            os.makedirs(project_root)
            os.makedirs(os.path.join(project_root, "resources"))
            os.makedirs(project_src)
        except OSError as e:
            if e.errno == errno.EEXIST:
                raise ToolError(
                    "A directory called '{}' already exists.".format(
                        args.name))
            raise

        project_template_path = os.path.join(self.get_sdk_path(), 'pebble',
                                             'common', 'templates')
        if not os.path.exists(project_template_path):
            project_template_path = os.path.join(os.path.dirname(__file__),
                                                 '..', '..', 'sdk',
                                                 'templates')

        # Create main .c file
        if args.simple:
            default_main = os.path.join(project_template_path, 'simple.c')
        else:
            default_main = os.path.join(project_template_path, 'main.c')
        copy2(default_main,
              os.path.join(project_src, "{}.c".format(project_name)))

        # Add appinfo.json file
        with open(os.path.join(project_template_path, 'appinfo.json')) as f:
            appinfo = Template(f.read())

        with open(os.path.join(project_root, "appinfo.json"), "w") as f:
            f.write(
                appinfo.substitute(uuid=str(uuid4()),
                                   project_name=project_name,
                                   sdk_version=SDK_VERSION))

        # Add .gitignore file
        copy2(os.path.join(project_template_path, 'gitignore'),
              os.path.join(project_root, '.gitignore'))

        # Add javascript files if applicable
        if args.javascript:
            project_js_src = os.path.join(project_src, "js")
            os.makedirs(project_js_src)

            try:
                copy2(os.path.join(project_template_path, 'app.js'),
                      os.path.join(project_js_src, 'app.js'))
            except IOError as e:
                if e.errno != errno.ENOENT:
                    raise e
                copy2(os.path.join(project_template_path, 'pebble-js-app.js'),
                      os.path.join(project_js_src, 'pebble-js-app.js'))

        # Add background worker files if applicable
        if args.worker:
            project_worker_src = os.path.join(project_root, "worker_src")
            os.makedirs(project_worker_src)
            # Add simple source file
            copy2(
                os.path.join(project_template_path, 'worker.c'),
                os.path.join(project_worker_src,
                             "{}_worker.c".format(project_name)))

        # Add wscript file
        if self.sdk == "2.9" or (self.sdk is None and sdk_version() == "2.9"):
            copy2(os.path.join(project_template_path, 'wscript_sdk2'),
                  os.path.join(project_root, "wscript"))
        else:
            copy2(os.path.join(project_template_path, 'wscript'),
                  os.path.join(project_root, "wscript"))

        post_event("sdk_create_project",
                   javascript=args.javascript,
                   worker=args.worker)
        print("Created new project {}".format(args.name))
Пример #21
0
    def __call__(self, args):
        super(NewProjectCommand, self).__call__(args)

        # User can give a path to a new project dir
        project_path = args.name
        project_name = os.path.split(project_path)[1]
        project_root = os.path.join(os.getcwd(), project_path)

        project_src = os.path.join(project_root, "src")

        # Create directories
        try:
            os.makedirs(project_root)
            os.makedirs(os.path.join(project_root, "resources"))
            os.makedirs(project_src)
        except OSError as e:
            if e.errno == errno.EEXIST:
                raise ToolError("A directory called '{}' already exists.".format(args.name))
            raise

        project_template_path = os.path.join(self.get_sdk_path(), 'pebble', 'common', 'templates')
        if not os.path.exists(project_template_path):
            project_template_path = os.path.join(os.path.dirname(__file__), '..', '..', 'sdk', 'templates')

        # Create main .c file
        if args.simple:
            default_main = os.path.join(project_template_path, 'simple.c')
        else:
            default_main = os.path.join(project_template_path, 'main.c')
        copy2(default_main, os.path.join(project_src, "{}.c".format(project_name)))

        # Add appinfo.json file
        with open(os.path.join(project_template_path, 'appinfo.json')) as f:
            appinfo = Template(f.read())

        with open(os.path.join(project_root, "appinfo.json"), "w") as f:
            f.write(appinfo.substitute(uuid=str(uuid4()), project_name=project_name, sdk_version=SDK_VERSION))

        # Add .gitignore file
        copy2(os.path.join(project_template_path, 'gitignore'), os.path.join(project_root, '.gitignore'))

        # Add javascript files if applicable
        if args.javascript:
            project_js_src = os.path.join(project_src, "js")
            os.makedirs(project_js_src)

            try:
                copy2(os.path.join(project_template_path, 'app.js'),
                      os.path.join(project_js_src, 'app.js'))
            except IOError as e:
                if e.errno != errno.ENOENT:
                    raise e
                copy2(os.path.join(project_template_path, 'pebble-js-app.js'),
                      os.path.join(project_js_src, 'pebble-js-app.js'))

        # Add background worker files if applicable
        if args.worker:
            project_worker_src = os.path.join(project_root, "worker_src")
            os.makedirs(project_worker_src)
            # Add simple source file
            copy2(os.path.join(project_template_path, 'worker.c'),
                  os.path.join(project_worker_src, "{}_worker.c".format(project_name)))

        # Add wscript file
        if self.sdk == "2.9" or (self.sdk is None and sdk_version() == "2.9"):
            copy2(os.path.join(project_template_path, 'wscript_sdk2'), os.path.join(project_root, "wscript"))
        else:
            copy2(os.path.join(project_template_path, 'wscript'), os.path.join(project_root, "wscript"))

        post_event("sdk_create_project", javascript=args.javascript, worker=args.worker)
        print("Created new project {}".format(args.name))