Пример #1
0
    def get_template_from_skin_key(self, skin_key, web_path, warning):
        local_path = skin_key + web_path
        # 3. Get the handler
        handler = ro_database.get_handler(local_path, soft=True)
        if handler:
            if warning:
                print warning
            return handler

        # 4. Not an exact match: trigger language negotiation
        folder_path, name = local_path.rsplit('/', 1)
        name = name + '.'
        n = len(name)
        languages = []
        for x in lfs.get_names(folder_path):
            if x[:n] == name:
                language = x[n:]
                if has_language(language):
                    languages.append(language)
        if not languages:
            return None

        # 4.1 Get the best variant
        accept = self.accept_language
        language = accept.select_language(languages)
        # Print Warning
        if warning:
            print warning
        # 4.2 By default use whatever variant
        # (XXX we need a way to define the default)
        if language is None:
            language = languages[0]
        local_path = '%s.%s' % (local_path, language)
        return ro_database.get_handler(local_path, soft=True)
Пример #2
0
    def get_template_from_skin_key(self, skin_key, web_path, warning):
        local_path = skin_key + web_path
        # 3. Get the handler
        handler = ro_database.get_handler(local_path, soft=True)
        if handler:
            if warning:
                print warning
            return handler

        # 4. Not an exact match: trigger language negotiation
        folder_path, name = local_path.rsplit('/', 1)
        name = name + '.'
        n = len(name)
        languages = []
        for x in lfs.get_names(folder_path):
            if x[:n] == name:
                language = x[n:]
                if has_language(language):
                    languages.append(language)
        if not languages:
            return None

        # 4.1 Get the best variant
        accept = self.accept_language
        language = accept.select_language(languages)
        # Print Warning
        if warning:
            print warning
        # 4.2 By default use whatever variant
        # (XXX we need a way to define the default)
        if language is None:
            language = languages[0]
        local_path = '%s.%s' % (local_path, language)
        return ro_database.get_handler(local_path)
Пример #3
0
    def load(self):
        path = expanduser('~/.usine')
        if lfs.is_file(path):
            return 'ERROR: %s is a file, remove it first' % path

        # Make the user configuration file if needed
        if not lfs.exists(path):
            print 'Making the configuration folder:', path
            lfs.make_folder(path)
            return 'Now add the INI files within the folder'

        # Read the user configuration file
        ini  = [ '%s/%s' % (path, x)
                 for x in lfs.get_names(path) if x[-4:] == '.ini' ]
        if len(ini) == 0:
            return 'ERROR: zero INI files found in %s/' % path

        # Read the ini file
        cfg = RawConfigParser()
        cfg.read(ini)

        # Get the data
        for section in cfg._sections:
            options = cfg._sections[section]
            type, name = section.split()
            module = modules[type]
            obj = module(options)

            # Keep the data unit
            self.by_type.setdefault(type, []).append(obj)
            self.by_type_and_name[(type, name)] = obj

        # Sort
        for type in self.by_type:
            self.by_type[type].sort(key=lambda x: x.name)
Пример #4
0
 def action_update(self):
     """
     If config folder is a GIT repository, rebase it
     """
     path = expanduser('~/.usine')
     for x in lfs.get_names(path):
         folder = '{}/{}'.format(path, x)
         if lfs.exists('{}/.git'.format(folder)):
             local.run(['git', 'fetch', 'origin'], cwd=folder)
             local.run(['git', 'reset', '--hard', 'origin/master'], cwd=folder)
