コード例 #1
0
ファイル: admin.py プロジェクト: CzechErface/web2py
def plugin_install(app, fobj, request, filename):
    """Installs a plugin:

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

    Args:
        app(str): 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:
        name of the file where plugin is temporarily stored
        or `False` on failure

    """
    upname = apath('../deposit/%s' % filename, request)

    try:
        write_file(upname, fobj.read(), 'wb')
        path = apath(app, request)
        w2p_unpack_plugin(upname, path)
        fix_newlines(path)
        return upname
    except Exception:
        os.unlink(upname)
        return False
コード例 #2
0
def plugin_install(app, fobj, request, filename):
    """Installs a plugin:

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

    Args:
        app(str): 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:
        name of the file where plugin is temporarily stored
        or `False` on failure

    """
    upname = apath('../deposit/%s' % filename, request)

    try:
        write_file(upname, fobj.read(), 'wb')
        path = apath(app, request)
        w2p_unpack_plugin(upname, path)
        fix_newlines(path)
        return upname
    except Exception:
        os.unlink(upname)
        return False
コード例 #3
0
ファイル: admin.py プロジェクト: Jbaumotte/web2py
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:
        write_file(upname, fobj.read(), 'wb')
        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
ファイル: admin.py プロジェクト: ducmanh86/web2py
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:
        write_file(upname, fobj.read(), 'wb')
        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
コード例 #5
0
def update_w2p_tvseries(w2p_folder, version):
    if raw_input('Q:    Update/download app from internet ([Y]/n)?').lower() in ['y', 'yes']:
        version = '.'.join([str(a) for a in version])
        print '  INFO: Downloading version %s' % version
        w2p_tvseries_url = 'https://github.com/niphlod/w2p_tvseries/zipball/%s' % version

        destfolder = os.path.normpath(os.path.abspath(os.path.join(w2p_folder, 'deposit', '%s' % datetime.datetime.now().strftime('%f'))))
        if not os.path.exists(destfolder):
            os.makedirs(destfolder)
        if not download(w2p_tvseries_url, zipball):
            print '  ERROR: Problems downloading from github, please try again later'
            wait_and_exit(1)

        print '  INFO: unzipping into %s' % destfolder
        extract(zipball, destfolder)
        if not os.listdir(destfolder):
            print '  ERROR: Problems downloading or extracting, Aborting auto-install'
            wait_and_exit(1)
        sourcefolder = os.path.abspath(os.path.join(destfolder, os.listdir(destfolder)[0]))
        appbckfolder = os.path.abspath(os.path.join(w2p_folder, 'applications', 'w2p_tvseries_bck'))
        finalfolder = os.path.abspath(os.path.join(w2p_folder, 'applications', 'w2p_tvseries'))

        if os.path.exists(appbckfolder):
            print '  INFO: cleaning %s' % appbckfolder
            recursive_unlink(appbckfolder)

        if os.path.exists(finalfolder):
            print '  INFO: backupping current from %s to %s' % (finalfolder, appbckfolder)
            shutil.copytree(finalfolder, appbckfolder)

        print '  INFO: overwriting %s with %s' % (finalfolder, sourcefolder)
        overwrite(sourcefolder, finalfolder)

        print '  INFO: cleaning %s' % (destfolder)
        recursive_unlink(destfolder)

        print '  INFO: fixing newlines in %s' % (finalfolder)
        fix_newlines(finalfolder)

        print '  INFO: updating static files with latest version'
        sourcefile = os.path.abspath(os.path.join(w2p_folder, 'applications', 'welcome' , 'static', 'js', 'web2py.js'))
        destfile = os.path.abspath(os.path.join(finalfolder, 'static', 'js', 'web2py.js'))
        os.unlink(destfile)
        shutil.copy(sourcefile, destfile)
コード例 #6
0
ファイル: admin.py プロジェクト: bmiklautz/web2py
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.

    Args:
        app(str): new application name
        fobj(obj): file object containing the application to be installed
        request: the global request object
        filename(str): original filename of the `fobj`,
            required to determine extension
        overwrite(bool): force overwrite of existing application

    Returns:
        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:
        with open(upname, 'wb') as appfp:
            copyfileobj(fobj, appfp, 4194304)  # 4 MB buffer
        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
コード例 #7
0
ファイル: admin.py プロジェクト: web2py/web2py
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.

    Args:
        app(str): new application name
        fobj(obj): file object containing the application to be installed
        request: the global request object
        filename(str): original filename of the `fobj`,
            required to determine extension
        overwrite(bool): force overwrite of existing application

    Returns:
        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:
        with open(upname, 'wb') as appfp:
            copyfileobj(fobj, appfp, 4194304) # 4 MB buffer
        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
