# -*- coding: utf-8 -*-

#
# Copyright (C) 2015-2016 Rodrigo Ramírez Norambuena <a@rodrigoramirez.com>
#

import requests
from distutils.version import LooseVersion
import os
import sys
import qpanel

dirname, filename = os.path.split(os.path.abspath(__file__))
ROOT_PATH = os.path.join(dirname, os.pardir, os.pardir)

BRANCH = 'stable'
REPO = 'git@github.com:roramirez/qpanel.git'
URL_STABLE_VERSION = 'https://rodrigoramirez.com/qpanel/version/' + BRANCH
VERSION_FILE = os.path.join(ROOT_PATH, 'VERSION')

def require_upgrade():
    return check_require_upgrade(get_current_version(), get_stable_version())


def check_require_upgrade(current, stable):
    a = LooseVersion(current)
    b = LooseVersion(stable)
    if a < b:
        return True
    return False


# InmplementME
def last_check_update():
    return True


def get_current_version():
    return qpanel.__version__

def get_stable_version(url=URL_STABLE_VERSION):
    stable_version = __get_data_url(url)
    return __first_line(stable_version)


def __get_data_url(url):
    req = requests.get(url)
    try:
        return req.text
    except:
        return None


def __first_line(content):
    tmp = ''
    if content is not None:
        tmp = content.splitlines()
    if len(tmp) >= 1:
        return tmp[0]
    return tmp

@@ -169,153 +169,15 @@
 ort 
-os%0Aimport sys%0Aimport qpanel%0A%0Adirname, filename = os.path.split(os.path.abspath(__file__))%0AROOT_PATH = os.path.join(dirname, os.pardir, os.pardir)
+qpanel%0A
 %0A%0ABR
@@ -316,57 +316,8 @@
 NCH%0A
-VERSION_FILE = os.path.join(ROOT_PATH, 'VERSION')
 %0A%0Ade
@@ -689,16 +689,17 @@
 sion__%0A%0A
+%0A
 def get_

remove code not used into upgrader module