Пример #5
0
    def get_template(self, web_path):
        web_path = normalize_path(web_path)

        # 1. Find local root
        web_roots = ui_registry.keys()
        web_roots.sort(reverse=True)
        for web_root in web_roots:
            if web_path.startswith(web_root):
                break
        else:
            raise ValueError, 'unexpected %s' % repr(web_path)

        # 2. Get the local path
        local_root = ui_registry[web_root]
        local_path = local_root + web_path[len(web_root):]

        # 3. Get the handler
        handler = ro_database.get_handler(local_path, soft=True)
        if handler:
            return handler

        # 4. Not an exact match: trigger language negotiation
        folder_path, name = local_path.rsplit('/', 1)
        name = name + '.'
        n = len(name)
        languages = []
        for x in lfs.get_names(folder_path):
            if x[:n] == name:
                language = x[n:]
                if has_language(language):
                    languages.append(language)
        if not languages:
            return None

        # 4.1 Get the best variant
        accept = self.accept_language
        language = accept.select_language(languages)

        # 4.2 By default use whatever variant
        # (XXX we need a way to define the default)
        if language is None:
            language = languages[0]
        local_path = '%s.%s' % (local_path, language)
        return ro_database.get_handler(local_path)
Пример #6
0
    def get_template(self, web_path):
        web_path = normalize_path(web_path)

        # 1. Find local root
        web_roots = ui_registry.keys()
        web_roots.sort(reverse=True)
        for web_root in web_roots:
            if web_path.startswith(web_root):
                break
        else:
            raise ValueError, 'unexpected %s' % repr(web_path)

        # 2. Get the local path
        local_root = ui_registry[web_root]
        local_path = local_root + web_path[len(web_root):]

        # 3. Get the handler
        handler = ro_database.get_handler(local_path, soft=True)
        if handler:
            return handler

        # 4. Not an exact match: trigger language negotiation
        folder_path, name = local_path.rsplit('/', 1)
        name = name + '.'
        n = len(name)
        languages = []
        for x in lfs.get_names(folder_path):
            if x[:n] == name:
                language = x[n:]
                if has_language(language):
                    languages.append(language)
        if not languages:
            return None

        # 4.1 Get the best variant
        accept = self.accept_language
        language = accept.select_language(languages)

        # 4.2 By default use whatever variant
        # (XXX we need a way to define the default)
        if language is None:
            language = languages[0]
        local_path = '%s.%s' % (local_path, language)
        return ro_database.get_handler(local_path)
Пример #7
0
    def load(self):
        path = expanduser('~/.usine')
        if lfs.is_file(path):
            return 'ERROR: %s is a file, remove it first' % path

        # Make the user configuration file if needed
        if not lfs.exists(path):
            print 'Making the configuration folder:', path
            lfs.make_folder(path)
            return 'Now add the INI files within the folder'

        # Read the user configuration file
        ini = [
            '%s/%s' % (path, x) for x in lfs.get_names(path)
            if x[-4:] == '.ini'
        ]
        if len(ini) == 0:
            return 'ERROR: zero INI files found in %s/' % path

        # Read the ini file
        cfg = RawConfigParser()
        cfg.read(ini)

        # Get the data
        for section in cfg._sections:
            options = cfg._sections[section]
            type, name = section.split()
            module = modules[type]
            obj = module(options)

            # Keep the data unit
            self.by_type.setdefault(type, []).append(obj)
            self.by_type_and_name[(type, name)] = obj

        # Sort
        for type in self.by_type:
            self.by_type[type].sort(key=lambda x: x.name)
Пример #8
0
 def ea_language(self):
     path = get_abspath('ui/ikaaro/editarea/langs')
     languages = [ x[:-3] for x in lfs.get_names(path) ]
     return get_context().accept_language.select_language(languages)
Пример #9
0
 def rte_language(self):
     path = get_abspath('ui/ikaaro/tiny_mce/langs')
     languages = [ x[:-3] for x in lfs.get_names(path) ]
     return get_context().accept_language.select_language(languages)
