Пример #1
0
def app_create(app, request, force=False, key=None, info=False):
    """
    Create a copy of welcome.w2p (scaffolding) app

    Parameters
    ----------
    app:
        application name
    request:
        the global request object

    """
    path = apath(app, request)
    if not os.path.exists(path):
        try:
            os.mkdir(path)
        except:
            if info:
                return False, traceback.format_exc(sys.exc_info)
            else:
                return False
    elif not force:
        if info:
            return False, "Application exists"
        else:
            return False
    try:
        w2p_unpack('welcome.w2p', path)
        for subfolder in [
                'models', 'views', 'controllers', 'databases', 'modules',
                'cron', 'errors', 'sessions', 'cache', 'languages', 'static',
                'private', 'uploads'
        ]:
            subpath = os.path.join(path, subfolder)
            if not os.path.exists(subpath):
                os.mkdir(subpath)
        db = os.path.join(path, 'models', 'db.py')
        if os.path.exists(db):
            data = read_file(db)
            data = data.replace('<your secret key>',
                                'sha512:' + (key or web2py_uuid()))
            write_file(db, data)
        if info:
            return True, None
        else:
            return True
    except:
        rmtree(path)
        if info:
            return False, traceback.format_exc(sys.exc_info)
        else:
            return False
Пример #2
0
def app_create(app, request, force=False, key=None, info=False):
    """
    Create a copy of welcome.w2p (scaffolding) app

    Parameters
    ----------
    app:
        application name
    request:
        the global request object

    """
    path = apath(app, request)
    if not os.path.exists(path):
        try:
            os.mkdir(path)
        except:
            if info:
                return False, traceback.format_exc(sys.exc_info)
            else:
                return False
    elif not force:
        if info:
            return False, "Application exists"
        else:
            return False
    try:
        w2p_unpack('welcome.w2p', path)
        for subfolder in [
            'models', 'views', 'controllers', 'databases',
            'modules', 'cron', 'errors', 'sessions', 'cache',
            'languages', 'static', 'private', 'uploads']:
            subpath = os.path.join(path, subfolder)
            if not os.path.exists(subpath):
                os.mkdir(subpath)
        db = os.path.join(path, 'models', 'db.py')
        if os.path.exists(db):
            data = read_file(db)
            data = data.replace('<your secret key>',
                                'sha512:' + (key or web2py_uuid()))
            write_file(db, data)
        if info:
            return True, None
        else:
            return True
    except:
        rmtree(path)
        if info:
            return False, traceback.format_exc(sys.exc_info)
        else:
            return False
Пример #3
0
Файл: admin.py Проект: redb/MNPP
def app_install(app, fobj, request, filename, overwrite=None):
    """
    Installs an application:

    - Identifies file type by filename
    - Writes `fobj` contents to the `../deposit/` folder
    - Calls `w2p_unpack()` to do the job.

    Parameters
    ----------
    app:
        new application name
    fobj:
        file object containing the application to be installed
    request:
        the global request object
    filename:
        original filename of the `fobj`, required to determine extension

    Returns
    -------
    upname:
        name of the file where app is temporarily stored or `None` on failure
    """
    did_mkdir = False
    if filename[-4:] == '.w2p':
        extension = 'w2p'
    elif filename[-7:] == '.tar.gz':
        extension = 'tar.gz'
    else:
        extension = 'tar'
    upname = apath('../deposit/%s.%s' % (app, extension), request)

    try:
        upfile = open(upname, 'wb')
        upfile.write(fobj.read())
        upfile.close()
        path = apath(app, request)
        if not overwrite:
            os.mkdir(path)
            did_mkdir = True
        w2p_unpack(upname, path)
        if extension != 'tar':
            os.unlink(upname)
        fix_newlines(path)
        return upname
    except Exception:
        if did_mkdir:
            rmtree(path)
        return False
Пример #4
0
def app_create(app, request, force=False, key=None):
    """
    Create a copy of welcome.w2p (scaffolding) app

    Parameters
    ----------
    app:
        application name
    request:
        the global request object

    """
    did_mkdir = False
    try:
        path = apath(app, request)
        os.mkdir(path)
    except:
        if not force:
            return False
    try:
        w2p_unpack('welcome.w2p', path)
        for subfolder in [
                'models', 'views', 'controllers', 'databases', 'modules',
                'cron', 'errors', 'sessions', 'languages', 'static', 'private',
                'uploads'
        ]:
            subpath = os.path.join(path, subfolder)
            if not os.path.exists(subpath):
                os.mkdir(subpath)
        db = os.path.join(path, 'models', 'db.py')
        if os.path.exists(db):
            fp = open(db, 'r')
            data = fp.read()
            fp.close()
            data = data.replace('<your secret key>',
                                'sha512:' + (key or web2py_uuid()))
            fp = open(db, 'w')
            fp.write(data)
            fp.close()
        return True
    except:
        rmtree(path)
        return False
