def uninstall_standalone_rtc_from_package(self, package, rtc, verbose=False): rtcs = [] cmds = setting = package.setting.get("standalone", []) uninstall_cmd = None for cmd in cmds: if self.__get_rtc_name_from_standalone_command(package, cmd) == rtc.rtcprofile.basicInfo.name: if verbose: sys.stdout.write( "## Uninstalling RTC (%s) from package (--standalone mode)\n" % rtc.rtcprofile.basicInfo.name ) uninstall_cmd = cmd backup_dir = os.path.join(package.path, "backup") if not os.path.isdir(backup_dir): os.mkdir(backup_dir) pass setting_filename = os.path.join(package.path, "setting.yaml") backup_filename = os.path.join(backup_dir, "setting.yaml" + wasanbon.timestampstr()) shutil.copy(setting_filename, backup_filename) import yaml dic = yaml.load(open(backup_filename, "r")) cmd_list = [cmd for cmd in dic["application"].get("standalone", []) if cmd != uninstall_cmd] if len(cmd_list) == 0 and "standalone" in dic["application"].keys(): del dic["application"]["standalone"] open(setting_filename, "w").write(yaml.dump(dic, default_flow_style=False)) return 0
def uninstall_standalone_rtc_from_package(self, package, rtc, verbose=False): rtcs = [] cmds = setting = package.setting.get('standalone', []) uninstall_cmd = None for cmd in cmds: if self.__get_rtc_name_from_standalone_command( package, cmd) == rtc.rtcprofile.basicInfo.name: if verbose: sys.stdout.write( '## Uninstalling RTC (%s) from package (--standalone mode)\n' % rtc.rtcprofile.basicInfo.name) uninstall_cmd = cmd backup_dir = os.path.join(package.path, 'backup') if not os.path.isdir(backup_dir): os.mkdir(backup_dir) pass setting_filename = os.path.join(package.path, 'setting.yaml') backup_filename = os.path.join( backup_dir, 'setting.yaml' + wasanbon.timestampstr()) shutil.copy(setting_filename, backup_filename) import yaml dic = yaml.load(open(backup_filename, 'r')) cmd_list = [ cmd for cmd in dic['application'].get('standalone', []) if cmd != uninstall_cmd ] if len(cmd_list) == 0 and 'standalone' in dic['application'].keys(): del dic['application']['standalone'] open(setting_filename, 'w').write(yaml.dump(dic, default_flow_style=False)) return 0
def delete(self, args): self.parser.add_option( '-f', '--force', help='Force Delete without yes/no option (default=False)', default=False, dest='force_flag', action='store_true') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag force = options.force_flag package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) systemfile = argv[3] systemfile_relpath = os.path.join( package.get_systempath(fullpath=False), systemfile) systemfile_fullpath = os.path.join(package.get_systempath(), systemfile) if not os.path.isfile(systemfile_fullpath): sys.stdout.write('## No System File exists.\n') return -1 if not force: from wasanbon import util if util.no_yes('# Delete? (%s):' % systemfile_relpath) == 'no': sys.stdout.write('## Aborted.\n') return 0 newfile = systemfile_fullpath + wasanbon.timestampstr() os.rename(systemfile_fullpath, newfile) sys.stdout.write('## Success\n') return 0
def copy(self, args): self.parser.add_option('-f', '--force', help='Force Delete without yes/no option (default=False)', default=False, dest='force_flag', action='store_true') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag force = options.force_flag package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) wasanbon.arg_check(argv, 5) srcfile = argv[3] dstfile = argv[4] srcfile_relpath = os.path.join(package.get_systempath(fullpath=False), srcfile) srcfile_fullpath = os.path.join(package.get_systempath(), srcfile) if not os.path.isfile(srcfile_fullpath): sys.stdout.write('## No System File exists.\n') return -1 dstfile_fullpath = os.path.join(package.get_systempath(), dstfile) if os.path.isfile(dstfile_fullpath): if not force: from wasanbon import util if util.no_yes('# Overwrite? (%s):' % systemfile_relpath) == 'no': sys.stdout.write('## Aborted.\n') return 0 newfile = dstfile_fullpath + wasanbon.timestampstr() os.rename(dstfile_fullpath, newfile) import shutil shutil.copyfile(srcfile_fullpath, dstfile_fullpath) sys.stdout.write('## Success\n') return 0
def sync(self, args): """ Sync RTC local repository to local package repository record """ options, argv = self.parse_args(args[:]) verbose = options.verbose_flag package = admin.package.get_package_from_path(os.getcwd()) file = package.rtc_repository_file import yaml repo_dict = yaml.load(open(file, 'r')) repos = admin.repository.get_rtc_repositories_from_package( package, verbose=verbose) for repo in repos: rtc = admin.rtc.get_rtc_from_package(package, repo.name) hashcode = admin.repository.get_repository_hash(repo) repo_dict[repo.name][ 'description'] = rtc.rtcprofile.basicInfo.description repo_dict[repo.name]['type'] = repo.type repo_dict[repo.name]['url'] = repo.url repo_dict[repo.name]['hash'] = hashcode if repo.type in repo_dict[repo.name].keys(): del (repo_dict[repo.name][repo.type]) os.rename(file, file + wasanbon.timestampstr()) yaml.dump(repo_dict, open(file, 'w'), encoding='utf8', allow_unicode=True, default_flow_style=False) return 0
def cat(self, args): self.parser.add_option('-f', '--file', help='RTCProfile filename (default="RTC.xml")', default='RTC.xml', dest='filename', action='store', type='string') self.parser.add_option('-i', '--inputfile', help='Input from RTCProfile filename (default=None)', default=None, dest='inputfile', action='store', type='string') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag filename = options.filename inputfile = options.inputfile if inputfile: sys.stdout.write('## Input File is %s\n' % inputfile) wasanbon.arg_check(argv, 4) else: wasanbon.arg_check(argv, 5) rtc_name = argv[3] package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) filepath = os.path.join(rtc.path, filename) if os.path.isfile(filepath): file = filepath + wasanbon.timestampstr() os.rename(filepath, file) if inputfile: inputData = open(inputfile, 'r').read() else: inputData = argv[4] fout = open(filepath, 'w') fout.write(inputData) fout.close() sys.stdout.write('Success\n') return 0
def cat(self, args): self.parser.add_option( '-f', '--file', help= 'Build System with Specific RTSProfile (must be placed in system_dir', default=None, dest='systemfile', action='store', type='string') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag systemfile = options.systemfile package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) if systemfile is None: systemfile = package.default_system_filepath else: systemfile = os.path.join(package.get_systempath(), systemfile) if os.path.isfile(systemfile): newfile = systemfile + wasanbon.timestampstr() os.rename(systemfile, newfile) fout = open(systemfile, 'w') fout.write(argv[3]) fout.close() sys.stdout.write('Success\n') return 0
def sync(self, args): """ Synchronize rtc/repository.yaml file and each rtc repository version hash. """ options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag sys.stdout.write('# Writing repository.yaml for package distribution\n') sys.stdout.write('## Parsing RTC directory\n') package = admin.package.get_package_from_path(os.getcwd()) repos = [] for rtc in admin.rtc.get_rtcs_from_package(package, verbose=verbose): sys.stdout.write('### RTC %s\n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_path(rtc.path, description=rtc.rtcprofile.basicInfo.description) repos.append(repo) repo_file = os.path.join(package.get_rtcpath(), 'repository.yaml') bak_file = repo_file + wasanbon.timestampstr() if os.path.isfile(bak_file): os.remove(bak_file) import shutil, yaml shutil.copy(repo_file, bak_file) dic = yaml.load(open(bak_file, 'r')) if not dic: dic = {} for repo in repos: if getattr(repo, 'url') != None: url = repo.url.strip() else: url = '' dic[repo.name] = {'repo_name' : repo.name, 'git': url, 'description':repo.description, 'hash':repo.hash} yaml.dump(dic, open(repo_file, 'w'), encoding='utf8', allow_unicode=True, default_flow_style=False) pass
def add_version(appname, version, target=None, filename=None, description=""): if not target: target = os.path.join(wasanbon.get_wasanbon_home(), 'web') if not os.path.isdir(target): os.mkdir(target) if not filename: target_file = os.path.join(target, _list_page) else: target_file = os.path.join(target, filename) target_file_backup = target_file + wasanbon.timestampstr() dic = {} root = etree.fromstring(open(target_file, 'r').read()) body = root.find('body') listtop = body.find('ul') app_item = None for item in listtop.findall('li'): appname_ = item.text.strip() if appname_ == appname: app_item = item break if app_item is None: app_item = etree.Element('li') app_item.text = appname app_version_listtop = etree.Element('ul') app_item.extend([app_version_listtop]) listtop.extend([app_item]) app_version_listtop = app_item.find('ul') for version_item in app_version_listtop.findall('li'): a_item = version_item.find('a') version_text = a_item.text.strip() url = a_item.get('href').strip() if version_text == version: sys.stdout.write('App (%s) Version(%s) is already registered.\n' % (appname, version)) return pass # Can not find version. OKay version_item = etree.Element('li') filename = appname + '-' + version + '.zip' a_item = etree.Element('a', href=filename) a_item.text = version d_item = etree.Element('span') d_item.text = description version_item.extend([a_item, d_item]) app_version_listtop.extend([version_item]) found = True os.rename(target_file, target_file_backup) xmlstr = etree.tostring(root) open(target_file, 'w').write(xmlstr)
def update_profile(self, args): """ Run just one RTC and compare the profile between the existing RTC.xml and launched RTC, then save RTC.xml """ self.parser.add_option('-f', '--file', help='RTCProfile filename (default="RTC.xml")', default='RTC.xml', dest='filename', action='store', type='string') self.parser.add_option('-d', '--dryrun', help='Just output on console', default=False, dest='dry_flag', action='store_true') self.parser.add_option('-w', '--wakeuptimeout', help='Timeout of Sleep Function when waiting for the wakeup of RTC-Daemons', default=5, dest='wakeuptimeout', action='store', type='float') options, argv = self.parse_args(args[:], self._print_rtcs) verbose = options.verbose_flag dry = options.dry_flag filename = options.filename wakeuptimeout = options.wakeuptimeout wasanbon.arg_check(argv, 4) rtc_name = argv[3] package = admin.package.get_package_from_path(os.getcwd()) sys.stdout.write('# Starting RTC.\n') rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) standalone = admin.systeminstaller.is_installed(package, rtc, standalone=True, verbose=verbose) if standalone: admin.systemlauncher.launch_standalone_rtc(package, rtc, stdout=True, verbose=verbose) pass else: if self.run_rtc_in_package(package, rtc, verbose=verbose, background=True) != 0: return -1 wasanbon.sleep(wakeuptimeout) sys.stdout.write('# Acquiring RTCProfile from Inactive RTC\n') rtcp = admin.rtcprofile.create_rtcprofile(rtc, verbose=verbose) if standalone: pass else: self.terminate_rtcd(package, verbose=verbose) sys.stdout.write('# Comparing Acquired RTCProfile and Existing RTCProfile.\n') retval = admin.rtcprofile.compare_rtcprofile(rtc.rtcprofile, rtcp, verbose=verbose) if retval: filepath = os.path.join(rtc.path, filename) if not dry: outstr = admin.rtcprofile.tostring(retval, pretty_print=True) if outstr == None: sys.stdout.write('# RTC Profile save failed.\n') return -1 if os.path.isfile(filepath): f = filepath + wasanbon.timestampstr() os.rename(filepath, f) pass fout = open(filepath, 'w') fout.write(outstr) fout.close() else: sys.stdout.write(admin.rtcprofile.tostring(retval, pretty_print=True)) sys.stdout.write('Succeed.\n') return 0 sys.stdout.write('Succeed.\n') return 0
def sendCode(code): code_dir = 'codes' if not os.path.isdir(code_dir): os.mkdir(code_dir) codeName = 'code' + wasanbon.timestampstr() + '.py' fileName = os.path.join(code_dir, codeName) f = open(fileName, 'w') f.write(code) f.close() return fileName
def __call__(self, argv): """ Manifesting __call__ function is available but not recommended """ print '# Starting Testing Sequence' if os.path.isfile(filepath): os.rename(filepath, filepath + wasanbon.timestampstr()) pass open(filepath, 'w').close() cons = open('console_output.txt', 'w') sys.stdout = cons self.test(admin, 'environment', 'init', '-v') self.test(admin, 'binder', 'list', '-v') self.test(admin, 'binder', 'packages', '-v') self.test(admin, 'binder', 'rtcs', '-v') self.test(admin, 'package', 'list', '-v') self.test(admin, 'package', 'create', pkg_name, '-v') self.test(admin, 'package', 'directory', pkg_name, '-v') curdir = os.getcwd() os.chdir(os.path.join(os.getcwd(), pkg_name)) self.test(mgr, 'rtc', 'list', '-v') os.chdir(curdir) self.test(admin, 'package', 'delete', pkg_name, '-r', '-v') #repo_names = ['test_project01'] repo_names = ['test_project01', 'test_project02', 'test_project03'] for repo_name in repo_names: self.test(admin, 'repository', 'clone', repo_name, '-v') os.chdir(os.path.join(curdir, repo_name)) self.test(mgr, 'rtc', 'list', '-v') self.test(mgr, 'rtc', 'build', 'all', '-v') timeout = 3.0 self.test(mgr, 'system', 'run', '-v', '-b', '-w', str(timeout)) time.sleep(timeout*1.5) self.test(mgr, 'system', 'terminate', '-v') if not os.path.isfile('testout.txt'): log("testout.txt not found.") else: with open("testout.txt", "r") as f: val = int(f.read().strip()) log("testout.txt == %d" % val) self.test(mgr, 'rtc', 'clean', 'all', '-v') os.chdir(curdir) self.test(admin, 'package', 'delete', repo_name, '-v', '-r')
def add_rtc(self, argv): """ Add RTC information to binder $ mgr.py binder add_rtc $BINDER_NAME $RTC_NAME """ self.parser.add_option('-f', '--force', help='Force option (default=False)', default=False, action='store_true', dest='force_flag') options, argv = self.parse_args(argv[:], self._print_alternatives) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 5) binder_name = argv[3] rtc_name = argv[4] sys.stdout.write('# Information of RTC (%s) will be added to %s binder\n' % (rtc_name, binder_name)) binder = admin.binder.get_binder(binder_name, verbose=verbose) package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) global filename filename= None rtcs = [rtc_.name for rtc_ in binder.rtcs] if rtc_name in rtcs: sys.stdout.write('# This binder have the same RTC information.\n') else: if filename is None: def choice_command(ans): global filename filename = os.path.join(binder.rtcs_path, binder.rtc_files[ans]) return -1 util.choice(binder.rtc_files, choice_command, 'Select RTC repository file') else: if not filename in binder.rtcs_files: sys.stdout.write('# File %s is not found.\n' % filenmae) filename = os.path.join(binder.rtcs_path, filename) return -1 print filename text = open(filename, 'r').read() #os.rename(filename, filename + wasanbon.timestampstr()) #import yaml #repo_dic = yaml.load(open(filename, 'w')) text = text + """ %s : description : "%s" type : git url : '%s' platform : [%s] """ % (repo.name, rtc.rtcprofile.basicInfo.doc.description, repo.url.strip(), wasanbon.platform()) print text os.rename(filename, filename + wasanbon.timestampstr()) open(filename, 'w').write(text) return 0
def filter_func(ans): file = filenames[ans] import yaml dict = yaml.load(open(package.setting_file_path, 'r')) setting_file_path = package.setting_file_path archive_path = os.path.join(package.path, 'backup') if not os.path.isdir(archive_path): os.mkdir(archive_path) archived_file_path = os.path.join(archive_path, 'setting.yaml' + wasanbon.timestampstr()) os.rename(setting_file_path, archived_file_path) dict['application']['system'] = file open(setting_file_path, 'w').write(yaml.dump(dict, encoding='utf8', allow_unicode=True, default_flow_style=False)) return False
def cat(self, args): self.parser.add_option('-f', '--file', help='RTCProfile filename (default="RTC.xml")', default='RTC.xml', dest='filename', action='store', type='string') self.parser.add_option( '-i', '--inputfile', help='Input from RTCProfile filename (default=None)', default=None, dest='inputfile', action='store', type='string') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag filename = options.filename inputfile = options.inputfile if inputfile: sys.stdout.write('## Input File is %s\n' % inputfile) wasanbon.arg_check(argv, 4) else: wasanbon.arg_check(argv, 5) rtc_name = argv[3] package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) filepath = os.path.join(rtc.path, filename) if os.path.isfile(filepath): file = filepath + wasanbon.timestampstr() os.rename(filepath, file) if inputfile: inputData = open(inputfile, 'r').read() else: inputData = argv[4] fout = open(filepath, 'w') fout.write(inputData) fout.close() sys.stdout.write('Success\n') return 0
def check_dot_gitignore(self, repo, verbose=False): if self.is_rtc_repo(repo, verbose): default_dot_gitignore = self.default_dot_gitignore_rtc else: default_dot_gitignore = self.default_dot_gitignore_package tokens = [t.strip() for t in default_dot_gitignore.split(' ')] filepath = os.path.join(repo.path, '.gitignore') if not os.path.isfile(filepath): if verbose: sys.stdout.write('## No gitignore file in %s\n' % repo.name) return self.add_default_dot_gitignore(repo, verbose) if verbose: sys.stdout.write('## .gitignore found.\n') f = open(filepath, 'r') foundCount = 0 lines = [] for line in f: lines.append(line) if line.strip() in tokens: foundCount = foundCount + 1 tokens.remove(line.strip()) f.close() if len(tokens) == 0: if verbose: sys.stdout.write('### .gitignore covers default options.\n') return True if verbose: sys.stdout.write( '### WARNING! .gitignore does not cover default options.\n') for token in tokens: sys.stdout.write(' - %s\n' % token) sys.stdout.write('### Fixing automatically.\n') pass os.rename(filepath, filepath + wasanbon.timestampstr()) f = open(filepath, 'w') lines = lines + tokens for line in lines: f.write(line + '\n') f.close() return False
def sync(self, args): """ Synchronize rtc/repository.yaml file and each rtc repository version hash. """ options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag sys.stdout.write( '# Writing repository.yaml for package distribution\n') sys.stdout.write('## Parsing RTC directory\n') package = admin.package.get_package_from_path(os.getcwd()) repos = [] for rtc in admin.rtc.get_rtcs_from_package(package, verbose=verbose): sys.stdout.write('### RTC %s\n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_path( rtc.path, description=rtc.rtcprofile.basicInfo.description) repos.append(repo) repo_file = os.path.join(package.get_rtcpath(), 'repository.yaml') bak_file = repo_file + wasanbon.timestampstr() if os.path.isfile(bak_file): os.remove(bak_file) import shutil, yaml shutil.copy(repo_file, bak_file) dic = yaml.load(open(bak_file, 'r')) if not dic: dic = {} for repo in repos: if getattr(repo, 'url') != None: url = repo.url.strip() else: url = '' dic[repo.name] = { 'repo_name': repo.name, 'git': url, 'description': repo.description, 'hash': repo.hash } yaml.dump(dic, open(repo_file, 'w'), encoding='utf8', allow_unicode=True, default_flow_style=False) pass
def check_dot_gitignore(self, repo, verbose=False): if self.is_rtc_repo(repo, verbose): default_dot_gitignore = self.default_dot_gitignore_rtc else: default_dot_gitignore = self.default_dot_gitignore_package tokens = [t.strip() for t in default_dot_gitignore.split(" ")] filepath = os.path.join(repo.path, ".gitignore") if not os.path.isfile(filepath): if verbose: sys.stdout.write("## No gitignore file in %s\n" % repo.name) return self.add_default_dot_gitignore(repo, verbose) if verbose: sys.stdout.write("## .gitignore found.\n") f = open(filepath, "r") foundCount = 0 lines = [] for line in f: lines.append(line) if line.strip() in tokens: foundCount = foundCount + 1 tokens.remove(line.strip()) f.close() if len(tokens) == 0: if verbose: sys.stdout.write("### .gitignore covers default options.\n") return True if verbose: sys.stdout.write("### WARNING! .gitignore does not cover default options.\n") for token in tokens: sys.stdout.write(" - %s\n" % token) sys.stdout.write("### Fixing automatically.\n") pass os.rename(filepath, filepath + wasanbon.timestampstr()) f = open(filepath, "w") lines = lines + tokens for line in lines: f.write(line + "\n") f.close() return False
def filter_func(ans): file = filenames[ans] import yaml dict = yaml.load(open(package.setting_file_path, 'r')) setting_file_path = package.setting_file_path archive_path = os.path.join(package.path, 'backup') if not os.path.isdir(archive_path): os.mkdir(archive_path) archived_file_path = os.path.join( archive_path, 'setting.yaml' + wasanbon.timestampstr()) os.rename(setting_file_path, archived_file_path) dict['application']['system'] = file open(setting_file_path, 'w').write( yaml.dump(dict, encoding='utf8', allow_unicode=True, default_flow_style=False)) return False
def cat(self, args): self.parser.add_option('-f', '--file', help='Build System with Specific RTSProfile (must be placed in system_dir', default=None, dest='systemfile', action='store', type='string') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag systemfile = options.systemfile package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) if systemfile is None: systemfile = package.default_system_filepath else: systemfile = os.path.join(package.get_systempath(), systemfile) if os.path.isfile(systemfile): newfile = systemfile + wasanbon.timestampstr() os.rename(systemfile, newfile) fout = open(systemfile, 'w') fout.write(argv[3]) fout.close() sys.stdout.write('Success\n') return 0
def sync(self, args): """ Sync RTC local repository to local package repository record """ options, argv = self.parse_args(args[:]) verbose = options.verbose_flag package = admin.package.get_package_from_path(os.getcwd()) file = package.rtc_repository_file import yaml repo_dict = yaml.load(open(file, "r")) repos = admin.repository.get_rtc_repositories_from_package(package, verbose=verbose) for repo in repos: rtc = admin.rtc.get_rtc_from_package(package, repo.name) hashcode = admin.repository.get_repository_hash(repo) repo_dict[repo.name]["description"] = rtc.rtcprofile.basicInfo.description repo_dict[repo.name]["type"] = repo.type repo_dict[repo.name]["url"] = repo.url repo_dict[repo.name]["hash"] = hashcode if repo.type in repo_dict[repo.name].keys(): del (repo_dict[repo.name][repo.type]) os.rename(file, file + wasanbon.timestampstr()) yaml.dump(repo_dict, open(file, "w"), encoding="utf8", allow_unicode=True, default_flow_style=False) return 0
def configure(self, args): """ Configure system interactively in console. $ mgr.py system configure """ self.parser.add_option( '-f', '--file', help= 'Configure with Specific RTSProfile (must be placed in system_dir', default=None, dest='systemfile', action='store', type='string') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag package = admin.package.get_package_from_path(os.getcwd()) if options.systemfile: filename = os.path.join(package.get_systempath(), options.systemfile) else: filename = package.default_system_filepath from rtsprofile.rts_profile import RtsProfile file = open(filename, 'r') rtsprofile = RtsProfile(xml_spec=file) del (file) rtc_names = [rtc.instance_name for rtc in rtsprofile.components] from wasanbon import util def select_rtc(ans): rtc = rtsprofile.components[ans] confs = [] active_conf_index = -1 if len(rtc.configuration_sets) != 0: for i, conf in enumerate(rtc.configuration_sets): if conf.id == rtc.active_configuration_set: active_conf_index = i confs = conf.configuration_data conf_names = [conf.name + ':' + conf.data for conf in confs] def select_conf(ans2): key = confs[ans2].name sys.stdout.write('## INPUT (%s):' % key) val = raw_input() if util.yes_no('# %s = %s. Okay?' % (key, val)) == 'yes': rtc.configuration_sets[ active_conf_index].configuration_data[ans2].data = val return True return False util.choice(conf_names, select_conf, msg='# Select Configuration') return False util.choice(rtc_names, select_rtc, msg='# Select RTC') if util.yes_no("Save System?") != 'yes': sys.stdout.write('# Aborted \n') return 0 while True: if util.no_yes('Rename Filename?') == 'yes': filepath = os.path.join(package.get_systempath(), raw_input('Filename:')) else: filepath = filename newfile = filepath + wasanbon.timestampstr() try: os.rename(filepath, newfile) except Exception, e: sys.stdout.write( '## Exception occurred when renaming file.\n') traceback.print_exc() continue try: fout = open(filepath, 'w') fout.write(rtsprofile.save_to_xml()) fout.close() except: sys.stdout.write('## Exception occurred when saving file.\n') traceback.print_exc() continue break
def install_rtc_in_package( self, package, rtc, verbose=False, preload=True, precreate=True, copy_conf=True, rtcconf_filename="", copy_bin=True, standalone=False, conffile=None, allow_duplication=False, ): if verbose: sys.stdout.write("# Installing RTC in package %s\n" % package.name) if not standalone and self.is_installed(package, rtc, standalone=True, verbose=verbose): if verbose: sys.stdout.write("## RTC (%s) is already installed as standalone.\n" % rtc.name) sys.stdout.write("## Install standalone again.\n") standalone = True if standalone: name = rtc.rtcprofile.basicInfo.name targetconf = os.path.join(package.get_confpath(), "rtc_" + name + ".conf") conffilepath = package.rtcconf[rtc.rtcprofile.language.kind] shutil.copy(conffilepath, targetconf) rtcconf = admin.rtcconf.RTCConf(targetconf) rtcconf["manager.modules.load_path"] = "" rtcconf["manager.modules.preload"] = "" rtcconf["manager.components.precreate"] = "" rtcconf["manager.is_master"] = "NO" rtcconf["logger.file_name"] = "./log/standalonertc_%s" % name for key in rtcconf.keys(): if key.find("config_file") > 0: rtcconf.pop(key) targetconf = os.path.join(package.get_confpath(fullpath=False), "rtc_" + name + ".conf") targetconf = targetconf.replace("\\", "/") else: # not standalone if len(rtcconf_filename) == 0: rtcconf = admin.rtcconf.RTCConf(package.rtcconf[rtc.rtcprofile.language.kind]) else: rtcconf = admin.rtcconf.RTCConf(rtcconf_filename) targetfile = copy_binary_from_rtc(package, rtc, verbose=verbose, standalone=standalone) if len(targetfile) == 0: targetfile = os.path.join(package.get_binpath(fullpath=False), rtc.get_rtc_file_path()) pass rtc_count = 0 if standalone: backup_dir = os.path.join(package.path, "backup") if not os.path.isdir(backup_dir): os.mkdir(backup_dir) setting_filename = os.path.join(package.path, "setting.yaml") backup_filename = os.path.join(backup_dir, "setting.yaml" + wasanbon.timestampstr()) shutil.copy(setting_filename, backup_filename) import yaml dic = yaml.load(open(backup_filename, "r")) cmd_list = [cmd for cmd in dic["application"].get("standalone", []) if cmd.startswith(targetfile)] if len(cmd_list) == 0: dic["application"]["standalone"] = dic["application"].get("standalone", []) + [ targetfile + " -f " + targetconf ] open(setting_filename, "w").write(yaml.dump(dic, default_flow_style=False)) pass else: # If not standalone if verbose: sys.stdout.write("### Setting manager.modules.load_path:\n") rtcconf.append("manager.modules.load_path", os.path.dirname(targetfile)) if verbose: sys.stdout.write("### OK.\n") if preload: if verbose: sys.stdout.write("### Setting manager.modules.preload:\n") rtcconf.append("manager.modules.preload", os.path.basename(targetfile)) if verbose: sys.stdout.write("### OK.\n") if precreate: if verbose: sys.stdout.write("### Setting manager.components.precreate:\n") rtc_count = rtcconf.append( "manager.components.precreate", rtc.rtcprofile.basicInfo.name, verbose=verbose, allow_duplicate=allow_duplication, ) if rtc_count > 0: if verbose: sys.stdout.write("### OK.\n") else: if verbose: sys.stdout.write("### Failed.\n") return -1 if conffile == None: confpath = copy_conf_from_rtc(package, rtc, verbose=verbose, force=copy_conf, rtc_count=rtc_count - 1) else: confpath = conffile if confpath: key = ( rtc.rtcprofile.basicInfo.category + "." + rtc.rtcprofile.basicInfo.name + "%s.config_file" % (rtc_count - 1) ) if verbose: sys.stdout.write("## Configuring System. Set (%s) to %s\n" % (key, confpath)) rtcconf.append(key, confpath) rtcconf.sync() return 0
def add_rtc(self, argv): """ Add RTC information to binder $ mgr.py binder add_rtc $BINDER_NAME $RTC_NAME """ self.parser.add_option('-f', '--force', help='Force option (default=False)', default=False, action='store_true', dest='force_flag') options, argv = self.parse_args(argv[:], self._print_alternatives) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 5) binder_name = argv[3] rtc_name = argv[4] sys.stdout.write( '# Information of RTC (%s) will be added to %s binder\n' % (rtc_name, binder_name)) binder = admin.binder.get_binder(binder_name, verbose=verbose) package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) global filename filename = None rtcs = [rtc_.name for rtc_ in binder.rtcs] if rtc_name in rtcs: sys.stdout.write('# This binder have the same RTC information.\n') else: if filename is None: def choice_command(ans): global filename filename = os.path.join(binder.rtcs_path, binder.rtc_files[ans]) return -1 util.choice(binder.rtc_files, choice_command, 'Select RTC repository file') else: if not filename in binder.rtcs_files: sys.stdout.write('# File %s is not found.\n' % filenmae) filename = os.path.join(binder.rtcs_path, filename) return -1 print filename text = open(filename, 'r').read() #os.rename(filename, filename + wasanbon.timestampstr()) #import yaml #repo_dic = yaml.load(open(filename, 'w')) text = text + """ %s : description : "%s" type : git url : '%s' platform : [%s] """ % (repo.name, rtc.rtcprofile.basicInfo.doc.description, repo.url.strip(), wasanbon.platform()) print text os.rename(filename, filename + wasanbon.timestampstr()) open(filename, 'w').write(text) return 0
def configure(self, args): """ Configure system interactively in console. $ mgr.py system configure """ self.parser.add_option('-f', '--file', help='Configure with Specific RTSProfile (must be placed in system_dir', default=None, dest='systemfile', action='store', type='string') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag package = admin.package.get_package_from_path(os.getcwd()) if options.systemfile: filename = os.path.join(package.get_systempath(), options.systemfile) else: filename = package.default_system_filepath from rtsprofile.rts_profile import RtsProfile file = open(filename, 'r') rtsprofile = RtsProfile(xml_spec = file) del(file) rtc_names = [rtc.instance_name for rtc in rtsprofile.components] from wasanbon import util def select_rtc(ans): rtc = rtsprofile.components[ans] confs = [] active_conf_index = -1 if len(rtc.configuration_sets) != 0: for i, conf in enumerate(rtc.configuration_sets): if conf.id == rtc.active_configuration_set: active_conf_index = i confs = conf.configuration_data conf_names = [conf.name +':' + conf.data for conf in confs] def select_conf(ans2): key = confs[ans2].name sys.stdout.write('## INPUT (%s):' % key) val = raw_input() if util.yes_no('# %s = %s. Okay?' % (key, val)) == 'yes': rtc.configuration_sets[active_conf_index].configuration_data[ans2].data = val return True return False util.choice(conf_names, select_conf, msg='# Select Configuration') return False util.choice(rtc_names, select_rtc, msg='# Select RTC') if util.yes_no("Save System?") != 'yes': sys.stdout.write('# Aborted \n') return 0 while True: if util.no_yes('Rename Filename?') == 'yes': filepath = os.path.join(package.get_systempath(), raw_input('Filename:')) else: filepath = filename newfile = filepath + wasanbon.timestampstr() try: os.rename(filepath, newfile) except Exception, e: sys.stdout.write('## Exception occurred when renaming file.\n') traceback.print_exc() continue try: fout = open(filepath, 'w') fout.write(rtsprofile.save_to_xml()) fout.close() except: sys.stdout.write('## Exception occurred when saving file.\n') traceback.print_exc() continue break
def build(self, args): """ Build System in Console interactively $ mgr.py system build """ self.parser.add_option('-b', '--background', help='Launch in background(default=False)', default=False, action='store_true', dest='background_flag') self.parser.add_option('-w', '--wakeuptimeout', help='Timeout of Sleep Function when waiting for the wakeup of RTC-Daemons', default=5, dest='wakeuptimeout', action='store', type='float') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag background = options.background_flag wakeuptimeout = options.wakeuptimeout #force = options.force_flag package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) global endflag endflag = False try: processes = admin.systemlauncher.launch_system(package, verbose=verbose) time.sleep(wakeuptimeout) package = admin.package.get_package_from_path(os.getcwd()) nss = admin.nameserver.get_nameservers_from_package(package, verbose=verbose) for ns in nss: ns.refresh(verbose=verbose) # Interactive Connect pairs = admin.systemeditor.get_connectable_pairs(nss, verbose=verbose) from wasanbon import util for pair in pairs: if util.no_yes('# Connect? (%s->%s)\n' % (admin.systembuilder.get_port_full_path(pair[0]), admin.systembuilder.get_port_full_path(pair[1]))) == 'yes': while True: try: admin.systembuilder.connect_ports(pair[0], pair[1], verbose=verbose) sys.stdout.write('## Connected.\n') break except Exception, ex: if verbose: traceback.print_exc() pass sys.stdout.write('## Failed. \n') if util.yes_no('### Retry?') == 'no': break pass rtc_names = [] rtcs = [] for ns in nss: rtc_names = rtc_names + [admin.systembuilder.get_component_full_path(rtc) for rtc in ns.rtcs] rtcs = rtcs + ns.rtcs # Interactive Configure def select_rtc(ans): confs = admin.systemeditor.get_active_configuration_data(rtcs[ans]) conf_names = [conf.name +':' + conf.data for conf in confs] def select_conf(ans2): key = confs[ans2].name sys.stdout.write(' INPUT (%s):' % key) val = raw_input() if util.yes_no('%s = %s. Okay?' % (key, val)) == 'yes': admin.systembuilder.set_active_configuration_data(rtcs[ans], key, val) return True return False util.choice(conf_names, select_conf, msg='Select Configuration') return False util.choice(rtc_names, select_rtc, msg='Select RTC') #Save Running System if util.yes_no('# Save System ?') == 'yes': filename = os.path.basename(package.default_system_filepath) while True: if util.yes_no('# Rename filename? (default:%s)' % filename) == 'yes': while True: sys.stdout.write('# Input:') val = raw_input() if util.yes_no('# New Filename = %s. Okay?' % val) == 'yes': filename = val break pass pass # File check filepath = os.path.join(package.get_systempath(fullpath=True), filename) sys.stdout.write('## Saving to %s\n' % filepath) if os.path.isfile(filepath): if util.yes_no('## Overwrite?') == 'yes': newfilename = filepath + wasanbon.timestampstr() sys.stdout.write('## Rename existing file to %s\n' % os.path.basename(newfilename)) os.rename(filepath, newfilename) break else: break while True: sys.stdout.write('# Input Vendor Name:') vendorName = raw_input() sys.stdout.write('# Input Version:') version = raw_input() sys.stdout.write('# Input System Name (%s):' % package.name) systemName = raw_input() if len(systemName) == 0: systemName = package.name sys.stdout.write('# Input Description of System (abstract):') abstract = raw_input() sys.stdout.write('## Vendor Name = %s\n' % vendorName) sys.stdout.write('## Version = %s\n' % version) sys.stdout.write('## System Name = %s\n' % systemName) sys.stdout.write('## Abstract = %s\n' % abstract) if util.yes_no('# Okay?') == 'yes': break else: sys.stdout.write('# Retry') for i in range(5): try: sys.stdout.write('# Saving to %s\n' % filepath) admin.systemeditor.save_to_file(nss, filepath, system_name=systemName, abstract=abstract, version=version, vendor=vendorName, verbose=verbose) break except: traceback.print_exc() time.sleep(1.0) pass pass else: sys.stdout.write('## Aborted.')
def update_profile(self, args): """ Run just one RTC and compare the profile between the existing RTC.xml and launched RTC, then save RTC.xml """ self.parser.add_option('-f', '--file', help='RTCProfile filename (default="RTC.xml")', default='RTC.xml', dest='filename', action='store', type='string') self.parser.add_option('-d', '--dryrun', help='Just output on console', default=False, dest='dry_flag', action='store_true') self.parser.add_option( '-w', '--wakeuptimeout', help= 'Timeout of Sleep Function when waiting for the wakeup of RTC-Daemons', default=5, dest='wakeuptimeout', action='store', type='float') options, argv = self.parse_args(args[:], self._print_rtcs) verbose = options.verbose_flag dry = options.dry_flag filename = options.filename wakeuptimeout = options.wakeuptimeout wasanbon.arg_check(argv, 4) rtc_name = argv[3] package = admin.package.get_package_from_path(os.getcwd()) sys.stdout.write('# Starting RTC.\n') rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) standalone = admin.systeminstaller.is_installed(package, rtc, standalone=True, verbose=verbose) if standalone: admin.systemlauncher.launch_standalone_rtc(package, rtc, stdout=True, verbose=verbose) pass else: if self.run_rtc_in_package( package, rtc, verbose=verbose, background=True) != 0: return -1 wasanbon.sleep(wakeuptimeout) sys.stdout.write('# Acquiring RTCProfile from Inactive RTC\n') rtcp = admin.rtcprofile.create_rtcprofile(rtc, verbose=verbose) if standalone: pass else: self.terminate_rtcd(package, verbose=verbose) sys.stdout.write( '# Comparing Acquired RTCProfile and Existing RTCProfile.\n') retval = admin.rtcprofile.compare_rtcprofile(rtc.rtcprofile, rtcp, verbose=verbose) if retval: filepath = os.path.join(rtc.path, filename) if not dry: outstr = admin.rtcprofile.tostring(retval, pretty_print=True) if outstr == None: sys.stdout.write('# RTC Profile save failed.\n') return -1 if os.path.isfile(filepath): f = filepath + wasanbon.timestampstr() os.rename(filepath, f) pass fout = open(filepath, 'w') fout.write(outstr) fout.close() else: sys.stdout.write( admin.rtcprofile.tostring(retval, pretty_print=True)) sys.stdout.write('Succeed.\n') return 0 sys.stdout.write('Succeed.\n') return 0
def install_rtc_in_package(self, package, rtc, verbose=False, preload=True, precreate=True, copy_conf=True, rtcconf_filename="", copy_bin=True, standalone=False, conffile=None, allow_duplication=False): if verbose: sys.stdout.write('# Installing RTC in package %s\n' % package.name) if not standalone and self.is_installed( package, rtc, standalone=True, verbose=verbose): if verbose: sys.stdout.write( '## RTC (%s) is already installed as standalone.\n' % rtc.name) sys.stdout.write('## Install standalone again.\n') standalone = True if standalone: name = rtc.rtcprofile.basicInfo.name targetconf = os.path.join(package.get_confpath(), 'rtc_' + name + '.conf') conffilepath = package.rtcconf[rtc.rtcprofile.language.kind] shutil.copy(conffilepath, targetconf) rtcconf = admin.rtcconf.RTCConf(targetconf) rtcconf['manager.modules.load_path'] = '' rtcconf['manager.modules.preload'] = '' rtcconf['manager.components.precreate'] = '' rtcconf['manager.is_master'] = 'NO' rtcconf['logger.file_name'] = './log/standalonertc_%s' % name for key in rtcconf.keys(): if key.find('config_file') > 0: rtcconf.pop(key) targetconf = os.path.join(package.get_confpath(fullpath=False), 'rtc_' + name + '.conf') targetconf = targetconf.replace('\\', '/') else: # not standalone if len(rtcconf_filename) == 0: rtcconf = admin.rtcconf.RTCConf( package.rtcconf[rtc.rtcprofile.language.kind]) else: rtcconf = admin.rtcconf.RTCConf(rtcconf_filename) targetfile = copy_binary_from_rtc(package, rtc, verbose=verbose, standalone=standalone) if len(targetfile) == 0: targetfile = os.path.join(package.get_binpath(fullpath=False), rtc.get_rtc_file_path()) pass rtc_count = 0 if standalone: backup_dir = os.path.join(package.path, 'backup') if not os.path.isdir(backup_dir): os.mkdir(backup_dir) setting_filename = os.path.join(package.path, 'setting.yaml') backup_filename = os.path.join( backup_dir, 'setting.yaml' + wasanbon.timestampstr()) shutil.copy(setting_filename, backup_filename) import yaml dic = yaml.load(open(backup_filename, 'r')) cmd_list = [ cmd for cmd in dic['application'].get('standalone', []) if cmd.startswith(targetfile) ] if len(cmd_list) == 0: dic['application']['standalone'] = dic['application'].get( 'standalone', []) + [targetfile + ' -f ' + targetconf] open(setting_filename, 'w').write(yaml.dump(dic, default_flow_style=False)) pass else: # If not standalone if verbose: sys.stdout.write('### Setting manager.modules.load_path:\n') rtcconf.append('manager.modules.load_path', os.path.dirname(targetfile)) if verbose: sys.stdout.write('### OK.\n') if preload: if verbose: sys.stdout.write('### Setting manager.modules.preload:\n') rtcconf.append('manager.modules.preload', os.path.basename(targetfile)) if verbose: sys.stdout.write('### OK.\n') if precreate: if verbose: sys.stdout.write( '### Setting manager.components.precreate:\n') rtc_count = rtcconf.append('manager.components.precreate', rtc.rtcprofile.basicInfo.name, verbose=verbose, allow_duplicate=allow_duplication) if rtc_count > 0: if verbose: sys.stdout.write('### OK.\n') else: if verbose: sys.stdout.write('### Failed.\n') return -1 if conffile == None: confpath = copy_conf_from_rtc(package, rtc, verbose=verbose, force=copy_conf, rtc_count=rtc_count - 1) else: confpath = conffile if confpath: key = rtc.rtcprofile.basicInfo.category + '.' + rtc.rtcprofile.basicInfo.name + '%s.config_file' % ( rtc_count - 1) if verbose: sys.stdout.write('## Configuring System. Set (%s) to %s\n' % (key, confpath)) rtcconf.append(key, confpath) rtcconf.sync() return 0
def build(self, args): """ Build System in Console interactively $ mgr.py system build """ self.parser.add_option('-b', '--background', help='Launch in background(default=False)', default=False, action='store_true', dest='background_flag') self.parser.add_option( '-w', '--wakeuptimeout', help= 'Timeout of Sleep Function when waiting for the wakeup of RTC-Daemons', default=5, dest='wakeuptimeout', action='store', type='float') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag background = options.background_flag wakeuptimeout = options.wakeuptimeout #force = options.force_flag package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) global endflag endflag = False try: processes = admin.systemlauncher.launch_system(package, verbose=verbose) time.sleep(wakeuptimeout) package = admin.package.get_package_from_path(os.getcwd()) nss = admin.nameserver.get_nameservers_from_package( package, verbose=verbose) for ns in nss: ns.refresh(verbose=verbose) # Interactive Connect pairs = admin.systemeditor.get_connectable_pairs(nss, verbose=verbose) from wasanbon import util for pair in pairs: if util.no_yes( '# Connect? (%s->%s)\n' % (admin.systembuilder.get_port_full_path(pair[0]), admin.systembuilder.get_port_full_path( pair[1]))) == 'yes': while True: try: admin.systembuilder.connect_ports(pair[0], pair[1], verbose=verbose) sys.stdout.write('## Connected.\n') break except Exception, ex: if verbose: traceback.print_exc() pass sys.stdout.write('## Failed. \n') if util.yes_no('### Retry?') == 'no': break pass rtc_names = [] rtcs = [] for ns in nss: rtc_names = rtc_names + [ admin.systembuilder.get_component_full_path(rtc) for rtc in ns.rtcs ] rtcs = rtcs + ns.rtcs # Interactive Configure def select_rtc(ans): confs = admin.systemeditor.get_active_configuration_data( rtcs[ans]) conf_names = [conf.name + ':' + conf.data for conf in confs] def select_conf(ans2): key = confs[ans2].name sys.stdout.write(' INPUT (%s):' % key) val = raw_input() if util.yes_no('%s = %s. Okay?' % (key, val)) == 'yes': admin.systembuilder.set_active_configuration_data( rtcs[ans], key, val) return True return False util.choice(conf_names, select_conf, msg='Select Configuration') return False util.choice(rtc_names, select_rtc, msg='Select RTC') #Save Running System if util.yes_no('# Save System ?') == 'yes': filename = os.path.basename(package.default_system_filepath) while True: if util.yes_no('# Rename filename? (default:%s)' % filename) == 'yes': while True: sys.stdout.write('# Input:') val = raw_input() if util.yes_no('# New Filename = %s. Okay?' % val) == 'yes': filename = val break pass pass # File check filepath = os.path.join( package.get_systempath(fullpath=True), filename) sys.stdout.write('## Saving to %s\n' % filepath) if os.path.isfile(filepath): if util.yes_no('## Overwrite?') == 'yes': newfilename = filepath + wasanbon.timestampstr() sys.stdout.write( '## Rename existing file to %s\n' % os.path.basename(newfilename)) os.rename(filepath, newfilename) break else: break while True: sys.stdout.write('# Input Vendor Name:') vendorName = raw_input() sys.stdout.write('# Input Version:') version = raw_input() sys.stdout.write('# Input System Name (%s):' % package.name) systemName = raw_input() if len(systemName) == 0: systemName = package.name sys.stdout.write( '# Input Description of System (abstract):') abstract = raw_input() sys.stdout.write('## Vendor Name = %s\n' % vendorName) sys.stdout.write('## Version = %s\n' % version) sys.stdout.write('## System Name = %s\n' % systemName) sys.stdout.write('## Abstract = %s\n' % abstract) if util.yes_no('# Okay?') == 'yes': break else: sys.stdout.write('# Retry') for i in range(5): try: sys.stdout.write('# Saving to %s\n' % filepath) admin.systemeditor.save_to_file(nss, filepath, system_name=systemName, abstract=abstract, version=version, vendor=vendorName, verbose=verbose) break except: traceback.print_exc() time.sleep(1.0) pass pass else: sys.stdout.write('## Aborted.')