Ejemplo n.º 1
0
 def setting_path(self):
     """ This plugin's setting directory path. This includes OS dependent information like packages. """
     setting_path = os.path.join(__path__[0], 'settings',
                                 wasanbon.platform())
     if not os.path.isdir(setting_path):
         sys.stdout.write('# Error. UnsupportedPlatform (%s)\n' %
                          wasanbon.platform())
         raise wasanbon.UnsupportedPlatformException()
     return setting_path
Ejemplo n.º 2
0
def get_rtc_repositories_from_package(package_obj, verbose=False):
    if verbose:
        sys.stdout.write('# Loading Repository File from package(%s)\n' %
                         (package_obj.name))
    repos = []
    import wasanbon
    import yaml
    dict_ = yaml.load(open(package_obj.rtc_repository_file, 'r'))
    if dict is not None:
        #binder = wasanbon.plugins.admin.binder.binder
        binder = plugin_obj.admin.binder.binder
        for name, value in dict_.items():

            if 'git' in value.keys():
                typ = 'git'

            if verbose:
                sys.stdout.write('## Loading Repository (name=%s, url=%s)\n' %
                                 (name, value[typ]))

            repo = binder.Repository(name=name,
                                     type=typ,
                                     url=value[typ],
                                     platform=wasanbon.platform(),
                                     description=value['description'])
            repos.append(repo)
        pass

    return repos
Ejemplo n.º 3
0
    def init(self, args):
        """ This command must be called first.
        Install Pip, PyYAML, PyGithub, psutil, python-bitbucket, and several modules 
        if not installed. After that, Initialize $HOME/.wasanbon directory, 
        and search commands used in wasanbon. If some command-line tools are not installed, 
        this will tries to install them.
        """

        sys.stdout.write('# Starting wasanbon environment initialization...\n')
        self.parser.add_option('-f', '--force', help='Force option (default=False)', default=False, action='store_true', dest='force_flag')
        self.parser.add_option('-q', '--quiet', help='Verbosity option (default=False)', default=False, action='store_true', dest='quiet_flag')
        options, argv = self.parse_args(args[:])
        verbose = True #options.verbose_flag
        if options.quiet_flag: verbose = False
        force = options.force_flag

        sys.stdout.write('# Checking Installationg and Repair Environment.....\n')

        # This order is very important

        retval = []
        for install_pack in self._install_list:
            ret = setup.try_import_and_install(install_pack, verbose=verbose, force=force, workpath=wasanbon.temp_path)
            retval.append(ret == 0)

        if not all(retval):
            sys.stdout.write('# Failed. Try again.\n')
            return -1

        sys.stdout.write('# Success.\n')
        sys.stdout.write('# Initializing .wasanbon directory....\n')
        
        if verbose:sys.stdout.write('## Platform: %s\n' % wasanbon.platform())

        self._copy_path_yaml_from_setting_dir(force=force, verbose=verbose)
        self._update_path(verbose)

        if verbose: sys.stdout.write('# Installing Commands....\n')

        ret = self._install_commands(verbose)
        
        if ret == 0:
            sys.stdout.write('# Success.\n')
        else:
            sys.stdout.write('# Failed. Try again.\n')
            return -1


        sys.stdout.write('# Installing RTMs...\n')
        for rtm in self._install_rtms:
            if verbose: sys.stdout.write('# Installing %s\n' % rtm)
            if self._install_package(rtm, verbose=verbose, force=force) != 0:
                sys.stdout.write('# Installng %s Failed. Try again.\n' % rtm)
            else:
                if verbose: sys.stdout.write('## Installing %s succeeded.\n' % rtm)
                
        sys.stdout.write('## Installing RTMs Ends.\n')
        return 0
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def setup_bashrc(self, verbose=False):
        """ Setup bashrc profile. In Ubuntu, $HOME/.bashrc. In OSX, $HOME/.bash_profile. """
        if sys.platform == 'darwin':
            filename = '.bash_profile'
        elif sys.platform == 'linux2':
            filename = '.bashrc'
        else:
            return -1

        start_str = '#-- Starting Setup Script of wasanbon --#'
        stop_str = '#-- Ending Setup Script of wasanbon --#'
        target = os.path.join(wasanbon.get_home_path(), filename)
        script = open(
            os.path.join(__path__[0], "settings", wasanbon.platform(),
                         "bashrc"), "r").read()

        if verbose: sys.stdout.write('# Initializing $HOME/%s\n' % filename)

        if os.path.isfile(target):
            erase = False
            file = open(target, "r")
            fout = open(target + '.bak', "w")
            for line in file:
                if line.strip() == start_str:
                    erase = True
                    continue

                elif line.strip() == stop_str:
                    erase = False
                    continue

                if not erase:
                    fout.write(line)
                    pass
                pass

            file.close()
            fout.close()

            os.remove(target)
            os.rename(target + ".bak", target)

            fout = open(target, "a")
        else:
            fout = open(target, "w")
            pass

        fout.write("\n\n" + start_str + "\n")
        fout.write(script)
        fout.write("\n" + stop_str + "\n\n")

        fout.close()
        return 0
