Пример #1
0
    def __init__(self, path, size_min=4800, size_max=5200):
        # 1. Keep the path
        if not lfs.is_folder(path):
            error = '"%s" should be a folder, but it is not' % path
            raise ValueError, error

        folder = lfs.open(path)
        self.path = str(folder.path)

        # 2. Keep the path to the data
        self.path_data = '%s/database/' % self.path
        if not lfs.is_folder(self.path_data):
            error = '"%s" should be a folder, but it is not' % self.path_data
            raise ValueError, error

        # 3. Initialize the database, but chrooted
        self.fs = lfs.open(self.path_data)

        # 4. New interface to Git
        self.worktree = open_worktree(self.path_data)

        # 5. A mapping from key to handler
        self.cache = LRUCache(size_min, size_max, automatic=False)

        # 6. The git cache
        self.git_cache = LRUCache(900, 1100)
Пример #2
0
    def __init__(self, path, size_min=4800, size_max=5200):
        # 1. Keep the path
        if not lfs.is_folder(path):
            error = '"%s" should be a folder, but it is not' % path
            raise ValueError, error

        folder = lfs.open(path)
        self.path = str(folder.path)

        # 2. Keep the path to the data
        self.path_data = '%s/database/' % self.path
        if not lfs.is_folder(self.path_data):
            error = '"%s" should be a folder, but it is not' % self.path_data
            raise ValueError, error

        # 3. Initialize the database, but chrooted
        self.fs = lfs.open(self.path_data)

        # 4. New interface to Git
        self.worktree = open_worktree(self.path_data)

        # 5. A mapping from key to handler
        self.cache = LRUCache(size_min, size_max, automatic=False)

        # 6. The git cache
        self.git_cache = LRUCache(900, 1100)
Пример #3
0
def make_version(cwd='.'):
    """This function finds out the version number from the source, this will
    be written to the 'version.txt' file, which will be read once the software
    is installed to get the version number.
    """
    worktree = open_worktree(cwd)
    # The name of the active branch
    branch = worktree.get_branch_name()
    if branch is None:
        return None

    # The tag
    description = worktree.git_describe()

    # The version name
    if description:
        tag, n, commit = description
        if tag.startswith(branch):
            version = tag
        else:
            version = '%s-%s' % (branch, tag)
        # Exact match
        if n == 0:
            return version
    else:
        version = branch

    # Get the timestamp
    head = worktree.get_metadata()
    timestamp = head['committer_date']
    timestamp = timestamp.strftime('%Y%m%d%H%M')
    return '%s-%s' % (version, timestamp)
Пример #4
0
def build(path, config, environment):
    # Get version path
    package_root = config.get_value('package_root')
    version_txt = get_file_path(package_root, 'version.txt')
    # Get git worktree
    try:
        worktree = open_worktree(path)
    except KeyError:
        worktree = None
    # If not in a git repostory, get package version
    if worktree is None:
        return get_package_version(package_root)
    # Find out the version string
    version = make_version(worktree)
    # Initialize the manifest file (ignore links & submodules)
    manifest = set([ x for x in get_manifest() if not islink(x) and not isdir(x)])
    manifest.add('MANIFEST')
    # Write version
    open(path + version_txt, 'w').write(version)
    print '**'*30
    print '* Version:', version
    manifest.add(version_txt)
    # Write environment.json file
    environment_json = get_file_path(package_root, 'environment.json')
    environment_kw = {'build_path': path, 'environment': environment}
    open(path + environment_json, 'w').write(dumps(environment_kw))
    manifest.add(environment_json)
    print '* Build environment.json'
    # Run gulp
    if environment == 'production':
        gulp_builder = GulpBuilder(package_root, worktree, manifest)
        gulp_builder.run()
        # Rules
        from itools.html import XHTMLFile, HTMLFile
        rules = [('.po', '.mo', po2mo, None)]
        # Pre-load PO files
        po_files = {}
        for dst_lang in config.get_value('target_languages'):
            po = POFile('%s/locale/%s.po' % (package_root, dst_lang))
            po_files[dst_lang] = po
        # Templates
        src_lang = config.get_value('source_language', default='en')
        for dst_lang in config.get_value('target_languages'):
            rules.append(
                ('.xml.%s' % src_lang, '.xml.%s' % dst_lang, make_template, XHTMLFile))
            rules.append(
                ('.xhtml.%s' % src_lang, '.xhtml.%s' % dst_lang, make_template, XHTMLFile))
            rules.append(
                ('.html.%s' % src_lang, '.html.%s' % dst_lang, make_template, HTMLFile))
        # Make
        make(worktree, rules, manifest, package_root, po_files)
    # Write the manifest
    lines = [ x + '\n' for x in sorted(manifest) ]
    open(path + 'MANIFEST', 'w').write(''.join(lines))
    print '* Build MANIFEST file (list of files to install)'
    print '**'*30
    return version
