Example #1
0
    def get_setting_dic(self, verbose=True):
        user = None
        password = None
        dic = {}
        if not os.path.isfile('web_setting.yaml') and not os.path.isfile(
                os.path.join(wasanbon.get_wasanbon_home(), 'web',
                             'web_setting.yaml')):
            dic = default_setting_dic
        else:
            import yaml
            if os.path.isfile('web_setting.yaml'):
                dic = yaml.load(open('web_setting.yaml', 'r').read())
            else:
                dic = yaml.load(
                    open(
                        os.path.join(wasanbon.get_wasanbon_home(), 'web',
                                     'web_setting.yaml'), 'r').read())
                pass

        if dic is None:
            if verbose:
                sys.stdout.write(
                    '# Invalid web_setting_file (./web_setting.yaml or ~/.wasanbon/web/web_setting.yaml\n'
                )
            dic = default_setting_dic
        return dic
    def init(self, args):
        self.parser.add_option('-f', '--force', help='Force Initialize Setting', default=False, action='store_true',  dest='force')
        
        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag # This is default option
        force = options.force

        if not os.path.isdir(self.web_dir):
            os.mkdir(self.web_dir)
        
        if not os.path.isdir(self.app_dir):
            os.mkdir(self.app_dir)
        
        if not os.path.isdir(self.pack_dir):
            os.mkdir(self.pack_dir)

        style_file = 'index.css'
        style_file_path = os.path.join(self.app_dir, style_file)
        if not os.path.isfile(style_file_path):
            import shutil
            shutil.copy(os.path.join(__path__[0], 'styles', style_file), style_file_path)

        if (not os.path.isfile(os.path.join(wasanbon.get_wasanbon_home(), 'web', 'web_setting.yaml'))) or force:
            import yaml
            print 'CP', yaml.dump(default_setting_dic)
            with open(os.path.join(wasanbon.get_wasanbon_home(), 'web', 'web_setting.yaml'), 'w') as f:

                f.write(yaml.dump(default_setting_dic))
                f.close()
        self.download_from_appshare('Apps')
        self.install_app('Apps', force=force, verbose=verbose)
        self.download_from_appshare('Setting')
        self.install_app('Setting', force=force, verbose=verbose)
def cache_to_dict(target=None):
    if target is None:
        target = os.path.join(wasanbon.get_wasanbon_home(), 'web')

    if not os.path.isdir(target):
        os.mkdir(target)

    target_file = os.path.join(target, _list_page)


    dic = {}
    root =  etree.fromstring(open(target_file, 'r').read())
    body = root.find('body')
    listtop = body.find('ul')
    
    for item in listtop.findall('li'):
        appname = item.text.strip()
        if appname in dic.keys():
            sys.stdout.write(' -- Application (%s) is doubled.\n' % appname)
            return {}

        dic[appname] = {}

        app_version_listtop = item.find('ul')
        for version_item in app_version_listtop.findall('li'):
            a_item = version_item.find('a')
            d_item = version_item.find('span')
            version_text = a_item.text.strip()
            url = a_item.get('href').strip()
            
            dic[appname][version_text] = {'url': url, 'description' : d_item.text.strip() }
            #dic[appname]['description'] = d_item.text.strip()

    return dic
Example #4
0
def cache_to_dict(target=None):
    if target is None:
        target = os.path.join(wasanbon.get_wasanbon_home(), 'web')

    if not os.path.isdir(target):
        os.mkdir(target)

    target_file = os.path.join(target, _list_page)


    dic = {}
    root =  etree.fromstring(open(target_file, 'r').read())
    body = root.find('body')
    listtop = body.find('ul')
    
    for item in listtop.findall('li'):
        appname = item.text.strip()
        if appname in dic.keys():
            sys.stdout.write(' -- Application (%s) is doubled.\n' % appname)
            return {}

        dic[appname] = {}

        app_version_listtop = item.find('ul')
        for version_item in app_version_listtop.findall('li'):
            a_item = version_item.find('a')
            d_item = version_item.find('span')
            version_text = a_item.text.strip()
            url = a_item.get('href').strip()
            
            dic[appname][version_text] = {'url': url, 'description' : d_item.text.strip() }
            #dic[appname]['description'] = d_item.text.strip()

    return dic
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)
Example #6
0
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)
Example #7
0
    def init(self, args):
        self.parser.add_option('-f',
                               '--force',
                               help='Force Initialize Setting',
                               default=False,
                               action='store_true',
                               dest='force')

        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag  # This is default option
        force = options.force

        if not os.path.isdir(self.web_dir):
            os.mkdir(self.web_dir)

        if not os.path.isdir(self.app_dir):
            os.mkdir(self.app_dir)

        if not os.path.isdir(self.pack_dir):
            os.mkdir(self.pack_dir)

        style_file = 'index.css'
        style_file_path = os.path.join(self.app_dir, style_file)
        if not os.path.isfile(style_file_path):
            import shutil
            shutil.copy(os.path.join(__path__[0], 'styles', style_file),
                        style_file_path)

        if (not os.path.isfile(
                os.path.join(wasanbon.get_wasanbon_home(), 'web',
                             'web_setting.yaml'))) or force:
            import yaml
            print 'CP', yaml.dump(default_setting_dic)
            with open(
                    os.path.join(wasanbon.get_wasanbon_home(), 'web',
                                 'web_setting.yaml'), 'w') as f:

                f.write(yaml.dump(default_setting_dic))
                f.close()
        self.download_from_appshare('Apps')
        self.install_app('Apps', force=force, verbose=verbose)
        self.download_from_appshare('Setting')
        self.install_app('Setting', force=force, verbose=verbose)