Ejemplo n.º 6
0
    def setup_bashrc(self, verbose=False):
    	""" Setup bashrc profile. In Ubuntu, $HOME/.bashrc. In OSX, $HOME/.bash_profile. """
        if sys.platform == 'darwin':
            filename = '.bash_profile'
        elif sys.platform == 'linux2':            
            filename = '.bashrc'
        else:
            return -1

        start_str = '#-- Starting Setup Script of wasanbon --#'
        stop_str  = '#-- Ending Setup Script of wasanbon --#'
        target = os.path.join(wasanbon.get_home_path(), filename)
        script = open(os.path.join(__path__[0], "settings", wasanbon.platform(), "bashrc"), "r").read()
        
        if verbose: sys.stdout.write('# Initializing $HOME/%s\n' % filename)
        
        if os.path.isfile(target):
            erase = False
            file = open(target, "r")
            fout = open(target + '.bak', "w")
            for line in file:
                if line.strip() == start_str:
                    erase = True
                    continue

                elif line.strip() == stop_str:
                    erase = False
                    continue

                if not erase:
                    fout.write(line)
                    pass
                pass
        
            file.close()
            fout.close()

            os.remove(target)
            os.rename(target + ".bak" , target)
            
            fout = open(target, "a")
        else:
            fout = open(target, "w")
            pass

        fout.write("\n\n" + start_str + "\n")
        fout.write(script)
        fout.write("\n" + stop_str + "\n\n")
            

        fout.close()
        return 0
Ejemplo n.º 7
0
 def get_git_repository_from_path(self, path, verbose=False, description=""):
     typ = "git"
     p = admin.git.git_command(["config", "--get", "remote.origin.url"], path=path)
     p.wait()
     url = p.stdout.read().strip()
     name = os.path.basename(url).strip()
     desc = description.strip()
     if name.endswith(".git"):
         name = name[:-4]
     repo = admin.binder.Repository(
         name=name, type=typ, url=url, description=desc, platform=wasanbon.platform(), path=path
     )
     return repo
Ejemplo n.º 8
0
 def get_git_repository_from_rtc(self, rtc, verbose=False):
     typ = "git"
     name = rtc.rtcprofile.basicInfo.name
     p = admin.git.git_command(["config", "--get", "remote.origin.url"], path=rtc.path)
     p.wait()
     url = p.stdout.read()
     repo = admin.binder.Repository(
         name=rtc.rtcprofile.basicInfo.name,
         type=typ,
         url=url,
         description=rtc.rtcprofile.basicInfo.description,
         platform=wasanbon.platform(),
         path=rtc.path,
     )
     return repo
