def upload(self, session, title="", no_output=False, start_at=0, stop_at=None): # Stop at not implemented yet. if not self.uri: print "[-] No uri given!" return False elif not session.get_auth() and not session.new_token(): return False if start_at: self._index = start_at if not self.has_started_upload: self.has_started_upload = True self._index = start_at if os.path.isfile(self.uri): filename = os.path.basename(self.uri) file_info = os.stat(self.uri) self._file_size = file_info.st_size if not title: title = filename video_request = api.request('/video/request', session, data=dict( filename=filename, size=self._file_size, title=title, )) if not video_request: return False self._code = video_request['code'] if not no_output: print "[+] New Video Code:", self._code upload = api.request('/upload/create', session, data=dict( code=self._code, size=self._file_size, )) self._upload_id = upload['upload']['upload_id'] return self._upload(session, no_output) else: print "[-] Could not find file", self.uri else: return self._upload(session, no_output)
def setup(self, force=False): n7 = __addon__.getSetting("N7") warning = __addon__.getSetting("warning") if warning != 'done': dialog = xbmcgui.Dialog() info = dialog.yesno("N7 TV APP", _(30100), _(30101), _(30102), _(30103), _(30104)) if info: __addon__.setSetting("warning", "done") else: return False if n7 and not force: self.getControl( 205 ).setLabel( n7 ) if api.request(n7, api.DISCOVER, True): self.tuner = n7 log("N7 tuner ip loaded from cache: %s" % n7) return True else: dialog = xbmcgui.Dialog() dialog.ok(_(30114), _(30105) % (n7, )) #Automatic scan dialog = xbmcgui.Dialog() if dialog.yesno(_(30107), _(30108),_(30109), "", _(30110), _(30111)): scanner = api.scan() if scanner.run(): dialog = xbmcgui.Dialog() if len(scanner.n7) > 1: pos = dialog.select(_(30106), scanner.n7) n7 = scanner.n7[pos] else: n7 = scanner.n7[0] txt = _(30112) % n7 xbmc.executebuiltin("Notification(%s,%s,2)" % (__scriptname__ , txt)) __addon__.setSetting("N7", n7) self.tuner = n7 log("N7 tuner selected: %s" % n7) self.getControl( 205 ).setLabel( n7 ) del scanner return True else: xbmc.executebuiltin("Notification(%s,%s,2)" % (__scriptname__ ,_(30117))) #Manual IP n7 = dialog.numeric(3, _(30111)) if api.request(n7, api.DISCOVER, True): __addon__.setSetting("N7", n7) txt = _(30112) % n7 self.tuner = n7 self.getControl( 205 ).setLabel( n7 ) log("N7 tuner manually entered: %s" % n7) return True else: dialog.ok(_(30114), _(30105) % n7, _(30115)) __addon__.setSetting("N7", "") xbmc.sleep(3000) self.close()
def attribute(session, uuid, key, value=None): """ API call to get/set one site attribute """ payload = {'site': uuid, 'path': 'attributes/'+key} if value is None: return api.request(session, payload) else: return api.request(session, payload, 'PUT', value)
def service_level(session, uuid, value=None): """ API call to get/set site service level """ payload = {'site': uuid, 'path': 'service-level'} if value is None: return api.request(session, payload) else: return api.request(session, payload, 'PUT', value)
def attribute(session, uuid, key, value=None): """ API call to get/set one site attribute """ payload = {'site': uuid, 'path': 'attributes/' + key} if value is None: return api.request(session, payload) else: return api.request(session, payload, 'PUT', value)
def attributes(session, uuid, values=None): """ API call to get/set all site attributes at once """ payload = {'site': uuid, 'path': 'attributes'} if values is None: return api.request(session, payload) else: return api.request(session, payload, 'PUT', values)
def notifications(session, uuid, key=None, data=None): """ API call to get notifications for a site to track job status """ if key is None or data is None: payload = {'site': uuid, 'path': 'notifications'} return api.request(session, payload) else: payload = {'site': uuid, 'path': 'notifications/' + urllib.quote(key)} return api.request(session, payload, 'PUT', data)
def main(): data_study = { "author": "Aiko Yamashita", "description": "Context: Code smells are assumed to indicate bad design", # that leads to less maintainable code. However, this assumption has not been investigated in controlled studies with professional software developers. Aim: This paper investigates the relationship between code smells and maintenance effort. Method: Six developers were hired to perform three maintenance tasks each on four functionally equivalent Java systems originally implemented by different companies. Each developer spent three to four weeks. In total, they modified 298 Java files in the four systems. An Eclipse IDE plug-in measured the exact amount of time a developer spent maintaining each file. Regression analysis was used to explain the effort using file properties, including the number of smells. Result: None of the 12 investigated smells was significantly associated with increased effort after we adjusted for file size and the number of changes; Refused Bequest was significantly associated with decreased effort. File size and the number of changes explained almost all of the modeled variation in effort. Conclusion: The effects of the 12 smells on maintenance effort were limited. To reduce maintenance effort, a focus on reducing code size and the work practices that limit the number of changes may be more beneficial than refactoring code smells.", "id": "", "title": "Quantifying the effect of code smells on maintenance effort", "license": "" } api.request("Study", 'studies', data_study)
def onserver_status(session, uuid, environment, value=None): """ API call to get/set on-sserver development status """ payload = {'site': uuid, 'path': 'environments/'+environment+'/on-server-development'} if value is None: return api.request(session, payload) else: data = {'enabled': value} return api.request(session, payload, 'PUT', data)
def email(session, email=None): """ API call to get/set a user's email """ if email is None: payload = {'user': session.cookies.get('uuid'), 'path': 'email'} return api.request(session, payload) else: payload = {'user': session.cookies.get('uuid'), 'path': 'email'} return api.request(session, payload, 'PUT', email)
def notifications(session, uuid, key=None, data=None): """ API call to get notifications for a site to track job status """ if key is None or data is None: payload = {'site': uuid, 'path': 'notifications'} return api.request(session, payload) else: payload = {'site': uuid, 'path': 'notifications/'+urllib.quote(key)} return api.request(session, payload, 'PUT', data)
def attribute(session, attribute, value=None): """ API call to get/set a field from a user's profile """ if value is None: payload = {'user': session.cookies.get('uuid'), 'path': 'profile/'+attribute} return api.request(session, payload) else: payload = {'user': session.cookies.get('uuid'), 'path': 'profile/'+attribute} return api.request(session, payload, 'PUT', value)
def profile(session, values=None): """ API call to get/set a user's profile """ if values is None: payload = {'user': session.cookies.get('uuid'), 'path': 'profile'} return api.request(session, payload) else: payload = {'user': session.cookies.get('uuid'), 'path': 'profile'} return api.request(session, payload, 'PUT', values)
def main(): data_design_pattern = { "id": "", "sourceCode": api.get('source-codes', 1), "status": "PRIVATE", "tag": "design pattern", "xmlDescriptor": "descriptor", "author": "", "license": "" } api.request("Design Pattern", 'design-patterns', data_design_pattern)
def retrieve_meta(self): user = False if self.user_id: user = api.request('/user/' + str(self.user_id), method="GET") elif self.username: user = api.request('/userByUsername', method="GET", params=dict(username=self.username)) return user
def main(): data_source_code = { "id": "", "softwareSystem": api.get('software-systems', 1), "status": "PRIVATE", "tag": "Source code", "uri": "uri", "author": "", "license": "" } api.request("Source Code", 'source-codes', data_source_code)
def device_attribute(device_id, attribute, value = None, ts_start = None, ts_end = None ): if value != None: xml = api.request("setDeviceAttribute", devId = device_id, name = attribute, value = str(value)) return api.xml_value(xml, "retCode") == "0" else: if attribute.find("-ts"): xml = api.request("getDeviceTS2", devId = device_id, propName = attribute, start = ts_start, end = ts_end ) return api.xml_values(xml) else: xml = api.request("getDeviceAttribute", devId = device_id, name = attribute) return api.xml_value(xml, "value")
def main(): data_script = { "description": "Enter a description", "id": "", "sourceCode": "Code", "status": "PRIVATE", "tag": "string", "author": "", "license": "" } api.request("Script", 'scripts', data_script)
def onserver_status(session, uuid, environment, value=None): """ API call to get/set on-sserver development status """ payload = { 'site': uuid, 'path': 'environments/' + environment + '/on-server-development' } if value is None: return api.request(session, payload) else: data = {'enabled': value} return api.request(session, payload, 'PUT', data)
def main(): data_software_system = { "id": "", "study": api.get('studies', 1), "tag": "System A" } api.request("Sofware System", 'software-systems', data_software_system) data_software_system = { "id": "", "study": api.get('studies', 1), "tag": "System B", "author": "", "license": "" } api.request("Sofware System", 'software-systems', data_software_system) data_software_system = { "id": "", "study": api.get('studies', 1), "tag": "System C", "author": "", "license": "" } api.request("Sofware System", 'software-systems', data_software_system) data_software_system = { "id": "", "study": api.get('studies', 1), "tag": "System D", "author": "", "license": "" } api.request("Sofware System", 'software-systems', data_software_system)
def upstream(session, uuid, updatedb=False, overwrite=False): """ API call to get/set upstream """ payload = {'site': uuid, 'path': 'code-upstream-updates'} if not updatedb: return api.request(session, payload) else: if overwrite: xoption = 'theirs' else: xoption = '' data = {'updatedb': updatedb, 'xoption': xoption} return api.request(session, payload, 'POST', data)
def main(): root = api.path dirlist = [ item for item in os.listdir(root) if os.path.isdir(os.path.join(root, item)) ] for i in dirlist: data_developer = { "id": "", "name": i, "study": api.get('studies', 1), "license": "" } api.request(i, 'developers', data_developer)
def retrieve_meta(self): video = False if self.url: video = api.request('/videoByUrl', method="GET", params=dict(url=self.url)) elif self.video_id: video = api.request('/video/' + str(self.video_id), method="GET") elif self.code: video = api.request('/videoByUrl', method="GET", params=dict(url='https://vid.me/' + self.code)) return video
def device_attributes(device_id): xml = api.request("getDeviceValueList", deviceId = device_id, type = "2") valists = api.xml_nodes(xml, "valist") attributes = {} for valist in valists: attributes[valist.findtext("name")] = valist.findtext("value") return attributes
def api_ping(self, since=''): ping = api.request(self.exchange, self.symbol, limit=self.limit, since=since) trd = ping.get() trd = trd.set_index('tid') size = len(trd.index) return trd, size
def add_alert(device_id, action, attr_name, operation, threshold, address, msg): if action != "email" and action != "twitter": raise Exception("Error: action must be one of \"email\" or \"twitter\"") xml = api.request("addTrigger", devId = device_id, action = action, attrName = attr_name, operation = operation, threshold = str(threshold), address = address, msg = urllib.quote(msg)) return api.xml_value(xml, "triggerId")
def lock(session, uuid, environment, username, password): """ API call to lock an environment """ payload = {'site': uuid, 'path': 'environments/' + environment + '/lock'} data = {'username': username, 'password': password} return api.request(session, payload, 'PUT', data)
def lock(session, uuid, environment, username, password): """ API call to lock an environment """ payload = {'site': uuid, 'path': 'environments/'+environment+'/lock'} data = {'username': username, 'password': password} return api.request(session, payload, 'PUT', data)
def retrieve_meta(self): album = False if self.album_id: album = api.request('/album/' + str(self.album_id), method="GET") return album
def new_token(self): if not self.no_output: print '[-] Your token is invalid or has expired!' if self.oauth: request = self.run_oauth() else: if not self.username: username = raw_input("Please enter your username: "******"Please enter your password: "******"Basic")) if request: from User import User self.token = request['auth']['token'] self.expires = request['auth']['expires'] self.user = User({'user': request['user']}) self.auth = True return True else: return False
def invite_team_member(session, uuid, email): """ API call to invite a user to Pantheon and add to site team """ payload = {'site': uuid, 'path': 'team/'+urllib.quote(email)} data = {'invited_by': session.cookies.get('uuid')} return api.request(session, payload, 'POST', data)
def download_file(url, tgt_fd): from time import sleep print('F**k you bitch, download it yourself...') sleep(5) print('Well f**k, if you insist...') outfile = tgt_fd.buffer print('Requesting \''+url+'\'') response = api.request(url) size = len(response.content) strlen = 0 progress = 0 for data in response.iter_content(chunk_size=4096): if data: outfile.write(data) outfile.flush() progress += len(data) g = tools.gauge(progress / size, 20, format='\r Downloading... [%s]') s = g + ' ' + tools.format_data(progress, 2) + ' / ' + tools.format_data(size, 2) s += ' ' * (strlen - len(s)) strlen = len(s) sys.stdout.write(s) sys.stdout.flush() sys.stdout.write('\n') sys.stdout.flush()
def invite_team_member(session, uuid, email): """ API call to invite a user to Pantheon and add to site team """ payload = {'site': uuid, 'path': 'team/' + urllib.quote(email)} data = {'invited_by': session.cookies.get('uuid')} return api.request(session, payload, 'POST', data)
def _retrieve_videos(self, limit=20, offset=0, session=None, order=None, private=0): from Video import Video album_id = self._get_safe('album_id') if album_id: videos = api.request('/album/' + album_id + '/videos', method="GET", params=dict(private=private, order=order, session=session, offset=offset, limit=limit, album=album_id)) if videos: return [ Video(meta={'video': video}) for video in videos['videos'] ] else: return False else: return False
def set_thumbnail(self, session, thumb, no_output=False): video_id = self._get_safe('video_id') if video_id: if os.path.isfile(thumb): with open(thumb, 'rb') as f: chunk_request = True if not no_output: print "[+] Thumbnail is uploading..." file_info = os.stat(thumb) file_size = file_info.st_size chunk_request = api.request('/video/' + video_id + '/edit', session, files=dict(thumbnail=f)) print chunk_request if not no_output: print "[+] Thumbnail is done uploading." if chunk_request: return True else: return False else: return False else: return False
def select_grants_table_options(only_winners=True): """CLI interface for choice competition waves Arguments: only_winners {bool} -- only grant winners? Returns: dict|bool -- return GET params for parser or False if you quit from program """ GET_params = {'OnlyWinners': 'true'} if only_winners else {} response = api.request(api.URL, GET_params) # take select options from html web page competitions = parser.get_form_of_competition_waves(response.text) competitions = get_no_empty_competition_waves(competitions, GET_params) print('Выберите конкурс или напишите quit для выхода') for competition in competitions[::-1]: print('%s) %s' % (competition['id'], competition['text'])) while True: competitionid = input('Введите №:') if competitionid_is_exist(competitionid, competitions): GET_params['CompetitionId'] = competitionid break if competitionid == 'quit': sys.exit(0) return GET_params
def info(session, user_uuid=None): """ API call to get a user's information """ if user_uuid is None: user_uuid = session.cookies.get('uuid') payload = {'user': user_uuid, 'path': ''} return api.request(session, payload)
def main(): devs = api.getAll('developers') for a in range(1,7): dev = '{}{}'.format("dev", a) root = api.path + '/%s/logs/1-original/' % dev dirlist = [item for item in os.listdir(root) if os.path.isfile(os.path.join(root, item))] for i in dirlist: date = i[0:10].replace("_", "-") with open(root + i, "rU") as f: reader = csv.reader(f, delimiter = "\t") data = list(reader) y = 0 while y < len(data): #First exception : comma at end of cell if str(data[y]).endswith(",']"): _list = (str(data[y]).replace(",']","']")).split(",") else: _list = str(data[y]).split(",") #Second exception : other commas in cell if len(_list) > 6: _list[4] = _list[4][:-1] for x in range(5, len(_list)-1): if _list[x].startswith(" '"): cropped_list = " " + _list[x][2:] else: cropped_list = "," + _list[x][1:] _list[4] = _list[4] + cropped_list _list[5] = _list[-1] data_interactive_log = { "delta": _list[5][8:][:-3], "developer": devs[a-1], "id": "", "kind": _list[2][7:].upper(), "origin": _list[4][9:], "registred": date, "sourceHandle": _list[3][15:], "status": "PRIVATE", "author": "", "license": "" } api.request("Interactive Log", 'interactive-logs', data_interactive_log) y = y + 1
def clone_code(session, uuid, environment, updatedb=False): """ API call to deploy code to a site environment """ payload = {'site': uuid, 'path': 'environments/'+environment+'/code'} data = { 'updatedb': 1 if updatedb else 0 } return api.request(session, payload, 'POST', data)
def clone_files(session, uuid, source, target): """ API call to clone user files between site environments """ payload = {'site': uuid, 'path': 'environments/'+target+'/files'} data = { 'clone-from-environment': source, } return api.request(session, payload, 'POST', data)
def clear_cache(session, uuid, environment): """ API call to clear caches """ payload = { 'site': uuid, 'path': 'environment/' + environment + '/clear-cache' } return api.request(session, payload, 'POST')
def download_url(session, uuid, environment, bucket, element): """ API call to get a single backup item's S3 token """ payload = { 'site': uuid, 'path': 'environments/'+environment+'/backups/catalog/'+bucket+'/'+element+'/s3token' } return api.request(session, payload)
def hostnames(session, uuid, environment): """ API call to get hostnames for an environment """ payload = { 'site': uuid, 'path': 'environments/' + environment + '/hostnames' } return api.request(session, payload)
def onserver_commit(session, uuid, environment, message=None): """ API call to do an on-server git commit """ payload = {'site': uuid, 'path': 'environments/'+environment+'/on-server-development/commit'} if message is None: data = '' else: data = {'message': message} return api.request(session, payload, 'PUT', data)
def clone_database(session, uuid, source, target, updatedb=False): """ API call to clone a database between site environments """ payload = {'site': uuid, 'path': 'environments/'+target+'/database'} data = { 'clone-from-environment': source, 'updatedb': 1 if updatedb else 0 } return api.request(session, payload, 'POST', data)
def backup(session, uuid, environment, entry_type, code=True, db=True, files=True): """ API call to make a backup """ payload = {'site': uuid, 'path': 'environments/'+environment+'/backups/create'} data = { 'entry_type': entry_type, 'scheduled_for': int(time.time()), 'code': 1 if code else 0, 'database': 1 if db else 0, 'files': 1 if files else 0 } return api.request(session, payload, 'POST', data)
def alert_info(alert_id): xml = api.request("getTrigger", triggerId = alert_id) return { "device_id": api.xml_value(xml, "devId"), "action": api.xml_value(xml, "action"), "attr_name": api.xml_value(xml, "attrName"), "operation": api.xml_value(xml, "operation"), "threshold": float(api.xml_value(xml, "threshold")), "address": api.xml_value(xml, "address"), "msg": api.xml_value(xml, "msgText"), "auto_disarm": api.xml_value(xml, "autoDisarm") == "true", "disarmed": api.xml_value(xml, "disarmed") == "true", }
def tjob_run(self, job): if job['since'] == 0: ping = api.request(job['exchange'], job['symbol'],limit=job['limit']) else: ping = api.request(job['exchange'], job['symbol'], limit=job['limit'], since=job['since']) try: trd = ping.to_sql(stype='yes') except KeyboardInterrupt: sys.exit("Program Stopped: Keyboard Interrupt") except: pass else: if 'stype' in trd: if trd['stype'][0]== 'id': job['since'] = int(trd['tid'].max()) elif trd['stype'][0] == 'timestamp': job['since'] = int(trd['timestamp'].max()) - 1 num = float(len(trd.index)) time = float(int(trd['timestamp'].max())-int(trd['timestamp'].min())) if time > 0: job['vel'] = int(round((num/time)*3600)) return job
import api print('Connecting to API...') api.connect_as_application('application', 'response') print('Requesting vertical paxos...') api.request('vertical-paxos', 0, 0, 3) print('Waiting for response from vertical paxos...') response = api.wait_for_response() print('Got response from vertical paxos...') print(str(response))
def remove_alert(alert_id): xml = api.request("removeTrigger", triggerId = str(alert_id)) return api.xml_value(xml, "retCode")
def alerts(device_id): xml = api.request("getTriggerList", devId = device_id) return api.xml_node_values(xml, "triggerList")
import xml.etree.ElementTree as ET import api name, cards, actions, state = api.request() state = ET.parse(state) fear = False for act in state.getroot().findall('./betting/round/action'): if act.get('type') in ('raise',): fear = True break if fear: api.response('fold') else: api.response( api.first_possible( ('check', 'call', 'allin'), actions ) )
def device_status(device_id): xml = api.request("getDevicePresenceInfo", devId = device_id) return api.xml_value(xml, "state")