def make_index_html_content(self, latest_url): """ Generate the content for index.html :param latest_url: URL to the report that was uploaded in this run :type latest_url: string :returns: HTML content :rtype: string """ env = Environment( loader=PackageLoader('rebuildbot', 'templates'), extensions=['jinja2.ext.loopcontrols'] ) template = env.get_template('index.html') date_s = datetime.now(pytz.utc).astimezone(tzlocal.get_localzone()) date_s = date_s.strftime('%Y-%m-%d %H:%M:%S%z %Z') existing_reports = self.get_current_reports() run_info = { 'version': _VERSION, 'date_s': date_s, 'host': platform_node(), 'user': getuser(), 'bucket': self.bucket.name, 'prefix': self.s3_prefix, 'dry_run': self.dry_run, } html = template.render(run_info=run_info, latest_url=latest_url, reports=existing_reports) return html
def send_mail(to, subject, html, dry_run=False): """ Send the message :param html: HTML to make up the body of the message :type html: string :param dry_run: whether to actually send, or just print what would be sent :type dry_run: boolean """ if dry_run: with open('output.html', 'w') as fh: fh.write(html) logger.warning( "DRY RUN - not sending mail; wrote body to ./output.html") return True logger.debug("sending mail") msg = MIMEMultipart('alternative') msg['subject'] = subject msg['To'] = ','.join(to) msg['From'] = '{user}@{host}'.format(user=getuser(), host=platform_node()) body = MIMEText(html, 'html') msg.attach(body) # send s = smtplib.SMTP('localhost') s.sendmail(msg['From'], to, msg.as_string()) return True
def _generate_html(self): """ Generate the HTML for the specified graphs. :return: :rtype: """ logger.debug('Generating templated HTML') env = Environment(loader=PackageLoader('pypi_download_stats', 'templates'), extensions=['jinja2.ext.loopcontrols']) env.filters['format_date_long'] = filter_format_date_long env.filters['format_date_ymd'] = filter_format_date_ymd env.filters['data_columns'] = filter_data_columns template = env.get_template('base.html') logger.debug('Rendering template') html = template.render(project=self.project_name, cache_date=self._stats.as_of_datetime, user=getuser(), host=platform_node(), version=VERSION, proj_url=PROJECT_URL, graphs=self._graphs, graph_keys=self.GRAPH_KEYS, resources=Resources(mode='inline').render(), badges=self._badges) logger.debug('Template rendered') return html
def _generate_html(self): """ Generate the HTML for the specified graphs. :return: :rtype: """ logger.debug('Generating templated HTML') env = Environment( loader=PackageLoader('pypi_download_stats', 'templates'), extensions=['jinja2.ext.loopcontrols']) env.filters['format_date_long'] = filter_format_date_long env.filters['format_date_ymd'] = filter_format_date_ymd env.filters['data_columns'] = filter_data_columns template = env.get_template('base.html') logger.debug('Rendering template') html = template.render( project=self.project_name, cache_date=self._stats.as_of_datetime, user=getuser(), host=platform_node(), version=VERSION, proj_url=PROJECT_URL, graphs=self._graphs, graph_keys=self.GRAPH_KEYS, resources=Resources(mode='inline').render(), badges=self._badges ) logger.debug('Template rendered') return html
def send_mail(to, subject, html, dry_run=False): """ Send the message :param html: HTML to make up the body of the message :type html: string :param dry_run: whether to actually send, or just print what would be sent :type dry_run: boolean """ if dry_run: with open('output.html', 'w') as fh: fh.write(html) logger.warning("DRY RUN - not sending mail; wrote body to ./output.html") return True logger.debug("sending mail") msg = MIMEMultipart('alternative') msg['subject'] = subject msg['To'] = ','.join(to) msg['From'] = '{user}@{host}'.format(user=getuser(), host=platform_node()) body = MIMEText(html, 'html') msg.attach(body) # send s = smtplib.SMTP('localhost') s.sendmail(msg['From'], to, msg.as_string()) return True
def format_html(hostname, dates, date_data, start_date, end_date): """ format the HTML report using the raw per-date dicts :param hostname: PuppetDB hostname :type hostname: string :param dates: ordered list of dates to display, left-to-right :type dates: list :param date_data: dict of each date to its data :type date_data: dict :param start_date: beginning of time period that data is for :type start_date: Datetime :param end_date: end of time period that data is for :type end_date: Datetime """ env = Environment(loader=PackageLoader('pypuppetdb_daily_report', 'templates'), extensions=['jinja2.ext.loopcontrols']) env.filters['reportmetricname'] = filter_report_metric_name env.filters['reportmetricformat'] = filter_report_metric_format env.filters['resourcedictsort'] = filter_resource_dict_sort template = env.get_template('base.html') run_info = { 'version': VERSION, 'date_s': datetime.datetime.now(pytz.utc).astimezone( tzlocal.get_localzone()).strftime('%Y-%m-%d %H:%M:%S%z %Z'), 'host': platform_node(), 'user': getuser(), } config = { 'start': start_date, 'end': end_date, 'num_rows': NUM_RESULT_ROWS, } html = template.render( data=date_data, dates=dates, hostname=hostname, config=config, run_info=run_info, ) return html
def format_html(hostname, dates, date_data, start_date, end_date): """ format the HTML report using the raw per-date dicts :param hostname: PuppetDB hostname :type hostname: string :param dates: ordered list of dates to display, left-to-right :type dates: list :param date_data: dict of each date to its data :type date_data: dict :param start_date: beginning of time period that data is for :type start_date: Datetime :param end_date: end of time period that data is for :type end_date: Datetime """ env = Environment(loader=PackageLoader('pypuppetdb_daily_report', 'templates'), extensions=['jinja2.ext.loopcontrols']) env.filters['reportmetricname'] = filter_report_metric_name env.filters['reportmetricformat'] = filter_report_metric_format env.filters['resourcedictsort'] = filter_resource_dict_sort template = env.get_template('base.html') run_info = { 'version': VERSION, 'date_s': datetime.datetime.now(pytz.utc).astimezone(tzlocal.get_localzone()).strftime('%Y-%m-%d %H:%M:%S%z %Z'), 'host': platform_node(), 'user': getuser(), } config = { 'start': start_date, 'end': end_date, 'num_rows': NUM_RESULT_ROWS, } html = template.render(data=date_data, dates=dates, hostname=hostname, config=config, run_info=run_info, ) return html
def add_userdata(self, shasum, data): """Adds userdata to the database shasum""" LOG.debug('add userdata') shasum = unicode(shasum) user = getuser() node = platform_node() user_key = node + ':' + user userdata = {} if not self.file_exists(shasum): LOG.error('trying to add userdata to nonexistent file' + shasum) return None entry = self.database[shasum] userdatalist = {} if 'userdata' in entry: userdatalist = entry['userdata'] if user_key in userdatalist: userdata = userdatalist[user_key] userdata.update(data) userdatalist[user_key] = userdata entry['userdata'] = userdatalist self.database[shasum] = entry
def generate_report(self, prefix, duration, log_url): """ Generate the overall HTML report for this run. :param prefix: the prefix to write S3 files under, or local files under :type prefix: str :param duration: the duration of the entire ReBuildBot run :type duration: :py:class:`datetime.timedelta` :param log_url: the URL to the logging output in S3 :type log_url: str :returns: generated report HTML :rytpe: str """ env = Environment( loader=PackageLoader('rebuildbot', 'templates'), extensions=['jinja2.ext.loopcontrols'] ) template = env.get_template('report.html') date_s = datetime.now(pytz.utc).astimezone(tzlocal.get_localzone()) date_s = date_s.strftime('%Y-%m-%d %H:%M:%S%z %Z') run_info = { 'version': _VERSION, 'date_s': date_s, 'host': platform_node(), 'user': getuser(), 'bucket': self.bucket.name, 'prefix': prefix, 'dry_run': self.dry_run, 'duration': str(duration), 'log_url': log_url, } build_infos = self.get_build_info_html_list() html = template.render(run_info=run_info, builds=build_infos) return html
def main(args=None): unitybuild.utils.msys_control_c_workaround() if sys.platform == 'cygwin': raise UserError("Running under cygwin python is not supported.") args = parse_args(args) if args.push: num = len(args.platforms) * len(args.vrsdks) * len(args.configs) if num != 1: raise UserError('Must specify exactly one build to push') import unitybuild.vcs as vcs vcs = vcs.create() project_dir = find_project_dir() print("Project dir:", os.path.normpath(project_dir)) if args.jenkins: # Jenkins does not allow building outside of the source tree. build_dir = os.path.normpath(os.path.join(project_dir, 'Builds')) else: # Local build setup. build_dir = os.path.normpath(os.path.join(project_dir, '..', 'Builds')) # TODO(pld): maybe faster to call CommandLine() multiple times in the same # Unity rather than to start up Unity multiple times. OTOH it requires faith # in Unity's stability. try: tmp_dir = None try: revision = vcs.get_build_stamp(project_dir) except LookupError as e: print('WARN: no build stamp (%s). Continue?' % (e,)) if not input('(y/n) > ').strip().lower().startswith('y'): raise UserError('Aborting: no stamp') revision = 'nostamp' create_notice_file(project_dir) for (platform, vrsdk, config) in iter_builds(args): stamp = revision + ('-exp' if args.experimental else '') print("Building %s %s %s exp:%d signed:%d il2cpp:%d" % ( platform, vrsdk, config, args.experimental, args.for_distribution, args.il2cpp)) tags = [platform, vrsdk, config] if args.experimental: tags.append('Exp') if args.for_distribution and platform != 'Windows': tags.append('Signed') if args.il2cpp: tags.append('Il2cpp') dirname = '_'.join(tags) tmp_dir = os.path.join(build_dir, 'tmp_' + dirname) output_dir = os.path.join(build_dir, dirname) if args.for_distribution and platform == 'Android' and sys.stdin.isatty(): try: maybe_prompt_and_set_version_code(project_dir) except Exception as e: print('Error prompting for version code: %s' % e) tmp_dir = build(stamp, tmp_dir, project_dir, EXE_BASE_NAME, experimental=args.experimental, platform=platform, il2cpp=args.il2cpp, vrsdk=vrsdk, config=config, for_distribution=args.for_distribution, is_jenkins=args.jenkins) output_dir = finalize_build(project_dir, tmp_dir, output_dir) sanity_check_build(output_dir) if args.for_distribution and platform == 'Android': set_android_version_code(project_dir, 'increment') if args.for_distribution and vrsdk == 'Oculus': # .pdb files violate VRC.PC.Security.3 and ovr-platform-utils rejects the submission to_remove = [] for (r, ds, fs) in os.walk(output_dir): for f in fs: if f.endswith('.pdb'): to_remove.append(os.path.join(r, f)) if to_remove: print('Removing from submission:\n%s' % ('\n'.join( os.path.relpath(f, output_dir) for f in to_remove))) list(map(os.unlink, to_remove)) if platform == 'iOS': # TODO: for iOS, invoke xcode to create ipa. E.g.: # $ cd tmp_dir/TiltBrush # $ xcodebuild -scheme Unity-iPhone archive -archivePath ARCHIVE_DIR # $ xcodebuild -exportArchive -exportFormat ipa -archivePath ARCHIVE_DIR -exportPath IPA print('iOS build must be completed from Xcode (%s)' % ( os.path.join(output_dir, EXE_BASE_NAME, 'Unity-iPhone.xcodeproj'))) continue if args.push: with open(output_dir+'/build_stamp.txt') as inf: embedded_stamp = inf.read().strip() import getpass from platform import node as platform_node # Don't overwrite 'platform' local var! description = '%s %s | %s@%s' % ( config, embedded_stamp, getpass.getuser(), platform_node()) if args.branch is not None: description += ' to %s' % args.branch if vrsdk == 'SteamVR': if platform not in ('Windows',): raise BuildFailed("Unsupported platform for push to Steam: %s" % platform) unitybuild.push.push_tilt_brush_to_steam( output_dir, description, args.user or 'tiltbrush_build', args.branch) elif vrsdk == 'Oculus': if platform not in ('Windows', 'Android'): raise BuildFailed("Unsupported platform for push to Oculus: %s" % platform) release_channel = args.branch if release_channel is None: release_channel = 'ALPHA' print(("No release channel specified for Oculus: using %s" % release_channel)) unitybuild.push.push_tilt_brush_to_oculus(output_dir, release_channel, description) except Error as e: print("\n%s: %s" % ('ERROR', e)) if isinstance(e, BadVersionCode): set_android_version_code(project_dir, e.desired_version_code) print(("\n\nVersion code has been auto-updated to %s.\nPlease retry your build." % e.desired_version_code)) if tmp_dir: print("\nSee %s" % os.path.join(tmp_dir, 'build_log.txt')) sys.exit(1) except KeyboardInterrupt: print("Aborted.") sys.exit(2)
def main( args=None, ): # pylint: disable=too-many-statements,too-many-branches,too-many-locals unitybuild.utils.msys_control_c_workaround() if sys.platform == "cygwin": raise UserError("Running under cygwin python is not supported.") args = parse_args(args) if args.push: num = len(args.platforms) * len(args.vrsdks) * len(args.configs) if num != 1: raise UserError("Must specify exactly one build to push") vcs = vcs_create() project_dir = find_project_dir() print("Project dir:", os.path.normpath(project_dir)) if args.jenkins: # Jenkins does not allow building outside of the source tree. build_dir = os.path.normpath(os.path.join(project_dir, "Builds")) else: # Local build setup. build_dir = os.path.normpath(os.path.join(project_dir, "..", "Builds")) # TODO(pld): maybe faster to call CommandLine() multiple times in the same # Unity rather than to start up Unity multiple times. OTOH it requires faith # in Unity's stability. try: tmp_dir = None try: revision = vcs.get_build_stamp(project_dir) except LookupError as e: print("WARN: no build stamp (%s). Continue?" % (e,)) if not input("(y/n) > ").strip().lower().startswith("y"): raise UserError("Aborting: no stamp") from e revision = "nostamp" create_notice_file(project_dir) for (platform, vrsdk, config) in iter_builds(args): stamp = revision + ("-exp" if args.experimental else "") print( "Building %s %s %s exp:%d signed:%d il2cpp:%d" % ( platform, vrsdk, config, args.experimental, args.for_distribution, args.il2cpp, ) ) sdk = vrsdk if sdk == "Oculus" and platform == "Android": sdk = "OculusMobile" dirname = "%s_%s_%s%s%s%s%s_FromCli" % ( sdk, "Release", EXE_BASE_NAME, "_Experimental" if args.experimental else "", "_Il2cpp" if args.il2cpp else "", "", # GuiAutoProfile "_signed" if args.for_distribution and platform != "Windows" else "", ) tmp_dir = os.path.join(build_dir, "tmp_" + dirname) output_dir = os.path.join(build_dir, dirname) if args.for_distribution and platform == "Android" and sys.stdin.isatty(): try: maybe_prompt_and_set_version_code(project_dir) except Exception as e: # pylint: disable=broad-except print("Error prompting for version code: %s" % e) tmp_dir = build( stamp, tmp_dir, project_dir, EXE_BASE_NAME, experimental=args.experimental, platform=platform, il2cpp=args.il2cpp, vrsdk=vrsdk, config=config, for_distribution=args.for_distribution, is_jenkins=args.jenkins, ) output_dir = finalize_build(tmp_dir, output_dir) sanity_check_build(output_dir) if args.for_distribution and platform == "Android": set_android_version_code(project_dir, "increment") if args.for_distribution and vrsdk == "Oculus": # .pdb files violate VRC.PC.Security.3 and ovr-platform-utils rejects the submission to_remove = [] for (r, _, fs) in os.walk(output_dir): for f in fs: if f.endswith(".pdb"): to_remove.append(os.path.join(r, f)) if to_remove: print( "Removing from submission:\n%s" % ("\n".join(os.path.relpath(f, output_dir) for f in to_remove)) ) list(map(os.unlink, to_remove)) if platform == "iOS": # TODO: for iOS, invoke xcode to create ipa. E.g.: # $ cd tmp_dir/TiltBrush # $ xcodebuild -scheme Unity-iPhone archive -archivePath ARCHIVE_DIR # $ xcodebuild -exportArchive -exportFormat ipa -archivePath ARCHIVE_DIR -exportPath IPA print( "iOS build must be completed from Xcode (%s)" % ( os.path.join( output_dir, EXE_BASE_NAME, "Unity-iPhone.xcodeproj" ) ) ) continue if args.push: with open(os.path.join(output_dir, "build_stamp.txt")) as inf: embedded_stamp = inf.read().strip() description = "%s %s | %s@%s" % ( config, embedded_stamp, getpass.getuser(), platform_node(), ) if args.branch is not None: description += " to %s" % args.branch if vrsdk == "SteamVR": if platform not in ("Windows",): raise BuildFailed( "Unsupported platform for push to Steam: %s" % platform ) unitybuild.push.push_open_brush_to_steam( output_dir, description, args.user or "tiltbrush_build", args.branch, ) elif vrsdk == "Oculus": if platform not in ("Windows", "Android"): raise BuildFailed( "Unsupported platform for push to Oculus: %s" % platform ) release_channel = args.branch if release_channel is None: release_channel = "ALPHA" print( ( "No release channel specified for Oculus: using %s" % release_channel ) ) unitybuild.push.push_open_brush_to_oculus( output_dir, release_channel, description ) except BadVersionCode as e: if isinstance(e, BadVersionCode): set_android_version_code(project_dir, e.desired_version_code) print( ( "\n\nVersion code has been auto-updated to %s.\nPlease retry your build." % e.desired_version_code ) ) if tmp_dir: print("\nSee %s" % os.path.join(tmp_dir, "build_log.txt")) sys.exit(1) except Error as e: print("\n%s: %s" % ("ERROR", e)) if tmp_dir: print("\nSee %s" % os.path.join(tmp_dir, "build_log.txt")) sys.exit(1) except KeyboardInterrupt: print("Aborted.") sys.exit(2)
from platform import node as platform_node from random import randint from os import environ # Constants DEVICE_ID = 0 # The device the camera is, usually 0. TODO make this adjustable FRAME_WIDTH = 1280 FRAME_HEIGHT = 720 # Arguments # These are effectively constant after the argument parser has ran. TAG_SIZE = 6.5 # The length of one side of an apriltag, in inches SEND_DATA = True # Sends data to URL if True. Set to False for debug MAX_LOCATION_HISTORY_LENGTH = 20 MODE_THRESHOLD = 1 BASE_STATION_DEVICE_ID = hash(platform_node() + str(randint(0, 1000000)) + str(randint(0, 1000000)) + str(DEVICE_ID) + str(time.time())) def main(): # DEBUGGING AND TIMING VARIABLES past_time = -1 # time to start counting. Set just before first picture taken num_frames = 0 # number of frames processed args = get_args() url = args["url"] SEND_DATA = args["url"] != None calib_file_name = args["file"] TAG_SIZE = args["size"] calib_file = open(calib_file_name)