def run(self, args): os.environ['PATH'] = "{}:{}".format(os.path.join(self.sdk_path(args), "arm-cs-tools", "bin"), os.environ['PATH']) cmdLine = 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 = cmdLine.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: appInfo = json.load(open("appinfo.json")) self._send_memory_usage(args, appInfo) self._send_resource_usage(args, appInfo) self._send_line_counts(args, appInfo) hasJS = os.path.exists(os.path.join('src', 'js')) PblAnalytics.code_has_java_script_evt(uuid=appInfo["uuid"], hasJS=hasJS) except Exception as e: logging.error("Exception occurred collecting app analytics: " "%s" % str(e)) logging.debug(traceback.format_exc()) return 0
def _send_resource_usage(self, args, appInfo): """ Send app resource usage up to analytics Parameters: -------------------------------------------------------------------- args: the args passed to the run() method appInfo: the applications appInfo """ # Collect the number and total size of each class of resource: resCounts = {"raw": 0, "image": 0, "font": 0} resSizes = {"raw": 0, "image": 0, "font": 0} for resDict in appInfo["resources"]["media"]: if resDict["type"] in ["png", "png-trans"]: type = "image" elif resDict["type"] in ["font"]: type = "font" elif resDict["type"] in ["raw"]: type = "raw" else: raise RuntimeError("Unsupported resource type %s" % (resDict["type"])) # Look for the generated blob in the build/resource directory. # As far as we can tell, the generated blob always starts with # the original filename and adds an extension to it, or (for # fonts), a name and extension. (dirName, fileName) = os.path.split(resDict["file"]) dirToSearch = [os.path.join("build", "resources", dirName)] if type == "raw": dirToSearch.append(os.path.join("resources", dirName)) found = False for dir in dirToSearch: for name in os.listdir(dir): if (type == "raw" and name == fileName) \ or (type != 'raw' and name.startswith(fileName) and name != fileName): size = os.path.getsize(os.path.join(dir, name)) found = True break if not found: raise RuntimeError("Could not find generated resource " "corresponding to %s." % (resDict["file"])) resCounts[type] += 1 resSizes[type] += size # Send the stats now PblAnalytics.res_sizes_evt(uuid=appInfo["uuid"], resCounts = resCounts, resSizes = resSizes)
def _send_resource_usage(self, args, appInfo): """ Send app resource usage up to analytics Parameters: -------------------------------------------------------------------- args: the args passed to the run() method appInfo: the applications appInfo """ # Collect the number and total size of each class of resource: resCounts = {"raw": 0, "image": 0, "font": 0} resSizes = {"raw": 0, "image": 0, "font": 0} for resDict in appInfo["resources"]["media"]: if resDict["type"] in ["png", "png-trans"]: type = "image" elif resDict["type"] in ["font"]: type = "font" elif resDict["type"] in ["raw"]: type = "raw" else: raise RuntimeError("Unsupported resource type %s" % (resDict["type"])) # Look for the generated blob in the build/resource directory. # As far as we can tell, the generated blob always starts with # the original filename and adds an extension to it, or (for # fonts), a name and extension. (dirName, fileName) = os.path.split(resDict["file"]) dirToSearch = os.path.join("build", "resources", dirName) found = False for name in os.listdir(dirToSearch): if (type == "raw" and name == fileName) \ or (type != 'raw' and name.startswith(fileName) and name != fileName): size = os.path.getsize(os.path.join(dirToSearch, name)) found = True break if not found: raise RuntimeError("Could not find generated resource " "corresponding to %s." % (resDict["file"])) resCounts[type] += 1 resSizes[type] += size # Send the stats now PblAnalytics.res_sizes_evt(uuid=appInfo["uuid"], resCounts=resCounts, resSizes=resSizes)
def run(self, args): LibPebbleCommand.run(self, args) if not os.path.exists(args.pbw_path): logging.error("Could not find pbw <{}> for install.".format(args.pbw_path)) return 1 self.pebble.app_log_enable() success = self.pebble.install_app(args.pbw_path, args.launch) # Send the phone OS version to analytics phoneInfoStr = self.pebble.get_phone_info() PblAnalytics.phone_info_evt(phoneInfoStr = phoneInfoStr) if success and args.logs: self.tail(skip_enable_app_log=True)
def _send_line_counts(self, args, appInfo): """ Send app line counts up to analytics Parameters: -------------------------------------------------------------------- args: the args passed to the run() method appInfo: the applications appInfo """ c_line_count = 0 js_line_count = 0 if os.path.exists('src'): c_line_count += self._count_lines('src', ['.h', '.c']) js_line_count += self._count_lines('src', ['.js']) PblAnalytics.code_line_count_evt(uuid=appInfo["uuid"], c_line_count = c_line_count, js_line_count = js_line_count)
def run(self, args): LibPebbleCommand.run(self, args) if not os.path.exists(args.pbw_path): logging.error("Could not find pbw <{}> for install.".format( args.pbw_path)) return 1 self.pebble.app_log_enable() success = self.pebble.install_app(args.pbw_path, args.launch) # Send the phone OS version to analytics phoneInfoStr = self.pebble.get_phone_info() PblAnalytics.phone_info_evt(phoneInfoStr=phoneInfoStr) if success and args.logs: self.tail(skip_enable_app_log=True)
def _send_line_counts(self, args, appInfo): """ Send app line counts up to analytics Parameters: -------------------------------------------------------------------- args: the args passed to the run() method appInfo: the applications appInfo """ c_line_count = 0 js_line_count = 0 if os.path.exists('src'): c_line_count += self._count_lines('src', ['.h', '.c']) js_line_count += self._count_lines('src', ['.js']) PblAnalytics.code_line_count_evt(uuid=appInfo["uuid"], c_line_count=c_line_count, js_line_count=js_line_count)
def _send_memory_usage(self, args, appInfo): """ Send app memory usage to analytics Parameters: -------------------------------------------------------------------- args: the args passed to the run() method appInfo: the applications appInfo """ cmdName = 'arm_none_eabi_size' cmdArgs = [os.path.join("build", "pebble-app.elf")] try: output = sh.arm_none_eabi_size(*cmdArgs) (textSize, dataSize, bssSize) = [int(x) for x in \ output.stdout.splitlines()[1].split()[:3]] sizeDict = {'text': textSize, 'data': dataSize, 'bss': bssSize} PblAnalytics.code_size_evt(uuid=appInfo["uuid"], segSizes=sizeDict) except sh.ErrorReturnCode as e: logging.error("command %s %s failed. stdout: %s, stderr: %s" % (cmdName, ' '.join(cmdArgs), e.stdout, e.stderr)) except sh.CommandNotFound as e: logging.error("The command %s could not be found. Could not " "collect memory usage analytics." % (e.message))
def _send_memory_usage(self, args, appInfo): """ Send app memory usage to analytics Parameters: -------------------------------------------------------------------- args: the args passed to the run() method appInfo: the applications appInfo """ cmdName = 'arm_none_eabi_size' cmdArgs = [os.path.join("build", "pebble-app.elf")] try: output = sh.arm_none_eabi_size(*cmdArgs, _tty_out=False) (textSize, dataSize, bssSize) = [int(x) for x in \ output.stdout.splitlines()[1].split()[:3]] sizeDict = {'text': textSize, 'data': dataSize, 'bss': bssSize} PblAnalytics.code_size_evt(uuid=appInfo["uuid"], segSizes = sizeDict) except sh.ErrorReturnCode as e: logging.error("command %s %s failed. stdout: %s, stderr: %s" % (cmdName, ' '.join(cmdArgs), e.stdout, e.stderr)) except sh.CommandNotFound as e: logging.error("The command %s could not be found. Could not " "collect memory usage analytics." % (e.message))
def run(self, args): os.environ['PATH'] = "{}:{}".format( os.path.join(self.sdk_path(args), "arm-cs-tools", "bin"), os.environ['PATH']) # 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: appInfo = json.load(open("appinfo.json")) self._send_memory_usage(args, appInfo) self._send_resource_usage(args, appInfo) self._send_line_counts(args, appInfo) hasJS = os.path.exists(os.path.join('src', 'js')) PblAnalytics.code_has_java_script_evt(uuid=appInfo["uuid"], hasJS=hasJS) except Exception as e: logging.error("Exception occurred collecting app analytics: " "%s" % str(e)) logging.debug(traceback.format_exc()) return 0
def run(self, args): os.environ['PATH'] = "{}:{}".format( os.path.join(self.sdk_path(args), "arm-cs-tools", "bin"), os.environ['PATH']) # 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])").strip() if py_version != '2': if sh.which('python2') 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: appInfo = json.load(open("appinfo.json")) self._send_memory_usage(args, appInfo) self._send_resource_usage(args, appInfo) self._send_line_counts(args, appInfo) hasJS = os.path.exists(os.path.join('src', 'js')) PblAnalytics.code_has_java_script_evt(uuid=appInfo["uuid"], hasJS=hasJS) except Exception as e: logging.error("Exception occurred collecting app analytics: " "%s" % str(e)) logging.debug(traceback.format_exc()) return 0