def install(self, args): """ install application """ self.parser.add_option("-s", "--specify-version", help="Specify Version of App", default=None, dest="version") self.parser.add_option( "-f", "--force", help="Force install", default=False, action="store_true", dest="force_flag" ) options, argv = self.parse_args(args[:], self._print_alternative_packages) verbose = options.verbose_flag # This is default option version = options.version force = options.force_flag wasanbon.arg_check(argv, 4) appname = argv[3] if appname == "all": apps = [] for p in self.get_packages(): n = p.split("-")[0] if not n in apps: apps.append(n) else: apps = [appname] for app in apps: self.install_app(app, version, force) return 0
def pull(self, args): """ Pull Repository from server $ mgr.py repository pull [RTC_NAME]""" options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(package, verbose=verbose) else: names = argv[3:] rtcs = [ admin.rtc.get_rtc_from_package(package, name, verbose=verbose) for name in names ] failed_flag = False for rtc in rtcs: # rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) sys.stdout.write('# Pulling RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) if admin.repository.pull(repo, verbose=verbose) == 0: sys.stdout.write('## Success\n') else: sys.stdout.write('## Failed\n') failed_flag = True return failed_flag
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 uninstall(self, args): """ uninstall application """ options, argv = self.parse_args(args[:], self._print_alternative_packages) verbose = options.verbose_flag # This is default option appdist = self.app_dir wasanbon.arg_check(argv, 4) app_name = argv[3] if app_name.find('-') >= 0: app_name = app_name.split('-')[0] package_names = self.get_packages() application_names = self.get_applications() for an in application_names: if app_name != an.split('-')[0]: continue sys.stdout.write('''# Removing '%s'.\n''' % (an)) import shutil #os.removedirs(os.path.join(appdist, app_name)) shutil.rmtree(os.path.join(appdist, an)) return 0
def push(self, args): """ Push Repository to server (default origin, master) $ mgr.py repository push [RTC_NAME]""" options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(package, verbose=verbose) else: rtcs = [admin.rtc.get_rtc_from_package(package, argv[3], verbose=verbose)] failed_flag = False return_value_map = {} for rtc in rtcs: #rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) sys.stdout.write('# Pushing RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) if admin.repository.push(repo, verbose=verbose) == 0: sys.stdout.write('## Success\n') return_value_map[rtc.rtcprofile.basicInfo.name] = True else: sys.stdout.write('## Failed\n') return_value_map[rtc.rtcprofile.basicInfo.name] = False failed_flag = False if verbose: for key, value in return_value_map.items(): sys.stdout.write('# RTC (' + key + ') Push : ' + ' '*(25-len(key)) + ('Success' if value else 'Failed') + '\n') if failed_flag: return -1 return 0
def generate_converter(self, argv): self.parser.add_option('-l', '--language', help='Language option (default=python)', default='python', action='store', dest='language') options, argv = self.parse_args(argv[:], self._print_alternatives) verbose = options.verbose_flag # This is default option language = options.language if language == 'python': wasanbon.arg_check(argv, 5) name = argv[3] typename = argv[4] admin.idl.parse() #gm = admin.idl.get_global_module() from host import inport_converter as ip ip.create_inport_converter_module(admin.idl.get_idl_parser(), name, typename, verbose=verbose) from host import outport_converter as op op.create_outport_converter_module(admin.idl.get_idl_parser(), name, typename, verbose=verbose) elif language == 'dart': admin.idl.parse() from client import dart_converter as dc dc.generate_converter(admin.idl.get_idl_parser(), verbose=verbose) return 0
def pull(self, args): """ Pull Repository from server $ mgr.py repository pull [RTC_NAME]""" options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(package, verbose=verbose) else: names = argv[3:] rtcs = [admin.rtc.get_rtc_from_package(package, name, verbose=verbose) for name in names] failed_flag = False for rtc in rtcs: # rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) sys.stdout.write('# Pulling RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) if admin.repository.pull(repo, verbose=verbose) == 0: sys.stdout.write('## Success\n') else: sys.stdout.write('## Failed\n') failed_flag = True return failed_flag
def install(self, args): """ install application """ self.parser.add_option('-s', '--specify-version', help='Specify Version of App', default=None, dest='version') self.parser.add_option('-f', '--force', help='Force install', default=False, action='store_true', dest='force_flag') options, argv = self.parse_args(args[:], self._print_alternative_packages) verbose = options.verbose_flag # This is default option version = options.version force = options.force_flag wasanbon.arg_check(argv, 4) appname = argv[3] if appname == 'all': apps = [] for p in self.get_packages(): n = p.split('-')[0] if not n in apps: apps.append(n) else: apps = [appname] for app in apps: self.install_app(app, version, force) return 0
def uninstall(self, args): """ uninstall application """ options, argv = self.parse_args(args[:], self._print_alternative_packages) verbose = options.verbose_flag # This is default option appdist = self.app_dir wasanbon.arg_check(argv, 4) app_name = argv[3] if app_name.find("-") >= 0: app_name = app_name.split("-")[0] package_names = self.get_packages() application_names = self.get_applications() for an in application_names: if app_name != an.split("-")[0]: continue sys.stdout.write("""# Removing '%s'.\n""" % (an)) import shutil # os.removedirs(os.path.join(appdist, app_name)) shutil.rmtree(os.path.join(appdist, an)) return 0
def remote_create(self, args): """ Create local repository """ self.parser.add_option('-u', '--username', help='Username of github', default=None, dest='username', action='store', type='string') self.parser.add_option('-p', '--password', help='Password of github', default=None, dest='password', action='store', type='string') options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag p = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) rtc = admin.rtc.get_rtc_from_package(p, argv[3]) try: repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) if repo is None: sys.stdout.write('# Repository is not found.\n') return -1 except wasanbon.RepositoryNotFoundException, e: sys.stdout.write('# Repository is not found.\n') return -1
def upload_appshare(self, args): """ Start Web Server """ self.parser.add_option('-d', '--description', help='Set Description', default="", dest='description') #self.parser.add_option('-p', '--port', help='Set TCP Port number for web server', type='int', default=8000, dest='port') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag # This is default option description = options.description wasanbon.arg_check(argv, 4) filepath = argv[3] if not os.path.isfile(filepath): sys.stdout.write(' - file (%s) not found.\n') import apps apps.update_cache(url=self.applist_url, verbose=verbose) dic = self.get_setting_dic() user = dic['user'] password = dic['password'] apps.upload(filepath, user, password, self.applist_filename, hostname=self.upload_host, dir=self.upload_dir, description=description) return 0
def upload_appshare(self, args): """ Start Web Server """ self.parser.add_option("-d", "--description", help="Set Description", default="", dest="description") # self.parser.add_option('-p', '--port', help='Set TCP Port number for web server', type='int', default=8000, dest='port') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag # This is default option description = options.description wasanbon.arg_check(argv, 4) filepath = argv[3] if not os.path.isfile(filepath): sys.stdout.write(" - file (%s) not found.\n") import apps apps.update_cache(url=self.applist_url, verbose=verbose) dic = self.get_setting_dic() user = dic["user"] password = dic["password"] apps.upload( filepath, user, password, self.applist_filename, hostname=self.upload_host, dir=self.upload_dir, description=description, ) return 0
def image(self, args): """ Create image from RTSProfile. This will saved to ${path_to_package}/images/[RTSP_NAME].jpg $ mgr.py rtsprofile image [RTSP_NAME] """ options, argv = self.parse_args(args[:], self._print_system_profiles) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 4) package = admin.package.get_package_from_path(os.getcwd()) 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 image_path = os.path.join(package.path, 'image') if not os.path.isdir(image_path): os.mkdir(image_path) from rtsprofile.rts_profile import RtsProfile rtsp = RtsProfile(open(systemfile_fullpath, 'r').read()) im = mgr.imaging.get_rtsp_image(package, rtsp, port_height=10, port_text_font=10) filepath = os.path.join(image_path, argv[3][:-4] + '.png') #im = self.get_image() im.save(filepath) return 0
def commit(self, args): """ Commit changes to local Package repository """ self.parser.add_option( "-p", "--push", help="Push simultaneously", default=False, dest="push_flag", action="store_true" ) options, argv = self.parse_args(args[:]) verbose = options.verbose_flag push = options.push_flag p = admin.package.get_package_from_path(os.getcwd()) sys.stdout.write("# Committing package %s to local repository\n" % p.name) repo = admin.repository.get_repository_from_path(os.getcwd(), verbose=verbose) wasanbon.arg_check(argv, 4) comment = argv[3] if repo is None: raise wasanbon.RepositoryNotFoundException() if admin.repository.commit(repo, comment, verbose=verbose) == 0: sys.stdout.write("## Success.\n") if push: sys.stdout.write("# Pushing Package %s\n" % os.path.basename(os.getcwd())) repo = admin.repository.get_repository_from_path(os.getcwd(), verbose=verbose) if admin.repository.push(repo, verbose=verbose) != 0: sys.stdout.write("## Failed.\n") return -1 sys.stdout.write("## Success.\n") return 0 sys.stdout.write("## Failed.\n") return -1
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 image(self, args): """ Create image from RTSProfile. This will saved to ${path_to_package}/images/[RTSP_NAME].jpg $ mgr.py rtsprofile image [RTSP_NAME] """ options, argv = self.parse_args(args[:], self._print_system_profiles) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 4) package = admin.package.get_package_from_path(os.getcwd()) 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 image_path = os.path.join(package.path, 'image') if not os.path.isdir(image_path): os.mkdir(image_path) from rtsprofile.rts_profile import RtsProfile rtsp = RtsProfile(open(systemfile_fullpath, 'r').read()) im = mgr.imaging.get_rtsp_image(package, rtsp, port_height=10, port_text_font=10) filepath = os.path.join(image_path, argv[3][:-4] + '.png') #im = self.get_image() im.save(filepath) return 0
def clean(self, args): options, argv = self.parse_args(args, self._print_rtcs) verbose = options.verbose_flag if verbose: sys.stdout.write('# Cleanup RTCs\n') wasanbon.arg_check(argv, 4) pack = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(pack, verbose=verbose) else: rtcs = [ admin.rtc.get_rtc_from_package(pack, argv[3], verbose=verbose) ] retval = 0 for rtc in rtcs: if verbose: sys.stdout.write('# Cleanuping RTC %s\n' % rtc.rtcprofile.basicInfo.name) ret, msg = admin.builder.clean_rtc(rtc.rtcprofile, verbose=verbose) if not ret: retval = -1 return retval
def install(self, args): """ Install RTCs to System $ mgr.py system install [RTC_NAME] """ self.parser.add_option('-f', '--force', help='Force option (default=True)', default=True, action='store_true', dest='force_flag') self.parser.add_option('-s', '--standalone', help='Install Standalone RTC(default=False)', default=False, action='store_true', dest='standalone_flag') self.parser.add_option( '-d', '--duplicate', help='Allow Duplicate RTC Creation(default=False)', default=False, action='store_true', dest='allow_duplicate') options, argv = self.parse_args(args[:], self._print_rtcs) verbose = options.verbose_flag force = options.force_flag standalone = options.standalone_flag allow_duplicate = options.allow_duplicate wasanbon.arg_check(argv, 4) pack = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(pack, verbose=verbose) else: rtcs = [ admin.rtc.get_rtc_from_package(pack, arg, verbose=verbose) for arg in argv[3:] ] retval = 0 for rtc in rtcs: ret = admin.systeminstaller.install_rtc_in_package( pack, rtc, verbose=verbose, preload=True, precreate=True, copy_conf=True, rtcconf_filename="", copy_bin=True, standalone=standalone, conffile=None, allow_duplication=allow_duplicate) if ret != 0: retval = ret return retval
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 commit(self, args): """ Commit local changes to local repository. $ mgr.py repository commit [RTC_NAME] [COMMENT]""" self.parser.add_option('-p', '--push', help='Commit with push (default="False")', default=False, action="store_true", dest="push_flag") options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag push = options.push_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 5) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(package, verbose=verbose) else: rtcs = [ admin.rtc.get_rtc_from_package(package, argv[3], verbose=verbose) ] #rtc_names = [argv[3]] return_value_map = {} failed_flag = False for rtc in rtcs: #rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) sys.stdout.write('# Committing RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) comment = argv[4] if admin.repository.commit(repo, comment, verbose=verbose) == 0: sys.stdout.write('## Success\n') if push: sys.stdout.write('# Pushing RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) if admin.repository.push(repo, verbose=verbose) == 0: sys.stdout.write('## Success\n') return_value_map[rtc.rtcprofile.basicInfo.name] = True else: sys.stdout.write('## Failed.\n') return_value_map[rtc.rtcprofile.basicInfo.name] = False else: return_value_map[rtc.rtcprofile.basicInfo.name] = True else: sys.stdout.write('## Failed.\n') return_value_map[rtc.rtcprofile.basicInfo.name] = False failed_flag = True if verbose: for key, value in return_value_map.items(): sys.stdout.write('# RTC (' + key + ') Commit : ' + ' ' * (25 - len(key)) + ('Success' if value else 'Failed') + '\n') if failed_flag: return -1 return 0
def clone(self, args): """ Cloning Package from repository. $ wasanbon-admin.py repository clone [PACKAGE_REPOSITORY_NAME] """ #self.parser.add_option('-r', '--remove', help='Remove All Files (default=False)', default=False, action='store_true', dest='remove_flag') self.parser.add_option( '-u', '--url', help='Directory point the url of repository (default="None")', default="None", type="string", dest="url") self.parser.add_option( '-t', '--type', help='Set the type of repository (default="git")', default="git", type="string", dest="type") options, argv = self.parse_args(args[:], self._list_package_repos) verbose = options.verbose_flag url = options.url typ = options.type if url is "None": wasanbon.arg_check(argv, 4) repo_name = argv[3] package_repo = admin.binder.get_package_repo(repo_name) sys.stdout.write('# Cloning Package %s\n' % package_repo.name) #import repository try: if self.clone_package(package_repo, path=package_repo.basename, verbose=verbose) == 0: sys.stdout.write('## Success.\n') return 0 else: sys.stdout.write('## Failed.\n') return -1 except: return -1 else: package_repo = admin.binder.Repository(os.path.basename(url), type=typ, platform=wasanbon.platform, url=url, description="") sys.stdout.write('# Cloning Package %s\n' % package_repo.name) try: if self.clone_package(package_repo, path=package_repo.basename, verbose=verbose) == 0: sys.stdout.write('## Success.\n') return 0 else: sys.stdout.write('## Failed.\n') return -1 except: return -1
def download_appshare(self, args): self.parser.add_option('-s', '--specify-version', help='Download application from AppShare', default=None, dest='version') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag # This is default option version = options.version wasanbon.arg_check(argv, 4) appname = argv[3] return self.download_from_appshare(appname, version)
def create(self, args): """ Create Package # Usage $ wasanbon-admin.py package create [PACK_NAME] """ options, argv = self.parse_args(args[:]) verbose = options.verbose_flag wasanbon.arg_check(argv, 4) sys.stdout.write('# Creating package %s\n' % args[3]) #import package return self.create_package(prjname = argv[3], verbose=verbose)
def create(self, args): """ Create Package # Usage $ wasanbon-admin.py package create [PACK_NAME] """ options, argv = self.parse_args(args[:]) verbose = options.verbose_flag wasanbon.arg_check(argv, 4) sys.stdout.write('# Creating package %s\n' % args[3]) #import package return self.create_package(prjname=argv[3], verbose=verbose)
def exit_rtc(self, argv): self.parser.add_option('-i', '--id', help='Set EC_ID', type='int', default=0, dest='ec_id') options, argv = self.parse_args(argv[:]) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 4) sys.stdout.write('# Resetting RTC (%s)\n' % argv[3]) ec_id = options.ec_id comp = self.component(argv[3], lambda c : c.exit(), verbose=verbose) return 0
def clone(self, args): """ Cloning Package from repository. $ wasanbon-admin.py repository clone [PACKAGE_REPOSITORY_NAME] """ # self.parser.add_option('-r', '--remove', help='Remove All Files (default=False)', default=False, action='store_true', dest='remove_flag') self.parser.add_option( "-u", "--url", help='Directory point the url of repository (default="None")', default="None", type="string", dest="url", ) self.parser.add_option( "-t", "--type", help='Set the type of repository (default="git")', default="git", type="string", dest="type", ) options, argv = self.parse_args(args[:], self._list_package_repos) verbose = options.verbose_flag url = options.url typ = options.type if url is "None": wasanbon.arg_check(argv, 4) repo_name = argv[3] package_repo = admin.binder.get_package_repo(repo_name) sys.stdout.write("# Cloning Package %s\n" % package_repo.name) # import repository try: if self.clone_package(package_repo, path=package_repo.basename, verbose=verbose) == 0: sys.stdout.write("## Success.\n") return 0 else: sys.stdout.write("## Failed.\n") return -1 except: return -1 else: package_repo = admin.binder.Repository( os.path.basename(url), type=typ, platform=wasanbon.platform, url=url, description="" ) sys.stdout.write("# Cloning Package %s\n" % package_repo.name) try: if self.clone_package(package_repo, path=package_repo.basename, verbose=verbose) == 0: sys.stdout.write("## Success.\n") return 0 else: sys.stdout.write("## Failed.\n") return -1 except: return -1
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 upload(self, argv): """ Update Wordpress Site """ #self.parser.add_option('-f', '--force', help='Force option (default=False)', default=False, action='store_true', dest='force_flag') self.parser.add_option('-i', '--i', help='Update Image (default=False)', default=False, action='store_true', dest='image_flag') options, argv = self.parse_args(argv[:]) verbose = options.verbose_flag # This is default option upImage = options.image_flag wasanbon.arg_check(argv, 4) rtc_name = argv[3] if verbose: sys.stdout.write('# Searching RTC (%s)...\n' % rtc_name) package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose) rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) setting_filename = 'setting.txt' post_id_dict = yaml.load(open(self.cache_file_path, 'r')) post_id = -1 title = '[RTC] ' + rtc_name for key, value in post_id_dict.items(): if key == title: post_id = value['id'] if post_id < 0: sys.stdout.write('## Error. Can not find post.\n') wp = self._initialize(setting_filename, verbose=verbose) from wordpress_xmlrpc.methods.posts import GetPost cat = self.check_rtc_term(wp, rtc.rtcprofile.basicInfo.category) if upImage: image = mgr.imaging.get_image(rtc.rtcprofile) filename = rtc.rtcprofile.basicInfo.name + '.jpg' image_path = save_image(image, filename) image_info = upload_image(wp, image_path) else: image_info = None html = mgr.rtcprofile.get_html(rtc) if post_id < 0: old_post = None else: old_post = wp.call(GetPost(post_id)) if old_post: html = self.copy_build_status(old_post.content, html) post(wp, old_post, title, html, rtc.rtcprofile, image_info) return 0
def get(self, args): options, argv = self.parse_args(args[:], self._print_alts) verbose = options.verbose_flag # This is default option package = admin.package.get_package_from_path(os.getcwd()) rtcconf_paths = package.rtcconf wasanbon.arg_check(argv, 5) lang = argv[3] key = argv[4] print admin.rtcconf.RTCConf(package.rtcconf[lang])[key]
def clone(self, args): """ Clone RTC. $ mgr.py repository clone [repo_name] """ self.parser.add_option('-u', '--url', help='Directory point the url of repository (default="None")', default="None", type="string", dest="url") self.parser.add_option('-t', '--type', help='Set the type of repository (default="git")', default="git", type="string", dest="type") options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag url = options.url typ = options.type if url is "None": wasanbon.arg_check(argv, 4) pack = admin.package.get_package_from_path(os.getcwd()) repos = admin.binder.get_rtc_repos() curdir = os.getcwd() os.chdir(pack.get_rtcpath()) match = False failed_flag = False if url is "None": for rtc_name in argv[3:]: for repo in repos: if repo.name == argv[3]: sys.stdout.write('# Cloning RTC (%s)\n' % rtc_name) ret = admin.repository.clone_rtc(repo, verbose=verbose) if ret < 0: sys.stdout.write('## Failed. Return Code = %s\n' % ret) failed_flag = True else: sys.stdout.write('## Success.\n') pass match = True break else: match = True rtc_name = os.path.basename(url) repo = admin.binder.Repository(os.path.basename(url), type=typ, platform=wasanbon.platform, url=url, description="") sys.stdout.write('# Cloning RTC (%s)\n' % rtc_name) ret = admin.repository.clone_rtc(repo, verbose=verbose) if ret < 0: sys.stdout.write('## Failed. Return Code = %s\n' % ret) failed_flag = True else: sys.stdout.write('## Success.\n') pass match = True os.chdir(curdir) if not match: raise wasanbon.RepositoryNotFoundException() if failed_flag: return -1 return 0
def git_init(self, args): """ Initialize git repository in RTC directory. $ mgr.py repository git_init [RTC_NAME] """ options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(package, verbose=verbose) else: names = argv[3:] rtcs = [ admin.rtc.get_rtc_from_package(package, name, verbose=verbose) for name in names ] failed_flag = False for rtc in rtcs: # rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) sys.stdout.write( '# Initializing git local repository on RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) if not repo is None: failed_flag = True sys.stdout.write('## RTC already has local repository.\n') continue sys.stdout.write('## Creating git repository in %s\n' % rtc.path) repo = admin.repository.init_git_repository_to_path( rtc.path, verbose=verbose) sys.stdout.write('## Adding Files to repository\n') admin.repository.add_files( repo, verbose=verbose, exclude_pattern='^\.|.*\.pyc$|.*~$|.*\.log$|build-.*') comment = 'First comment.' sys.stdout.write('## Commiting ...\n') if admin.repository.commit(repo, comment, verbose=verbose) != 0: sys.stdout.write('## First Commit failed.') sys.stdout.write('## Success\n') if failed_flag: sys.stdout.write('## Failed.\n') return -1 sys.stdout.write('### Success.\n') return 0
def url(self, args): """ Get Repository URL of RTC. $ mgr.py repository url [RTC_NAME] """ options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) rtc_name = argv[3] rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) print repo.url.strip() 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 image(self, argv): """ Create image from RTCProfile. This will saved to ${path_to_package}/images/[RTC_NAME].png $ mgr.py rtcprofile image [RTC_NAME] """ options, argv = self.parse_args(argv[:], self._print_rtcs) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 4) package = admin.package.get_package_from_path(os.getcwd()) image_path = os.path.join(package.path, 'image') if not os.path.isdir(image_path): os.mkdir(image_path) rtc = admin.rtc.get_rtc_from_package(package, argv[3]) filepath = os.path.join(image_path, rtc.rtcprofile.basicInfo.name + '.png') im = mgr.imaging.get_image(rtc.rtcprofile) im.save(filepath) return 0
def name(self, args): """ Get Repository URL of RTC. $ mgr.py repository url [RTC_NAME] """ options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) rtc_name = argv[3] rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) repo = self.get_registered_repository_from_rtc(rtc,verbose=verbose) if repo is None: sys.stdout.write('# Repository Not Found.\n') return -1 print repo.name return 0
def delete(self, args): """ Delete Package # Usage $ wasanbon-admin.py package delete [PACK_NAME] -r : remove directory (default False) """ self.parser.add_option('-r', '--remove', help='Remove All Files (default=False)', default=False, action='store_true', dest='remove_flag') options, argv = self.parse_args(args[:], self.print_packages) verbose = options.verbose_flag remove = options.remove_flag wasanbon.arg_check(args, 4) retval = 0 for n in argv[3:]: sys.stdout.write('# Removing package %s\n' % n) ret = self.delete_package(n, deletepath=remove, verbose=verbose) if ret != 0: retval = 1 return retval
def dump(self, argv): """ Dump RTCProfile to STDOUT $ mgr.py rtcprofile dump [RTC_NAME] """ options, argv = self.parse_args(argv[:], self._print_rtcs) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 4) pack = admin.package.get_package_from_path(os.getcwd()) rtc = admin.rtc.get_rtc_from_package(pack, argv[3]) #path = rtc.get_rtc_profile_path() #with open(path, 'r') as f: # sys.stdout.write(f.read()) sys.stdout.write( admin.rtcprofile.tostring(rtc.rtcprofile, pretty_print=True)) return 0
def dump(self, argv): """ Dump RTCProfile to STDOUT $ mgr.py rtcprofile dump [RTC_NAME] """ options, argv = self.parse_args(argv[:], self._print_rtcs) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 4) pack = admin.package.get_package_from_path(os.getcwd()) rtc = admin.rtc.get_rtc_from_package(pack, argv[3]) #path = rtc.get_rtc_profile_path() #with open(path, 'r') as f: # sys.stdout.write(f.read()) sys.stdout.write(admin.rtcprofile.tostring(rtc.rtcprofile, pretty_print=True)) return 0
def build(self, args): self.parser.add_option('-o', '--only', help='Build Only (Not Install) (default=False)', default=False, action='store_true', dest='only_flag') self.parser.add_option('-s', '--standalone', help='Install Standalone Mode (default=False)', default=False, action='store_true', dest='standalone_flag') options, argv = self.parse_args(args, self._print_rtcs) verbose = options.verbose_flag if sys.platform == 'win32': if verbose: sys.stdout.write('# In Windows, always build with verbose option.\n') verbose = True only = options.only_flag standalone = options.standalone_flag wasanbon.arg_check(argv, 4) pack = admin.package.get_package_from_path(os.getcwd()) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(pack, verbose=verbose) else: rtcs = [admin.rtc.get_rtc_from_package(pack, argv[3], verbose=verbose)] return_value_map = {} retval = 0 for rtc in rtcs: sys.stdout.write('# Building RTC (%s)\n' % rtc.rtcprofile.basicInfo.name) ret, msg = admin.builder.build_rtc(rtc.rtcprofile, verbose=verbose) return_value_map[rtc.rtcprofile.basicInfo.name] = ret if not ret: sys.stdout.write('## Failed.\n') retval = -1 else: sys.stdout.write('## Success.\n') if not only: if not standalone: # Confirm if this rtc is standalone_flag = admin.systeminstaller.is_installed(pack, rtc, verbose=verbose, standalone=True) else: standalone_flag = standalone sys.stdout.write('## Installing RTC (standalone=%s).\n' % (standalone_flag is True)) admin.systeminstaller.install_rtc_in_package(pack, rtc, verbose=verbose, standalone=standalone_flag) sys.stdout.write('### Success.\n') if verbose: sys.stdout.write('Build Summary:\n') for key, value in return_value_map.items(): sys.stdout.write(' - Build RTC (' + key + ')' + ' '*(25-len(key)) + ('Success' if value else 'False') + '\n') return retval
def commit(self, args): """ Commit local changes to local repository. $ mgr.py repository commit [RTC_NAME] [COMMENT]""" self.parser.add_option('-p', '--push', help='Commit with push (default="False")', default=False, action="store_true", dest="push_flag") options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag push = options.push_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 5) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(package, verbose=verbose) else: rtcs = [admin.rtc.get_rtc_from_package(package, argv[3], verbose=verbose)] #rtc_names = [argv[3]] return_value_map = {} failed_flag = False for rtc in rtcs: #rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) sys.stdout.write('# Committing RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) comment = argv[4] if admin.repository.commit(repo, comment, verbose=verbose) == 0: sys.stdout.write('## Success\n') if push: sys.stdout.write('# Pushing RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) if admin.repository.push(repo, verbose=verbose) == 0: sys.stdout.write('## Success\n') return_value_map[rtc.rtcprofile.basicInfo.name] = True else: sys.stdout.write('## Failed.\n') return_value_map[rtc.rtcprofile.basicInfo.name] = False else: return_value_map[rtc.rtcprofile.basicInfo.name] = True else: sys.stdout.write('## Failed.\n') return_value_map[rtc.rtcprofile.basicInfo.name] = False failed_flag = True if verbose: for key, value in return_value_map.items(): sys.stdout.write('# RTC (' + key + ') Commit : ' + ' '*(25-len(key)) + ('Success' if value else 'Failed') + '\n') if failed_flag: return -1 return 0
def commit(self, args): """ Commit changes of binder file (.yaml) to local repository. $ wasanbon-admin.py binder commit [binder_owner_name] (comment) """ self.parser.add_option('-p', '--push', help='Push simultaneously', default=False, dest='push_flag', action='store_true') options, argv = self.parse_args(args[:], self._print_alternatives) verbose = options.verbose_flag push = options.push_flag wasanbon.arg_check(argv, 5) binder_name = argv[3] comment = argv[4] binder = self.get_binder(binder_name, verbose=verbose) sys.stdout.write('# Committing binder %s to local repository\n' % binder_name) p = admin.git.git_command(['commit', '-am', comment], path=binder.path) output, stderr = p.communicate() #output = p.stdout.read() if verbose: sys.stdout.write(output) if True: sys.stdout.write('## Success.\n') if push: sys.stdout.write('# Pushing binder %s\n' % binder_name) remote = 'origin' branch = 'master' p = admin.git.git_command(['push', remote, branch], path=binder.path) output, stderr = p.communicate() #output = p.stdout.read() if verbose: sys.stdout.write(output) if p.returncode != 0: sys.stdout.write('## Failed.\n') return -1 sys.stdout.write('## Success.\n') return 0 sys.stdout.write('## Failed.\n') return -1
def name(self, args): """ Get Repository URL of RTC. $ mgr.py repository url [RTC_NAME] """ options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) rtc_name = argv[3] rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) repo = self.get_registered_repository_from_rtc(rtc, verbose=verbose) if repo is None: sys.stdout.write('# Repository Not Found.\n') return -1 print repo.name return 0
def configure(self, argv): self.parser.add_option('-s', '--set', help='Configuration Set Name (default=default)', type='string', default='default', dest='set_name') options, argv = self.parse_args(argv[:]) verbose = options.verbose_flag # This is default option wasanbon.arg_check(argv, 6) set_name = options.set_name rtc_full_path = argv[3] conf_name = argv[4] conf_value = argv[5] found_conf = False def func(comp): for cs in comp.conf_sets: if cs == set_name: cset = comp.conf_sets[set_name] for key, value in cset.data.items(): if key == conf_name: comp.set_conf_set_value(set_name, conf_name, conf_value) found_conf = True comps = [] def taskfunc(args): try: comp = self.component(rtc_full_path, func, verbose=verbose) except: sys.stdout.write('Failed. Exception occured.\n'); traceback.print_exc() return if found_conf: sys.stdout.write('Success.\n') else: sys.stdout.write('Failed.\n'); comps.append(comp) from wasanbon.util import task interval = 10 task.task_with_wdt(taskfunc, [], interval) if len(comps) == 0: sys.stdout.write('Timeout\n') return -1 return 0
def git_init(self, args): """ Initialize git repository in RTC directory. $ mgr.py repository git_init [RTC_NAME] """ options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(package, verbose=verbose) else: names = argv[3:] rtcs = [admin.rtc.get_rtc_from_package(package, name, verbose=verbose) for name in names] failed_flag = False for rtc in rtcs: # rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) sys.stdout.write('# Initializing git local repository on RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) if not repo is None: failed_flag = True sys.stdout.write('## RTC already has local repository.\n') continue sys.stdout.write('## Creating git repository in %s\n' % rtc.path) repo = admin.repository.init_git_repository_to_path(rtc.path, verbose=verbose) sys.stdout.write('## Adding Files to repository\n') admin.repository.add_files(repo, verbose=verbose, exclude_pattern='^\.|.*\.pyc$|.*~$|.*\.log$|build-.*') comment = 'First comment.' sys.stdout.write('## Commiting ...\n') if admin.repository.commit(repo, comment, verbose=verbose) != 0: sys.stdout.write('## First Commit failed.') sys.stdout.write('## Success\n') if failed_flag: sys.stdout.write('## Failed.\n') return -1 sys.stdout.write('### Success.\n') return 0
def push(self, args): """ Push Repository to server (default origin, master) $ mgr.py repository push [RTC_NAME]""" options, argv = self.parse_args(args[:], self._print_alternative_rtcs) verbose = options.verbose_flag verbose = True package = admin.package.get_package_from_path(os.getcwd()) wasanbon.arg_check(argv, 4) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(package, verbose=verbose) else: rtcs = [ admin.rtc.get_rtc_from_package(package, argv[3], verbose=verbose) ] failed_flag = False return_value_map = {} for rtc in rtcs: #rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose) sys.stdout.write('# Pushing RTC (%s) \n' % rtc.rtcprofile.basicInfo.name) repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose) if admin.repository.push(repo, verbose=verbose) == 0: sys.stdout.write('## Success\n') return_value_map[rtc.rtcprofile.basicInfo.name] = True else: sys.stdout.write('## Failed\n') return_value_map[rtc.rtcprofile.basicInfo.name] = False failed_flag = False if verbose: for key, value in return_value_map.items(): sys.stdout.write('# RTC (' + key + ') Push : ' + ' ' * (25 - len(key)) + ('Success' if value else 'Failed') + '\n') if failed_flag: return -1 return 0
def generate(self, argv): """ Generate RTC skeleton code. # Usage: mgr.py generate_rtc generate [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 force = options.force_flag wasanbon.arg_check(argv, 4) rtm_root_path = wasanbon.get_rtm_root() default_idl_path = os.path.join(rtm_root_path, 'rtm') except_files = [ 'SDOPackage.idl', 'Manager.idl', 'OpenRTM.idl', 'RTC.idl' ] idls, idl_dirs = self.search_idls(default_idl_path, except_files=except_files) idls = [ os.path.join(default_idl_path, 'idl', 'BasicDataType.idl'), os.path.join(default_idl_path, 'idl', 'ExtendedDataTypes.idl'), os.path.join(default_idl_path, 'idl', 'InterfaceDataTypes.idl') ] self._parser = parser.IDLParser(verbose=verbose) self._parser.parse(idls=idls, idl_dirs=idl_dirs, except_files=except_files) pack = admin.package.get_package_from_path(os.getcwd()) rtc = admin.rtc.get_rtc_from_package(pack, argv[3], verbose=verbose) self.generate_codes_from_profile(rtc)
def show(self, argv): """ Show datatype (struct, enum, typedef, and interface) information. """ self.parser.add_option('-l', '--long', help='Long format option (default=False)', default=False, action='store_true', dest='long_flag') self.parser.add_option( '-r', '--recursive', help= 'Recursive Type Parse. Show each members in inner structs. (default=False)', default=False, action='store_true', dest='recursive_flag') options, argv = self.parse_args(argv[:], self._print_alternatives) verbose = options.verbose_flag # This is default option long = options.long_flag recursive = options.recursive_flag wasanbon.arg_check(argv, 4) self.parse() full_typename = argv[3] typs = self._parser.global_module.find_types(full_typename) if len(typs) == 0: sys.stdout.write('Not Found.\n') return 0 for t in typs: import yaml print yaml.dump(t.to_simple_dic(full_path=True, recursive=recursive), default_flow_style=False) 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 commit(self, args): """ Commit changes to local Package repository """ self.parser.add_option('-p', '--push', help='Push simultaneously', default=False, dest='push_flag', action='store_true') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag push = options.push_flag p = admin.package.get_package_from_path(os.getcwd()) sys.stdout.write('# Committing package %s to local repository\n' % p.name) repo = admin.repository.get_repository_from_path(os.getcwd(), verbose=verbose) wasanbon.arg_check(argv, 4) comment = argv[3] if repo is None: raise wasanbon.RepositoryNotFoundException() if admin.repository.commit(repo, comment, verbose=verbose) == 0: sys.stdout.write('## Success.\n') if push: sys.stdout.write('# Pushing Package %s\n' % os.path.basename(os.getcwd())) repo = admin.repository.get_repository_from_path( os.getcwd(), verbose=verbose) if admin.repository.push(repo, verbose=verbose) != 0: sys.stdout.write('## Failed.\n') return -1 sys.stdout.write('## Success.\n') return 0 sys.stdout.write('## Failed.\n') return -1
def gen_constructor(self, argv): """ Generate Constructor Code """ self.parser.add_option('-l', '--language', help='Language option (default=python)', default='python', action='store', dest='language') options, argv = self.parse_args(argv[:], self._print_alternatives) verbose = options.verbose_flag # This is default option language = options.language recursive = True wasanbon.arg_check(argv, 4) self.parse() full_typename = argv[3] codes = self.generate_constructor_python(full_typename, verbose=verbose) for code in codes: print code return 0
def build(self, args): self.parser.add_option('-o', '--only', help='Build Only (Not Install) (default=False)', default=False, action='store_true', dest='only_flag') self.parser.add_option('-s', '--standalone', help='Install Standalone Mode (default=False)', default=False, action='store_true', dest='standalone_flag') options, argv = self.parse_args(args, self._print_rtcs) verbose = options.verbose_flag if sys.platform == 'win32': if verbose: sys.stdout.write( '# In Windows, always build with verbose option.\n') verbose = True only = options.only_flag standalone = options.standalone_flag wasanbon.arg_check(argv, 4) pack = admin.package.get_package_from_path(os.getcwd()) if argv[3] == 'all': rtcs = admin.rtc.get_rtcs_from_package(pack, verbose=verbose) else: rtcs = [ admin.rtc.get_rtc_from_package(pack, argv[3], verbose=verbose) ] return_value_map = {} retval = 0 for rtc in rtcs: sys.stdout.write('# Building RTC (%s)\n' % rtc.rtcprofile.basicInfo.name) ret, msg = admin.builder.build_rtc(rtc.rtcprofile, verbose=verbose) return_value_map[rtc.rtcprofile.basicInfo.name] = ret if not ret: sys.stdout.write('## Failed.\n') retval = -1 else: sys.stdout.write('## Success.\n') if not only: if not standalone: # Confirm if this rtc is standalone_flag = admin.systeminstaller.is_installed( pack, rtc, verbose=verbose, standalone=True) else: standalone_flag = standalone sys.stdout.write('## Installing RTC (standalone=%s).\n' % (standalone_flag is True)) admin.systeminstaller.install_rtc_in_package( pack, rtc, verbose=verbose, standalone=standalone_flag) sys.stdout.write('### Success.\n') if verbose: sys.stdout.write('Build Summary:\n') for key, value in return_value_map.items(): sys.stdout.write(' - Build RTC (' + key + ')' + ' ' * (25 - len(key)) + ('Success' if value else 'False') + '\n') return retval