def is_version_latest(self): try: resp = requests.get('https://raw.githubusercontent.com/PaytmLabs/nerve/master/version.py', timeout=10) repo_ver = resp.text.split("'")[1].replace('.', '') curr_ver = VERSION.replace('.', '').replace('\'', '') if int(repo_ver) > int(curr_ver): return False return True except: return True
def push(url, post_data, user, pswd, verbose=False, type="GET", con=None, retcon=False): if verbose: print url, post_data con = con or pycurl.Curl() string_s = StringIO.StringIO() header_s = StringIO.StringIO() if post_data and type == "POST": con.setopt(pycurl.POST, 1) con.setopt(pycurl.POSTFIELDS, urllib.urlencode(post_data)) else: con.setopt(pycurl.POST, 0) if post_data: url += "?" + "&".join(["%s=%s" % (k, v) for k, v in post_data.items()]) if verbose: con.setopt(pycurl.VERBOSE, 1) basicheader = base64.b64encode(user + ":" + pswd) con.setopt(pycurl.HTTPHEADER, ["Authorization: Basic %s" % basicheader]) con.setopt(pycurl.USERAGENT, "OrionVM CLI bindings version %s" % VERSION) con.setopt(pycurl.FOLLOWLOCATION, False) con.setopt(pycurl.SSL_VERIFYPEER, 1) con.setopt(pycurl.SSL_VERIFYHOST, 2) con.setopt(pycurl.SSLVERSION, 3) con.setopt(pycurl.WRITEFUNCTION, string_s.write) con.setopt(pycurl.HEADERFUNCTION, header_s.write) con.setopt(pycurl.URL, url) con.perform() page = string_s.getvalue() retcode = con.getinfo(pycurl.HTTP_CODE) if retcode != 200: raise CurlException("API error %s" % retcode, retcode, response=page) header = header_s.getvalue() header = dict([[x.strip() for x in line.split(":", 1)] for line in header.split("\n") if ":" in line]) if "Server" not in header: raise Exception("Bad http header - No server information") s_version = re.match(".* v([0-9]+).([0-9]+)(?:.([0-9]+))?", header["Server"]) if s_version: major, minor, patch = [int(x and x or 0) for x in s_version.groups()] Major, Minor, Patch = [int(x) for x in VERSION.split(".", 2)] if Major != major: raise Exception("API and ovm-ctl versions do not match. Please update ovm-ctl or contact OrionVM") else: raise Exception("Bad http header - bad server information") if not retcon: return page return page, con
def warn_if_slow(f): if VERSION.endswith("-dev"): def new_f(*args, **keywords): t = time.time() r = f(*args, **keywords) if time.time() - t >= .1: warning("%s took %s seconds!", f.__name__, time.time() - t) return r else: new_f = f return new_f
def increment_release(rel_type='patch', new_number=None): (major, minor, patch) = VERSION.split('.') if rel_type is 'minor': minor = int(minor)+1 elif rel_type is 'major': major = int(major)+1 else: # Increment patch by default or if unknown patch = int(patch)+1 new_num = '{major}.{minor}.{patch}'.format(major=major, minor=minor, patch=patch) with open('version.py', 'w') as f: f.write("VERSION='%s'" % new_num) print 'New version is now: %s' % new_num return new_num
def __init__(self): short_version = '.'.join(VERSION.split('.', 2)[:2]) demo_server = 'demo%s.tryton.org' % short_version demo_database = 'demo%s' % short_version form_tab = 'left' if os.name != 'nt' else 'top' self.defaults = { 'login.profile': demo_server, 'login.login': '******', 'login.server': demo_server, 'login.port': '8000', 'login.db': demo_database, 'login.expanded': False, 'tip.autostart': False, 'tip.position': 0, 'logging.logger': '', 'logging.level': 'ERROR', 'logging.default': 'ERROR', 'form.toolbar': True, 'form.statusbar': True, 'client.default_width': 900, 'client.default_height': 750, 'client.modepda': False, 'client.toolbar': 'default', 'client.form_tab': form_tab, 'client.maximize': False, 'client.save_width_height': True, 'client.save_tree_expanded_state': True, 'client.spellcheck': False, 'client.default_path': get_home_dir(), 'client.lang': locale.getdefaultlocale()[0], 'client.language_direction': 'ltr', 'client.email': '', 'client.can_change_accelerators': False, 'client.limit': 1000, 'roundup.url': 'http://bugs.tryton.org/roundup/', 'roundup.xmlrpc': 'roundup-xmlrpc.tryton.org', 'menu.pane': 200, } self.config = {} self.options = { 'login.host': True } self.arguments = []
def __init__(self): short_version = '.'.join(VERSION.split('.', 2)[:2]) demo_server = 'demo%s.tryton.org' % short_version demo_database = 'demo%s' % short_version form_tab = 'left' if os.name != 'nt' else 'top' self.defaults = { 'login.profile': demo_server, 'login.login': '******', 'login.server': demo_server, 'login.port': '8000', 'login.db': demo_database, 'login.expanded': False, 'tip.autostart': False, 'tip.position': 0, 'form.toolbar': True, 'client.default_width': 900, 'client.default_height': 750, 'client.modepda': False, 'client.toolbar': 'default', 'client.form_tab': form_tab, 'client.maximize': False, 'client.save_width_height': True, 'client.save_tree_state': True, 'client.spellcheck': False, 'client.default_path': get_home_dir(), 'client.lang': locale.getdefaultlocale()[0], 'client.language_direction': 'ltr', 'client.email': '', 'client.can_change_accelerators': False, 'client.limit': 1000, 'roundup.url': 'http://bugs.tryton.org/roundup/', 'roundup.xmlrpc': 'roundup-xmlrpc.tryton.org', 'menu.pane': 200, 'menu.expanded': True, } self.config = {} self.options = { 'login.host': True } self.arguments = []
def get_config_dir(): if os.name == 'nt': return os.path.join(os.environ['APPDATA'], '.config', 'tryton', VERSION.rsplit('.', 1)[0]) return os.path.join(os.environ['HOME'], '.config', 'tryton', VERSION.rsplit('.', 1)[0])
import os from version import VERSION if __name__ == '__main__': base_path = os.path.dirname(os.path.abspath(__file__)) version_file = os.path.join(base_path, 'version.py') major, minor = VERSION.split('.') minor = int(minor) + 1 with open(version_file, 'w') as v_file: v_file.write("VERSION='%s.%s'" % (major, minor)) print("{}.{}".format(major, minor))
def get_config_dir(): return os.path.join( os.environ['HOME'], '.config', 'zeropos', VERSION.rsplit('.', 1)[0] )
def bryton_gpx_to_tcx(gpx, activity_type="ride", device=None, pretty=False): root = xml.Element(_ns("TrainingCenterDatabase")) root.set( _ns_xsi("schemaLocation"), """%s %s %s %s""" % ( "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2", "http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd", "http://www.garmin.com/xmlschemas/ActivityExtension/v2", "http://www.garmin.com/xmlschemas/ActivityExtensionv2.xsd", ), ) xml.register_namespace("a", _ACTIVITY_EXT_NS) xml.register_namespace("", _DEFAULT_NS) activities = xml.SubElement(root, _ns("Activities")) activity = xml.SubElement(activities, _ns("Activity")) if activity_type == "ride": activity.set(_ns("Sport"), "Biking") elif activity_type == "run": activity.set(_ns("Sport"), "Running") else: activity.set(_ns("Sport"), "Other") id = xml.SubElement(activity, _ns("Id")) id.text = gpx.getSummary()["start"] for lap in gpx.getTrackPoints(): lap_el = xml.SubElement(activity, _ns("Lap")) lap_el.set(_ns("StartTime"), lap["start"]) ride_time = xml.SubElement(lap_el, _ns("TotalTimeSeconds")) ride_time.text = str(float(lap["total_time"])) dist = xml.SubElement(lap_el, _ns("DistanceMeters")) dist.text = str(float(lap["distance"])) if "speed_max" in lap: max_speed = xml.SubElement(lap_el, _ns("MaximumSpeed")) max_speed.text = str(kph_to_ms(float(lap["speed_max"]))) cals = xml.SubElement(lap_el, _ns("Calories")) cals.text = str(lap["calories"]) if "hr_max" in lap: avg_hr = xml.SubElement(lap_el, _ns("AverageHeartRateBpm")) val = xml.SubElement(avg_hr, _ns("Value")) val.text = str(lap["hr_avg"]) max_hr = xml.SubElement(lap_el, _ns("MaximumHeartRateBpm")) val = xml.SubElement(max_hr, _ns("Value")) val.text = str(lap["hr_max"]) intensity = xml.SubElement(lap_el, _ns("Intensity")) intensity.text = "Active" if activity_type == "ride" and "cad_avg" in lap: cadence = xml.SubElement(lap_el, _ns("Cadence")) cadence.text = str(lap["cad_avg"]) trigger = xml.SubElement(lap_el, _ns("TriggerMethod")) trigger.text = "Manual" track = xml.SubElement(lap_el, _ns("Track")) # dist = 0.0 # prev = [] for point in lap["track_points"]: if point is None: # Track was paused track = xml.SubElement(lap_el, _ns("Track")) continue track_point = xml.SubElement(track, _ns("Trackpoint")) time = xml.SubElement(track_point, _ns("Time")) time.text = point["time"] if "lat" in point: pos = xml.SubElement(track_point, _ns("Position")) lat = xml.SubElement(pos, _ns("LatitudeDegrees")) lon = xml.SubElement(pos, _ns("LongitudeDegrees")) lat.text = str(point["lat"]) lon.text = str(point["lon"]) if "ele" in point: alt = xml.SubElement(track_point, _ns("AltitudeMeters")) alt.text = str(float(point["ele"])) # if 'lat' in point: # import math # from geopy import distance # if len(prev) >= 2: # # dist += round(geo_distance(prev['lat'], prev['lon'], point['lat'], point['lon']) * 1000.0, 3) # dist += distance.distance('%s;%s' % (prev[0]['lat'], prev[0]['lon']), '%s;%s' % (point['lat'], point['lon'])).m # prev.pop(0) # elif len(prev) > 0: # dist += distance.distance('%s;%s' % (prev[0]['lat'], prev[0]['lon']), '%s;%s' % (point['lat'], point['lon'])).m # # dist = round(dist, 1) # print math.floor(dist) # dist_el = xml.SubElement(track_point, _ns('DistanceMeters')) # dist_el.text = str(dist) # prev.append(point) if "hrm" in point: hr = xml.SubElement(track_point, _ns("HeartRateBpm")) val = xml.SubElement(hr, _ns("Value")) val.text = str(point["hrm"]) if "cad" in point and activity_type == "ride": cad = xml.SubElement(track_point, _ns("Cadence")) cad.text = str(point["cad"]) if "spd" in point or "pwr" in point or "cad" in point: ext = xml.SubElement(track_point, _ns("Extensions")) tpx = xml.SubElement(ext, _activity_ext_ns("TPX")) if "spd" in point: speed = xml.SubElement(tpx, _activity_ext_ns("Speed")) speed.text = str(kph_to_ms(point["spd"])) if "cad" in point and activity_type == "run": cad = xml.SubElement(tpx, _activity_ext_ns("RunCadence")) cad.text = str(point["cad"]) if "pwr" in point: pwr = xml.SubElement(tpx, _activity_ext_ns("Watts")) pwr.text = str(point["pwr"]) if "speed_avg" in lap or "cad_max" in lap: ext = xml.SubElement(lap_el, _ns("Extensions")) act_ext = xml.SubElement(ext, _activity_ext_ns("LX")) if "speed_avg" in lap: avg_speed = xml.SubElement(act_ext, _activity_ext_ns("AvgSpeed")) avg_speed.text = str(kph_to_ms(float(lap["speed_avg"]))) if "cad_max" in lap: if activity_type == "ride": max_cad = xml.SubElement(act_ext, _activity_ext_ns("MaxBikeCadence")) max_cad.text = str(lap["cad_max"]) elif activity_type == "run": max_cad = xml.SubElement(act_ext, _activity_ext_ns("MaxRunCadence")) max_cad.text = str(lap["cad_max"]) avg_cad = xml.SubElement(act_ext, _activity_ext_ns("AvgRunCadence")) avg_cad.text = str(lap["cad_avg"]) if "pwr_max" in lap: avg_pwr = xml.SubElement(act_ext, _activity_ext_ns("AvgWatts")) avg_pwr.text = str(lap["pwr_avg"]) max_pwr = xml.SubElement(act_ext, _activity_ext_ns("MaxWatts")) max_pwr.text = str(lap["pwr_max"]) if device is not None: # Except for the name i don't know what values to add here # so i just add some values from the BrytonBridge device info. creator = xml.SubElement(activity, _ns("Creator")) creator.set(_ns_xsi("type"), "Device_t") xml.SubElement(creator, _ns("Name")).text = "Bryton " + device["name"] unit_id = device["serial"][0:9] if not unit_id.isdigit(): unit_id = "98761235" xml.SubElement(creator, _ns("UnitId")).text = unit_id product_id = "" if "Rider" in device["name"]: product_id += "1" else: product_id += "2" num = re.search(r"\w+?(\d+)", device["name"]) product_id += num.group(1) if num is not None else "0" xml.SubElement(creator, _ns("ProductID")).text = product_id version = xml.SubElement(creator, _ns("Version")) v1 = re.search(r"\d+", device["rev"]) xml.SubElement(version, _ns("VersionMajor")).text = v1.group(0) if v1 is not None else "1" v2 = re.search(r"\d+", device["firmware"]) xml.SubElement(version, _ns("VersionMinor")).text = v2.group(0) if v2 is not None else "1" xml.SubElement(version, _ns("BuildMajor")).text = "0" xml.SubElement(version, _ns("BuildMinor")).text = "0" app = xml.SubElement(root, _ns("Author")) app.set(_ns_xsi("type"), "Application_t") xml.SubElement(app, _ns("Name")).text = "BrytonOffline" build = xml.SubElement(app, _ns("Build")) version = xml.SubElement(build, _ns("Version")) v1, v2 = VERSION.split(".")[0:2] xml.SubElement(version, _ns("VersionMajor")).text = v1 xml.SubElement(version, _ns("VersionMinor")).text = v2 xml.SubElement(version, _ns("BuildMajor")).text = "0" xml.SubElement(version, _ns("BuildMinor")).text = "0" xml.SubElement(build, _ns("Type")).text = "Release" xml.SubElement(app, _ns("LangID")).text = "EN" xml.SubElement(app, _ns("PartNumber")).text = "000-00000-00" if pretty: indent_element_tree(root) # Because of bugs in other software we need to replace # the "a" prefix with "ns3". # ElementTree didn't let me manually register the ns3 prefix, so i # need to replace it. return "<?xml version='1.0' encoding='utf-8'?>\n" + xml.tostring(root).replace("a:", "ns3:").replace( "xmlns:a", "xmlns:ns3" )