Пример #5
0
def make_git_database(path, size_min, size_max, fields=None):
    """Create a new empty Git database if the given path does not exists or
    is a folder.

    If the given path is a folder with content, the Git archive will be
    initialized and the content of the folder will be added to it in a first
    commit.
    """
    path = lfs.get_absolute_path(path)
    # Git init
    open_worktree('%s/database' % path, init=True)
    # The catalog
    if fields is None:
        fields = get_register_fields()
    catalog = make_catalog('%s/catalog' % path, fields)
    # Ok
    database = RWDatabase(path, size_min, size_max)
    database.catalog = catalog
    return database
Пример #6
0
def make_git_database(path, size_min, size_max, fields=None):
    """Create a new empty Git database if the given path does not exists or
    is a folder.

    If the given path is a folder with content, the Git archive will be
    initialized and the content of the folder will be added to it in a first
    commit.
    """
    path = lfs.get_absolute_path(path)
    # Git init
    open_worktree('%s/database' % path, init=True)
    # The catalog
    if fields is None:
        fields = get_register_fields()
    catalog = make_catalog('%s/catalog' % path, fields)
    # Ok
    database = RWDatabase(path, size_min, size_max)
    database.catalog = catalog
    return database
Пример #7
0
def get_manifest():
    worktree = open_worktree('.', soft=True)
    if worktree:
        exclude = frozenset(['.gitignore'])
        return [ x for x in worktree.get_filenames() if x not in exclude ]

    # No git: find out source files
    config = get_config()
    target_languages = config.get_value('target_languages')

    exclude = frozenset(['.git', 'build', 'dist'])
    bad_files = compile('.*(~|pyc|%s)$' % '|'.join(target_languages))
    return get_files(exclude, filter=lambda x: not bad_files.match(x))
Пример #8
0
def build(path, config, environment):
    # Get version path
    package_root = config.get_value('package_root')
    version_txt = get_file_path(package_root, 'version.txt')
    try:
        # Get git worktree
        worktree = open_worktree(path)
    except KeyError:
        # Not in a git repostory
        return get_package_version(package_root)
    # Find out the version string
    version = make_version(worktree)
    # Initialize the manifest file (ignore links & submodules)
    manifest = set(
        [x for x in get_manifest() if not islink(x) and not isdir(x)])
    manifest.add('MANIFEST')
    # Write version
    open(path + version_txt, 'w').write(version)
    print '**' * 30
    print '* Version:', version
    manifest.add(version_txt)
    # Write environment.json file
    environment_json = get_file_path(package_root, 'environment.json')
    environment_kw = {'build_path': path, 'environment': environment}
    open(path + environment_json, 'w').write(dumps(environment_kw))
    manifest.add(environment_json)
    print '* Build environment.json'
    # Run gulp
    if environment == 'production':
        gulp_builder = GulpBuilder(worktree, manifest)
        gulp_builder.run()
        # Rules
        from itools.html import XHTMLFile, HTMLFile
        rules = [('.po', '.mo', po2mo, None)]
        # Templates
        src_lang = config.get_value('source_language', default='en')
        for dst_lang in config.get_value('target_languages'):
            rules.append(('.xml.%s' % src_lang, '.xml.%s' % dst_lang,
                          make_template, XHTMLFile))
            rules.append(('.xhtml.%s' % src_lang, '.xhtml.%s' % dst_lang,
                          make_template, XHTMLFile))
            rules.append(('.html.%s' % src_lang, '.html.%s' % dst_lang,
                          make_template, HTMLFile))
        # Make
        make(worktree, rules, manifest, package_root)
    # Write the manifest
    lines = [x + '\n' for x in sorted(manifest)]
    open(path + 'MANIFEST', 'w').write(''.join(lines))
    print '* Build MANIFEST file (list of files to install)'
    print '**' * 30
    return version