def upload_list(usr, passwd, target=None, filename=None, hostname=None, dir=None):
    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)

    upload_file(usr, passwd, target_file, hostname, dir=dir)
Example #9
0
def upload_list(usr, passwd, target=None, filename=None, hostname=None, dir=None):
    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)

    upload_file(usr, passwd, target_file, hostname, dir=dir)
Example #10
0
def update_cache(url, target=None):
    if target is None:
        target = os.path.join(wasanbon.get_wasanbon_home(), 'web')
    if not os.path.isdir(target):
        os.mkdir(target)

    req = urllib2.Request(url)
    response = urllib2.urlopen(req)
    page_content = response.read()

    target_file = os.path.join(target, _list_page)
    open(target_file, 'w').write(page_content)
Example #11
0
    def get_setting_dic(self, verbose=True):
        user = None
        password = None
        dic = {}
        if not os.path.isfile("web_setting.yaml") and not os.path.isfile(
            os.path.join(wasanbon.get_wasanbon_home(), "web", "web_setting.yaml")
        ):
            dic = default_setting_dic
        else:
            import yaml

            if os.path.isfile("web_setting.yaml"):
                dic = yaml.load(open("web_setting.yaml", "r").read())
            else:
                dic = yaml.load(open(os.path.join(wasanbon.get_wasanbon_home(), "web", "web_setting.yaml"), "r").read())
                pass

        if dic is None:
            if verbose:
                sys.stdout.write("# Invalid web_setting_file (./web_setting.yaml or ~/.wasanbon/web/web_setting.yaml\n")
            dic = default_setting_dic
        return dic
Example #12
0
    def init(self, args):
        self.parser.add_option(
            "-f", "--force", help="Force Initialize Setting", default=False, action="store_true", dest="force"
        )

        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag  # This is default option
        force = options.force

        if not os.path.isdir(self.web_dir):
            os.mkdir(self.web_dir)

        if not os.path.isdir(self.app_dir):
            os.mkdir(self.app_dir)

        if not os.path.isdir(self.pack_dir):
            os.mkdir(self.pack_dir)

        style_file = "index.css"
        style_file_path = os.path.join(self.app_dir, style_file)
        if not os.path.isfile(style_file_path):
            import shutil

            shutil.copy(os.path.join(__path__[0], "styles", style_file), style_file_path)

        if (not os.path.isfile(os.path.join(wasanbon.get_wasanbon_home(), "web", "web_setting.yaml"))) or force:
            import yaml

            print "CP", yaml.dump(default_setting_dic)
            with open(os.path.join(wasanbon.get_wasanbon_home(), "web", "web_setting.yaml"), "w") as f:

                f.write(yaml.dump(default_setting_dic))
                f.close()
        self.download_from_appshare("Apps")
        self.install_app("Apps", force=force, verbose=verbose)
        self.download_from_appshare("Setting")
        self.install_app("Setting", force=force, verbose=verbose)
Example #13
0
def update_cache(url, target=None, verbose=False):
    if verbose: sys.stdout.write('# Update Cache in %s\n' % url)
    if target is None:
        target = os.path.join(wasanbon.get_wasanbon_home(), 'web')
    if not os.path.isdir(target):
        os.mkdir(target)

    req = urllib2.Request(url)
    response = urllib2.urlopen(req)
    page_content = response.read()
    
    if verbose: sys.stdout.write('############### Content #################\n')
    if verbose: sys.stdout.write(page_content)
    if verbose: sys.stdout.write('############### Content #################\n')
    target_file = os.path.join(target, _list_page)
    open(target_file, 'w').write(page_content)