Пример #5
0
def app_create(app, request,force=False,key=None):
    """
    Create a copy of welcome.w2p (scaffolding) app

    Parameters
    ----------
    app:
        application name
    request:
        the global request object

    """
    did_mkdir = False
    try:
        path = apath(app, request)
        os.mkdir(path)
    except:
        if not force:
            return False
    try:
        w2p_unpack('welcome.w2p', path)
        for subfolder in ['models','views','controllers', 'databases',
                          'modules','cron','errors','sessions',
                          'languages','static','private','uploads']:
            subpath =  os.path.join(path,subfolder)
            if not os.path.exists(subpath):
                os.mkdir(subpath)
        db = os.path.join(path, 'models', 'db.py')
        if os.path.exists(db):
            fp = open(db,'r')
            data = fp.read()
            fp.close()
            data = data.replace('<your secret key>',
                                'sha512:'+(key or web2py_uuid()))
            fp = open(db,'w')
            fp.write(data)
            fp.close()
        return True
    except:
        rmtree(path)
        return False
Пример #6
0
def app_create(app, request, force=False, key=None, info=False):
    """
    Create a copy of welcome.w2p (scaffolding) app

    Parameters
    ----------
    app:
        application name
    request:
        the global request object

    """
    path = apath(app, request)
    if not os.path.exists(path):
        try:
            os.mkdir(path)
        except:
            if info:
                return False, traceback.format_exc(sys.exc_info)
            else:
                return False
    elif not force:
        if info:
            return False, "Application exists"
        else:
            return False
    try:
        w2p_unpack("welcome.w2p", path)
        for subfolder in [
            "models",
            "views",
            "controllers",
            "databases",
            "modules",
            "cron",
            "errors",
            "sessions",
            "cache",
            "languages",
            "static",
            "private",
            "uploads",
        ]:
            subpath = os.path.join(path, subfolder)
            if not os.path.exists(subpath):
                os.mkdir(subpath)
        db = os.path.join(path, "models", "db.py")
        if os.path.exists(db):
            data = read_file(db)
            data = data.replace("<your secret key>", "sha512:" + (key or web2py_uuid()))
            write_file(db, data)
        if info:
            return True, None
        else:
            return True
    except:
        rmtree(path)
        if info:
            return False, traceback.format_exc(sys.exc_info)
        else:
            return False
Пример #7
0
def app_create(db, app, request, force=False, key=None, info=False):
    """
    Create a copy of welcome.w2p (scaffolding) app

    Parameters
    ----------
    app:
        application name
    request:
        the global request object

    """
    path = apath(app, request)
    if not os.path.exists(path):
        try:
            os.mkdir(path)
        except:
            if info:
                return False, traceback.format_exc(sys.exc_info)
            else:
                return False, None
    elif not force:
        if info:
            return False, "Application exists"
        else:
            return False, None
    try:
        w2p_unpack('welcome.w2p', path)
        for subfolder in [
            'models', 'views', 'controllers', 'databases',
            'modules', 'cron', 'errors', 'sessions', 'cache',
            'languages', 'static', 'private', 'uploads']:
            subpath = os.path.join(path, subfolder)
            if not os.path.exists(subpath):
                os.mkdir(subpath)
        dbt = os.path.join(path, 'models', 'db.py')
        if os.path.exists(dbt):
            data = read_file(dbt)
            data = data.replace('<your secret key>',
                                'sha512:' + (key or web2py_uuid()))
            write_file(dbt, data)

        parms = db(db.parametros.id==1).select()[0]

        templates = os.path.join('\\\\'
                                , '127.0.0.1'
                                , 'c$'
                                , parms.web2py
                                , 'applications'
                                , parms.soag
                                , 'Template'
                                , 'web2py')

        for subfolder in ['controllers', 'languages', 'models', 'modules', 'static', 'views']:
            template = os.path.join(templates, subfolder)
            subpath = os.path.join(path, subfolder)
            shutil.rmtree(subpath)
            shutil.copytree(template, subpath)

#        shutil.copyfile(os.path.join(templates, 'routes.py'), os.path.join(path, 'routes.py'))

        if info:
            return True, None
        else:
            return True, None
    except:
        shutil.rmtree(path)
        if info:
            return False, traceback.format_exc(sys.exc_info)
        else:
            return False, None