예제 #1
0
    def run(self, args):
        print "Creating new project {}".format(args.name)

        # 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
        os.makedirs(project_root)
        os.makedirs(os.path.join(project_root, "resources"))
        os.makedirs(project_src)

        # Create main .c file
        with open(os.path.join(project_src, "%s.c" % (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,
                                 "%s_worker.c" % (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)
    def run(self, args):
        print "Creating new project {}".format(args.name)

        # 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
        os.makedirs(project_root)
        os.makedirs(os.path.join(project_root, "resources"))
        os.makedirs(project_src)

        # Create main .c file
        with open(os.path.join(project_src, "%s.c" % (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, "%s_worker.c" % (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)
    def run(self, args):
        LibPebbleCommand.run(self, args)

        if not os.path.exists(args.bundle_path):
            logging.error("Could not find bundle <{}> for install.".format(args.bundle_path))
            return 1

        if args.logs:
            post_event("app_log_view", virtual=self.virtual_pebble)
            self.pebble.app_log_enable()

        if args.bundle_path.lower().endswith(".pbw"):
            success = self.pebble.install_app(args.bundle_path, direct=args.direct)
        elif args.bundle_path.lower().endswith(".pbz"):
            success = self.pebble.install_firmware(args.bundle_path)
        else:
            logging.error("You must specify either a .pbw or .pbz to install")
            return 1

        if self.pebble.is_phone_info_available():
            # Send the phone OS version to analytics
            phone_info = self.pebble.get_phone_info()
        else:
            phone_info = None

        if success:
            post_event("app_install_succeeded", virtual=self.virtual_pebble, phone_info=phone_info)
        else:
            post_event("app_install_failed", virtual=self.virtual_pebble, phone_info=phone_info)

        if success and args.logs:
            self.tail(skip_enable_app_log=True)
예제 #4
0
    def run(self, args):
        LibPebbleCommand.run(self, args)

        if not os.path.exists(args.bundle_path):
            logging.error("Could not find bundle <{}> for install.".format(
                args.bundle_path))
            return 1

        if args.logs:
            post_event("app_log_view", virtual=self.virtual_pebble)
            self.pebble.app_log_enable()

        if args.bundle_path.lower().endswith(".pbw"):
            success = self.pebble.install_app(args.bundle_path,
                                              direct=args.direct)
        elif args.bundle_path.lower().endswith(".pbz"):
            success = self.pebble.install_firmware(args.bundle_path)
        else:
            logging.error("You must specify either a .pbw or .pbz to install")
            return 1

        if self.pebble.is_phone_info_available():
            # Send the phone OS version to analytics
            phone_info = self.pebble.get_phone_info()
        else:
            phone_info = None

        if success:
            post_event("app_install_succeeded",
                       virtual=self.virtual_pebble,
                       phone_info=phone_info)
        else:
            post_event("app_install_failed",
                       virtual=self.virtual_pebble,
                       phone_info=phone_info)

        if success and args.logs:
            self.tail(skip_enable_app_log=True)
예제 #5
0
    def run(self, args):
        self.add_arm_tools_to_path(args)

        # If python3 is the default and python2 is available, then plug in
        #  our stub 'python' shell script which passes control to python2
        py_version = sh.python("-c",
                               "import sys;print(sys.version_info[0])",
                               _tty_out=False).strip()
        if py_version != '2':
            if sh.which('python2', _tty_out=False) is None:
                raise RuntimeError(
                    "The Pebble SDK requires python version 2.6 "
                    "or 2.7 (python2). You are currently running 'python%s' "
                    "by default and a 'python2' executable could not be found."
                    % py_version)
            os.environ['PATH'] = "{}:{}".format(
                os.path.join(os.path.normpath(os.path.dirname(__file__))),
                os.environ['PATH'])

        # Execute the build command
        cmdLine = '"%s" %s' % (self.waf_path(args), self.waf_cmds)
        retval = subprocess.call(cmdLine, shell=True)

        # If an error occurred, we need to do some sleuthing to determine a
        # cause. This allows the caller to post more useful information to
        # analytics. We normally don't capture stdout and stderr using Poepn()
        # because you lose the nice color coding produced when the command
        # outputs to a terminal directly.
        #
        # But, if an error occurs, let's run it again capturing the output
        #  so we can determine the cause
        if (retval):
            cmdArgs = [self.waf_path(args)] + self.waf_cmds.split()
            try:
                cmdObj = create_sh_cmd_obj(cmdArgs[0])
                output = cmdObj(*cmdArgs[1:])
                stderr = output.stderr
            except sh.ErrorReturnCode as e:
                stderr = e.stderr

            # Look for common problems
            if "Could not determine the compiler version" in stderr:
                raise NoCompilerException

            elif "region `APP' overflowed" in stderr:
                raise AppTooBigException

            else:
                raise BuildErrorException

        elif args.command == 'build':
            # No error building. Send up app memory usage and resource usage
            #  up to analytics
            # Read in the appinfo.json to get the list of resources
            try:
                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())
            except Exception as e:
                logging.error("Exception occurred collecting app analytics: "
                              "%s" % str(e))
                logging.debug(traceback.format_exc())

        return 0
예제 #6
0
 def run(self, args):
     self.add_arm_tools_to_path(args)
     
     # If python3 is the default and python2 is available, then plug in
     #  our stub 'python' shell script which passes control to python2
     py_version = sh.python("-c", 
                            "import sys;print(sys.version_info[0])",
                            _tty_out=False).strip()
     if py_version != '2':
         if sh.which('python2', _tty_out=False) is None:
             raise RuntimeError("The Pebble SDK requires python version 2.6 "
                 "or 2.7 (python2). You are currently running 'python%s' "
                 "by default and a 'python2' executable could not be found." % 
                 py_version)
         os.environ['PATH'] = "{}:{}".format(
             os.path.join(os.path.normpath(os.path.dirname(__file__))),
             os.environ['PATH'])
         
     # Execute the build command
     cmdLine = '"%s" %s' % (self.waf_path(args), self.waf_cmds)
     retval = subprocess.call(cmdLine, shell=True)
     
     # If an error occurred, we need to do some sleuthing to determine a
     # cause. This allows the caller to post more useful information to
     # analytics. We normally don't capture stdout and stderr using Poepn()
     # because you lose the nice color coding produced when the command
     # outputs to a terminal directly.
     #
     # But, if an error occurs, let's run it again capturing the output
     #  so we can determine the cause
     if (retval):
         cmdArgs = [self.waf_path(args)] + self.waf_cmds.split()
         try:
             cmdObj = create_sh_cmd_obj(cmdArgs[0])
             output = cmdObj(*cmdArgs[1:])
             stderr = output.stderr
         except sh.ErrorReturnCode as e:
             stderr = e.stderr        
              
         # Look for common problems
         if "Could not determine the compiler version" in stderr:
             raise NoCompilerException
         
         elif "region `APP' overflowed" in stderr:
             raise AppTooBigException
         
         else:
             raise BuildErrorException
         
     elif args.command == 'build':
         # No error building. Send up app memory usage and resource usage
         #  up to analytics
         # Read in the appinfo.json to get the list of resources
         try:
             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())
         except Exception as e:
             logging.error("Exception occurred collecting app analytics: "
                           "%s" % str(e))
             logging.debug(traceback.format_exc())
         
     return 0