Ejemplo n.º 9
0
 def get_git_repository_from_rtc(self, rtc, verbose=False):
     typ = 'git'
     name = rtc.rtcprofile.basicInfo.name
     p = admin.git.git_command(['config', '--get', 'remote.origin.url'],
                               path=rtc.path)
     p.wait()
     url = p.stdout.read()
     repo = admin.binder.Repository(
         name=rtc.rtcprofile.basicInfo.name,
         type=typ,
         url=url,
         description=rtc.rtcprofile.basicInfo.description,
         platform=wasanbon.platform(),
         path=rtc.path)
     return repo
Ejemplo n.º 10
0
 def get_git_repository_from_path(self,
                                  path,
                                  verbose=False,
                                  description=""):
     typ = 'git'
     p = admin.git.git_command(['config', '--get', 'remote.origin.url'],
                               path=path)
     p.wait()
     url = p.stdout.read().strip()
     name = os.path.basename(url).strip()
     desc = description.strip()
     if name.endswith('.git'): name = name[:-4]
     repo = admin.binder.Repository(name=name,
                                    type=typ,
                                    url=url,
                                    description=desc,
                                    platform=wasanbon.platform(),
                                    path=path)
     return repo
Ejemplo n.º 11
0
def get_rtc_repositories_from_package(package_obj, verbose=False):
    if verbose: sys.stdout.write('# Loading Repository File from package(%s)\n' % (package_obj.name))
    repos = []
    import wasanbon
    import yaml
    dict_ = yaml.load(open(package_obj.rtc_repository_file, 'r'))
    if dict is not None:
        #binder = wasanbon.plugins.admin.binder.binder
        binder = plugin_obj.admin.binder.binder
        for name, value in dict_.items():

            if 'git' in value.keys():
                typ = 'git'

            if verbose: sys.stdout.write('## Loading Repository (name=%s, url=%s)\n'%(name, value[typ]))

            repo = binder.Repository(name=name, type=typ, url=value[typ], platform=wasanbon.platform(), description=value['description'])
            repos.append(repo)
        pass

    return repos
Ejemplo n.º 12
0
    def get_rtc_repositories_from_package(self, package_obj, verbose=False):
        if verbose:
            sys.stdout.write('# Loading Repository File from package(%s)\n' %
                             (package_obj.name))
        repos = []
        import wasanbon
        import yaml
        dict_ = yaml.load(open(package_obj.rtc_repository_file, 'r'))
        if not dict_ is None:
            for name, value in dict_.items():
                if 'git' in value.keys():
                    typ = 'git'
                    url = value[typ]
                    pass
                elif 'url' in value.keys():
                    typ = value['type']
                    url = value['url']
                if verbose:
                    sys.stdout.write(
                        '## Loading Repository (name=%s, url=%s)\n' %
                        (name, url))
                path = None
                try:
                    rtc = admin.rtc.get_rtc_from_package(package_obj, name)
                    path = rtc.path
                except wasanbon.RTCNotFoundException:
                    pass

                repo = admin.binder.Repository(
                    name=name,
                    type=typ,
                    url=url,
                    platform=wasanbon.platform(),
                    description=value['description'],
                    path=path)
                repos.append(repo)
                pass
            pass
        return repos
Ejemplo n.º 13
0
    def get_rtc_repositories_from_package(self, package_obj, verbose=False):
        if verbose:
            sys.stdout.write("# Loading Repository File from package(%s)\n" % (package_obj.name))
        repos = []
        import wasanbon
        import yaml

        dict_ = yaml.load(open(package_obj.rtc_repository_file, "r"))
        if not dict_ is None:
            for name, value in dict_.items():
                if "git" in value.keys():
                    typ = "git"
                    url = value[typ]
                    pass
                elif "url" in value.keys():
                    typ = value["type"]
                    url = value["url"]
                if verbose:
                    sys.stdout.write("## Loading Repository (name=%s, url=%s)\n" % (name, url))
                path = None
                try:
                    rtc = admin.rtc.get_rtc_from_package(package_obj, name)
                    path = rtc.path
                except wasanbon.RTCNotFoundException:
                    pass

                repo = admin.binder.Repository(
                    name=name,
                    type=typ,
                    url=url,
                    platform=wasanbon.platform(),
                    description=value["description"],
                    path=path,
                )
                repos.append(repo)
                pass
            pass
        return repos
