Exemplo n.º 1
0
def check_for_overwrite(odt_file_url):
    if vfs.exists(odt_file_url):
        message = 'The file "%s" exists, can i overwrite it? [y/N]'
        stdout.write(message % odt_file_url)
        stdout.flush()
        line = stdin.readline()
        line = line.strip().lower()
        if line != 'y':
            stdout.write('Operation aborted\n')
            stdout.flush()
            exit(0)
Exemplo n.º 2
0
def get_target_directory(dirname):
    # Check the name and create the directory
    if vfs.exists(dirname):
        message = 'The directory "%s" exists, can i overwrite it? [y/N]'
        stdout.write(message % dirname)
        stdout.flush()
        line = stdin.readline()
        line = line.strip().lower()
        if line == 'y':
            vfs.remove(dirname)
        else:
            exit(0)
    vfs.make_folder(dirname)
    return vfs.open(dirname)
Exemplo n.º 3
0
from lpod.span import odf_create_span
from lpod.template import stl_odf
from lpod.vfs import vfs


def get_namespace(homme=False):
    return {u"titre": u"Test de STL no 1",
            u"date": date.today().strftime(u"%d/%m/%Y"),
            u"homme": homme,
            u"genre": u"M." if homme else u"Mme",
            u"nom": u"Michu",
            u"enum1": {'label': u"Revenu", 'value': 1234.56},
            u"enum2": {'label': u"Âge", 'value': 65},
            u"couleur": u"rouge",
            u"gras": u"gras comme un moine",
            u"élément": odf_create_span(u"élément", style='T2')}


if __name__ == '__main__':
    try:
        output = argv[1]
    except IndexError:
        print >>stderr, "Usage: %s <output document>" % argv[0]
        exit(1)
    document = odf_new_document_from_template('test_template.ott')
    stl_odf(document, get_namespace())
    if vfs.exists(output):
        vfs.remove(output)
    document.save(output)
    print 'Document "%s" generated.' % output
Exemplo n.º 4
0
    # Parse !
    opts, filenames = parser.parse_args()

    # Arguments
    if not filenames:
        parser.print_help()
        exit(1)
    output_filename = opts.output
    output_doc = None

    # Concatenate content in the output doc
    for filename in filenames:

        # Exists ?
        if not vfs.exists(filename):
            print "Skip", filename, "not existing"
            continue

        # A good file => Only text, spreadsheet and CSV
        mimetype = vfs.get_mimetype(filename)
        if mimetype not in ("application/vnd.oasis.opendocument.text",
                            "application/vnd.oasis.opendocument.spreadsheet",
                            "text/csv",
                            "application/vnd.oasis.opendocument.presentation"):
            print 'Skip "%s" with mimetype "%s"' % (filename, mimetype)
            continue

        # Not yet an output_doc ?
        if output_doc is None:
            # Create an empty doc