import tempfile

from torii import Torii

t = Torii(base_url='https://localhost:8443/torii', username='hpcgadmin', password='hpcgadmin')
applications = t.applications.import_application(path='/opt/hpcg_sogeti/sogeti/plugins/apps/*/src', force=True)

print('{0} applications imported : '.format(len(applications)))
for application in applications:
    print('    - {0} {0}'.format(application, application.validationScript[0:20] if application.validationScript else '(No validation)'))

    if application.validationScript:
        app = application

tmpdir = tempfile.mkdtemp()
#app = t.applications.list()[0]

t.applications.export_application(app.id, dir=tmpdir, zip=False)

app_reimp = t.applications.import_application(path=tmpdir + '/*', force=True)

print(app_reimp.validationScript)