Пример #10
0
def get_test_filenames(test_path, force_download):
    """Return the test file names
    If the test files does'nt exists, we download it
    """

    uris = {'http://download.wikimedia.org/qualitywiki/latest':
            [('qualitywiki-latest-stub-articles.xml', '.gz'),      #~  3.1 KB
             ('qualitywiki-latest-stub-meta-current.xml', '.gz'),  #~ 11.0 KB
             ('qualitywiki-latest-stub-meta-history.xml', '.gz')], #~ 28.9 KB
            'http://download.wikimedia.org/tawiki/latest':
            [('tawiki-latest-stub-articles.xml', '.gz'),           #~ 1.2 MB
             ('tawiki-latest-stub-meta-history.xml', '.gz')],      #~ 7.3 MB
            'http://www.w3.org/XML/Test/': [('xmlts20080205', '.tar.gz')]
            }
    compressed_dir_path = join(test_path, 'compressed_files')

    if force_download is True:
        if lfs.exists(compressed_dir_path):
            print 'Remove compressed directory ', compressed_dir_path
            lfs.remove(compressed_dir_path)
            for names in uris.itervalues():
                for (name, ext) in names:
                    path = join(test_path, name)
                    if lfs.exists(path):
                        print 'Remove %s file' % path
                        lfs.remove(path)

    # test directory
    if lfs.exists(test_path) is False:
        lfs.make_folder(test_path)

    # compressed directory
    if lfs.exists(compressed_dir_path) is False:
        lfs.make_folder(compressed_dir_path)
    else:
        lfs.open(compressed_dir_path)

    test_dir_filenames = lfs.get_names(test_path)
    for base_uri, names in uris.iteritems():
        for (name, ext) in names:
            if test_dir_filenames.count(name):
                continue
            compressed_dest = join(compressed_dir_path, '%s%s' % (name, ext))
            # check if tarball already exists
            if lfs.exists(compressed_dest) is False:
                src = join(base_uri, '%s%s' % (name, ext))
                print 'GET %s file' % src
                dest = join(test_path, name)
                if vfs.exists(src) is False:
                    print "%s uri does not exists" % src
                    continue
                src_file = vfs.open(src)
                # save Gzip file
                compressed_dest_file = lfs.make_file(compressed_dest)
                compressed_dest_file.write(src_file.read())
                compressed_dest_file.close()
                src_file.close()
            print 'Extract file %s' % compressed_dest
            # Uncompressed File Path
            if name == 'xmlts20080205':
                # uncompress only xmlconf.xml file
                tar = open_tar(compressed_dest)
                xmlconf_file = tar.extractfile('xmlconf/xmlconf.xml')
                ucf_path = join(test_path, name)
                ucf_file = lfs.make_file(ucf_path)
                ucf_file.write(xmlconf_file.read())
                ucf_file.close()
            else:
                # untar Gzip file
                compressed_dest_file = lfs.open(compressed_dest)
                gzip_file = GzipFile(compressed_dest)
                ucf_path = join(test_path, name)
                ucf_file = lfs.make_file(ucf_path)
                ucf_file.write(gzip_file.read())
                compressed_dest_file.close()
                gzip_file.close()
                ucf_file.close()

    tests = []
    # update test dir name
    test_dir_filenames = lfs.get_names(test_path)
    for filename in test_dir_filenames:
        real_path = join(test_path, filename)
        if lfs.is_file(real_path):
            bytes = lfs.get_size(real_path)
            tests.append((real_path, filename, bytes,
                          get_string_size(bytes)))
    tests.sort(key=lambda x: x[2])
    return tests
Пример #11
0
 def test_get_names(self):
     self.assertEqual('hello.txt' in lfs.get_names('tests'), True)
Пример #12
0
 def test_get_names(self):
     self.assertEqual('hello.txt' in lfs.get_names('tests'), True)
Пример #13
0
 def ea_language(self):
     path = get_abspath('ui/editarea/langs')
     languages = [x[:-3] for x in lfs.get_names(path)]
     return get_context().accept_language.select_language(languages)
Пример #14
0
 def rte_language(self):
     path = get_abspath('ui/tiny_mce/langs')
     languages = [x[:-3] for x in lfs.get_names(path)]
     return get_context().accept_language.select_language(languages)
Пример #15
0
 def __init__(self, uri):
     for key in lfs.get_names(uri):
         if key[-3:] == '.mo':
             language = key[:-3]
             path = '{0}/{1}'.format(uri, key)
             self[language] = MOFile(path)
Пример #16
0
 def __init__(self, uri):
     for key in lfs.get_names(uri):
         if key[-3:] == '.mo':
             language = key[:-3]
             path = '{0}/{1}'.format(uri, key)
             self[language] = MOFile(path)