Пример #9
0
def build(path, config, environment):
    # Get version path
    package_root = config.get_value('package_root')
    version_txt = get_file_path(package_root, 'version.txt')
    # Get git worktree
    try:
        worktree = open_worktree(path)
    except KeyError:
        worktree = None
    # If not in a git repostory, get package version
    if worktree is None:
        return get_package_version(package_root)
    # Find out the version string
    version = make_version(worktree)
    # Initialize the manifest file (ignore links & submodules)
    manifest = set(
        [x for x in get_manifest() if not islink(x) and not isdir(x)])
    manifest.add('MANIFEST')
    # Write version
    open(path + version_txt, 'w').write(version)
    print '**' * 30
    print '* Version:', version
    manifest.add(version_txt)
    # Write environment.json file
    environment_json = get_file_path(package_root, 'environment.json')
    environment_kw = {'build_path': path, 'environment': environment}
    open(path + environment_json, 'w').write(dumps(environment_kw))
    manifest.add(environment_json)
    print '* Build environment.json'
    # Run gulp
    if environment == 'production':
        gulp_builder = GulpBuilder(package_root, worktree, manifest)
        gulp_builder.run()
        # Rules
        ipkg_build(worktree, manifest, config)
    # Write the manifest
    lines = [x + '\n' for x in sorted(manifest)]
    open(path + 'MANIFEST', 'w').write(''.join(lines))
    print '* Build MANIFEST file (list of files to install)'
    print '**' * 30
    return version
Пример #10
0
def build(config):
    # Get version path
    package_root = config.get_value('package_root')
    version_txt = get_package_version_path(package_root)
    try:
        # Get git worktree
        worktree = open_worktree('.')
    except KeyError:
        # Not in a git repostory
        return get_package_version(package_root)
    # Find out the version string
    version = make_version(worktree)
    # Initialize the manifest file
    manifest = set([ x for x in get_manifest() if not islink(x) ])
    manifest.add('MANIFEST')
    # Write version
    open(version_txt, 'w').write(version)
    print '* Version:', version
    manifest.add(version_txt)
    # (3) Rules
    rules = [('.po', '.mo', po2mo)]
    # Templates
    src_lang = config.get_value('source_language', default='en')
    for dst_lang in config.get_value('target_languages'):
        rules.append(
            ('.xml.%s' % src_lang, '.xml.%s' % dst_lang, make_template))
        rules.append(
            ('.xhtml.%s' % src_lang, '.xhtml.%s' % dst_lang, make_template))
    # (4) Make
    make(worktree, rules, manifest)
    # (5) Run gulp
    gulp_builder = GulpBuilder(worktree, manifest)
    gulp_builder.run()
    # (6) Write the manifest
    lines = [ x + '\n' for x in sorted(manifest) ]
    open('MANIFEST', 'w').write(''.join(lines))
    print '* Build MANIFEST file (list of files to install)'
    return version
Пример #11
0
def get_manifest():
    from git import open_worktree

    worktree = open_worktree('.')
    exclude = frozenset(['.gitignore'])
    return [ x for x in worktree.get_filenames() if x not in exclude ]
Пример #12
0
def get_manifest():
    worktree = open_worktree('.')
    exclude = frozenset(['.gitignore'])
    return [ x for x in worktree.get_filenames() if x not in exclude ]
Пример #13
0
def get_manifest():
    worktree = open_worktree('.')
    return [x for x in worktree.get_filenames() if not x.startswith('.')]