コード例 #8
0
ファイル: admin.py プロジェクト: nicozanf/web2py
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.

    Args:
        app(str): new application name
        fobj(obj): file object containing the application to be installed
        request: the global request object
        filename(str): original filename of the `fobj`,
            required to determine extension
        overwrite(bool): force overwrite of existing application

    Returns:
        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:
        write_file(upname, fobj.read(), "wb")
        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
コード例 #9
0
ファイル: default.py プロジェクト: huiker/web2py
def site():
    """ Site handler """

    myversion = request.env.web2py_version

    # Shortcut to make the elif statements more
    # legible
    file_or_appurl = request.vars.has_key('file') or \
                     request.vars.has_key('appurl')

    if request.vars.filename and not request.vars.has_key('file'):
        try:
            appname = cleanpath(request.vars.filename).replace('.', '_')
            path = apath(appname)
            os.mkdir(path)
            untar('welcome.tar', path)
            response.flash = T('new application "%(appname)s" created',
                               dict(appname=appname))
        except Exception:
            response.flash = \
                T('unable to create new application "%(appname)s"',
                  dict(appname=request.vars.filename))

    elif file_or_appurl and not request.vars.filename:
        msg = 'you must specify a name for the uploaded application'
        response.flash = T(msg)

    elif file_or_appurl and request.vars.filename:
        mkdir = False

        try:
            appname = cleanpath(request.vars.filename).replace('.', '_')
            tarname = apath('../deposit/%s.tar' % appname)

            if request.vars.appurl is not '':
                tarfile = urllib.urlopen(request.vars.appurl).read()
            elif request.vars.file is not '':
                tarfile = request.vars.file.file.read()

            open(tarname, 'wb').write(tarfile)
            path = apath(appname)
            os.mkdir(path)
            mkdir = True
            untar(tarname, path)
            fix_newlines(path)

            msg = 'application %(appname)s installed with md5sum: %(digest)s'
            response.flash = T(msg,
                               dict(appname=appname, digest=md5_hash(tarfile)))
        except Exception:
            if mkdir:
                shutil.rmtree(path)

            msg = 'unable to install application "%(appname)s"'
            response.flash = T(msg, dict(appname=request.vars.filename))

    regex = re.compile('^\w+$')
    apps = sorted([(file.upper(), file) for file in os.listdir(apath())
                   if regex.match(file)])
    apps = [item[1] for item in apps]

    return dict(app=None, apps=apps, myversion=myversion)
コード例 #10
0
 def test_fix_newlines(self):
     fix_newlines(os.path.dirname(os.path.abspath(__file__)))
コード例 #11
0
ファイル: test_fileutils.py プロジェクト: BuhtigithuB/web2py
 def test_fix_newlines(self):
     fix_newlines(os.path.dirname(os.path.abspath(__file__)))
コード例 #12
0
ファイル: default.py プロジェクト: dspiteself/web2py
def site():
    """ Site handler """

    myversion = request.env.web2py_version

    # Shortcut to make the elif statements more
    # legible
    file_or_appurl = request.vars.has_key('file') or \
                     request.vars.has_key('appurl')

    if request.vars.filename and not request.vars.has_key('file'):
        try:
            appname = cleanpath(request.vars.filename).replace('.', '_')
            path = apath(appname)
            os.mkdir(path)
            untar('welcome.tar', path)
            response.flash = T('new application "%(appname)s" created',
                               dict(appname=appname))
        except Exception:
            response.flash = \
                T('unable to create new application "%(appname)s"',
                  dict(appname=request.vars.filename))

    elif file_or_appurl and not request.vars.filename:
        msg = 'you must specify a name for the uploaded application'
        response.flash = T(msg)

    elif file_or_appurl and request.vars.filename:
        mkdir = False

        try:
            appname = cleanpath(request.vars.filename).replace('.', '_')
            tarname = apath('../deposit/%s.tar' % appname)

            if request.vars.appurl is not '':
                tarfile = urllib.urlopen(request.vars.appurl).read()
            elif request.vars.file is not '':
                tarfile = request.vars.file.file.read()

            open(tarname, 'wb').write(tarfile)
            path = apath(appname)
            os.mkdir(path)
            mkdir = True
            untar(tarname, path)
            fix_newlines(path)

            msg = 'application %(appname)s installed with md5sum: %(digest)s'
            response.flash = T(msg, dict(appname=appname,
                                         digest=md5_hash(tarfile)))
        except Exception:
            if mkdir:
                shutil.rmtree(path)

            msg = 'unable to install application "%(appname)s"'
            response.flash = T(msg, dict(appname=request.vars.filename))

    regex = re.compile('^\w+$')
    apps = sorted([(file.upper(), file) for file in os.listdir(apath())
                                        if regex.match(file)])
    apps = [item[1] for item in apps]

    return dict(app=None, apps=apps, myversion=myversion)