Exemplo n.º 1
0
 def validate_credentials(self, username, password):
     """
     to use basic login with a different server
     from gluon.contrib.login_methods.basic_auth import basic_auth
     auth.settings.login_methods.append(basic_auth('http://server'))
     """
     key = base64.b64encode(username + ':' + password)
     headers = {'Authorization': 'Basic ' + key}
     request = urllib2.Request(self.server, None, headers)
     try:
         urlopen(request)
         return True
     except (urllib2.URLError, urllib2.HTTPError):
         return False
Exemplo n.º 2
0
Arquivo: admin.py Projeto: fc7/web2py
def check_new_version(myversion, version_url):
    """Compares current web2py's version with the latest stable web2py version.

    Args:
        myversion: the current version as stored in file `web2py/VERSION`
        version_URL: the URL that contains the version
                     of the latest stable release

    Returns:
        tuple: state, version

        - state : `True` if upgrade available, `False` if current
          version is up-to-date, -1 on error
        - version : the most up-to-version available

    """
    try:
        version = to_native(urlopen(version_url).read())
        pversion = parse_version(version)
        pmyversion = parse_version(myversion)
    except IOError:
        import traceback
        print(traceback.format_exc())
        return -1, myversion

    if pversion[:3] + pversion[-6:] > pmyversion[:3] + pmyversion[-6:]:
        return True, version
    else:
        return False, version
Exemplo n.º 3
0
Arquivo: admin.py Projeto: fc7/web2py
def upgrade(request, url='http://web2py.com'):
    """Upgrades web2py (src, osx, win) if a new version is posted.
    It detects whether src, osx or win is running and downloads the right one

    Args:
        request: the current request object
            (required to determine version and path)
        url: the incomplete url where to locate the latest web2py
             (actual url is url+'/examples/static/web2py_(src|osx|win).zip')

    Returns
        tuple: completed, traceback

        - completed: True on success, False on failure
          (network problem or old version)
        - traceback: None on success, raised exception details on failure

    """
    web2py_version = request.env.web2py_version
    gluon_parent = request.env.gluon_parent
    if not gluon_parent.endswith('/'):
        gluon_parent += '/'
    (check, version) = check_new_version(web2py_version,
                                         url + '/examples/default/version')
    if not check:
        return False, 'Already latest version'
    if os.path.exists(os.path.join(gluon_parent, 'web2py.exe')):
        version_type = 'win'
        destination = gluon_parent
        subfolder = 'web2py/'
    elif gluon_parent.endswith('/Contents/Resources/'):
        version_type = 'osx'
        destination = gluon_parent[:-len('/Contents/Resources/')]
        subfolder = 'web2py/web2py.app/'
    else:
        version_type = 'src'
        destination = gluon_parent
        subfolder = 'web2py/'

    full_url = url + '/examples/static/web2py_%s.zip' % version_type
    filename = abspath('web2py_%s_downloaded.zip' % version_type)
    try:
        write_file(filename, urlopen(full_url).read(), 'wb')
    except Exception as e:
        return False, e
    try:
        unzip(filename, destination, subfolder)
        return True, None
    except Exception as e:
        return False, e