Ejemplo n.º 14
0
    def init(self, args):
        """ This command must be called first.
        Install Pip, PyYAML, PyGithub, psutil, python-bitbucket, and several modules 
        if not installed. After that, Initialize $HOME/.wasanbon directory, 
        and search commands used in wasanbon. If some command-line tools are not installed, 
        this will tries to install them.
        """

        sys.stdout.write('# Starting wasanbon environment initialization...\n')
        self.parser.add_option('-f',
                               '--force',
                               help='Force option (default=False)',
                               default=False,
                               action='store_true',
                               dest='force_flag')
        self.parser.add_option('-q',
                               '--quiet',
                               help='Verbosity option (default=False)',
                               default=False,
                               action='store_true',
                               dest='quiet_flag')
        options, argv = self.parse_args(args[:])
        verbose = True  #options.verbose_flag
        if options.quiet_flag: verbose = False
        force = options.force_flag

        sys.stdout.write(
            '# Checking Installationg and Repair Environment.....\n')

        # This order is very important

        retval = []
        for install_pack in self._install_list:
            ret = setup.try_import_and_install(install_pack,
                                               verbose=verbose,
                                               force=force,
                                               workpath=wasanbon.temp_path)
            retval.append(ret == 0)

        if not all(retval):
            sys.stdout.write('# Failed. Try again.\n')
            return -1

        sys.stdout.write('# Success.\n')
        sys.stdout.write('# Initializing .wasanbon directory....\n')

        if verbose: sys.stdout.write('## Platform: %s\n' % wasanbon.platform())

        self._copy_path_yaml_from_setting_dir(force=force, verbose=verbose)
        self._update_path(verbose)

        if verbose: sys.stdout.write('# Installing Commands....\n')

        ret = self._install_commands(verbose)

        if ret == 0:
            sys.stdout.write('# Success.\n')
        else:
            sys.stdout.write('# Failed. Try again.\n')
            return -1

        sys.stdout.write('# Installing RTMs...\n')
        for rtm in self._install_rtms:
            if verbose: sys.stdout.write('# Installing %s\n' % rtm)
            if self._install_package(rtm, verbose=verbose, force=force) != 0:
                sys.stdout.write('# Installng %s Failed. Try again.\n' % rtm)
            else:
                if verbose:
                    sys.stdout.write('## Installing %s succeeded.\n' % rtm)

        sys.stdout.write('## Installing RTMs Ends.\n')
        return 0
Ejemplo n.º 15
0
 def __call__(self, argv):
     """ Manifesting __call__ function is available but not recommended """
     sys.stdout.write('platform version: %s\n' % wasanbon.platform())
     sys.stdout.write('wasanbon version: %s\n' % wasanbon.get_version())
     pass
Ejemplo n.º 16
0
 def __call__(self, argv):
     """ Manifesting __call__ function is available but not recommended """
     sys.stdout.write('platform version: %s\n' % wasanbon.platform())
     sys.stdout.write('wasanbon version: %s\n' % wasanbon.get_version())
     pass
Ejemplo n.º 17
0
 def setting_path(self):
 	""" This plugin's setting directory path. This includes OS dependent information like packages. """
     setting_path = os.path.join(__path__[0], 'settings', wasanbon.platform())
     if not os.path.isdir(setting_path):
         raise wasanbon.UnsupportedPlatformException()
     return setting_path
Ejemplo n.º 18
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