repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
acrazing/dbapi
dbapi/base.py
BaseAPI.persist
def persist(self): """ 持久化会话信息 """ with open(self.persist_file, 'w+') as f: json.dump({ 'cookies': self.cookies, 'user_alias': self.user_alias, }, f, indent=2) self.logger.debug('persist session to <%s>' % self.persist_file)
python
def persist(self): """ 持久化会话信息 """ with open(self.persist_file, 'w+') as f: json.dump({ 'cookies': self.cookies, 'user_alias': self.user_alias, }, f, indent=2) self.logger.debug('persist session to <%s>' % self.persist_file)
[ "def", "persist", "(", "self", ")", ":", "with", "open", "(", "self", ".", "persist_file", ",", "'w+'", ")", "as", "f", ":", "json", ".", "dump", "(", "{", "'cookies'", ":", "self", ".", "cookies", ",", "'user_alias'", ":", "self", ".", "user_alias", ",", "}", ",", "f", ",", "indent", "=", "2", ")", "self", ".", "logger", ".", "debug", "(", "'persist session to <%s>'", "%", "self", ".", "persist_file", ")" ]
持久化会话信息
[ "持久化会话信息" ]
8c1f85cb1a051daf7be1fc97a62c4499983e9898
https://github.com/acrazing/dbapi/blob/8c1f85cb1a051daf7be1fc97a62c4499983e9898/dbapi/base.py#L156-L165
train
acrazing/dbapi
dbapi/base.py
BaseAPI.load
def load(self): """ 加载会话信息 """ if not os.path.isfile(self.persist_file): return with open(self.persist_file, 'r') as f: cfg = json.load(f) or {} self.cookies = cfg.get('cookies', {}) self.user_alias = cfg.get('user_alias') or None self.logger.debug('load session for <%s> from <%s>' % (self.user_alias, self.persist_file))
python
def load(self): """ 加载会话信息 """ if not os.path.isfile(self.persist_file): return with open(self.persist_file, 'r') as f: cfg = json.load(f) or {} self.cookies = cfg.get('cookies', {}) self.user_alias = cfg.get('user_alias') or None self.logger.debug('load session for <%s> from <%s>' % (self.user_alias, self.persist_file))
[ "def", "load", "(", "self", ")", ":", "if", "not", "os", ".", "path", ".", "isfile", "(", "self", ".", "persist_file", ")", ":", "return", "with", "open", "(", "self", ".", "persist_file", ",", "'r'", ")", "as", "f", ":", "cfg", "=", "json", ".", "load", "(", "f", ")", "or", "{", "}", "self", ".", "cookies", "=", "cfg", ".", "get", "(", "'cookies'", ",", "{", "}", ")", "self", ".", "user_alias", "=", "cfg", ".", "get", "(", "'user_alias'", ")", "or", "None", "self", ".", "logger", ".", "debug", "(", "'load session for <%s> from <%s>'", "%", "(", "self", ".", "user_alias", ",", "self", ".", "persist_file", ")", ")" ]
加载会话信息
[ "加载会话信息" ]
8c1f85cb1a051daf7be1fc97a62c4499983e9898
https://github.com/acrazing/dbapi/blob/8c1f85cb1a051daf7be1fc97a62c4499983e9898/dbapi/base.py#L167-L177
train
acrazing/dbapi
dbapi/base.py
BaseAPI.flush
def flush(self): """ 更新会话信息,主要是ck, user_alias """ if 'dbcl2' not in self.cookies: return r = self.req(API_ACCOUNT_HOME) if RE_SESSION_EXPIRE.search(r.url): return self.expire() self.cookies.update(dict(r.cookies)) self.user_alias = slash_right(r.url) self.logger.debug('flush with user_alias <%s>' % self.user_alias) return
python
def flush(self): """ 更新会话信息,主要是ck, user_alias """ if 'dbcl2' not in self.cookies: return r = self.req(API_ACCOUNT_HOME) if RE_SESSION_EXPIRE.search(r.url): return self.expire() self.cookies.update(dict(r.cookies)) self.user_alias = slash_right(r.url) self.logger.debug('flush with user_alias <%s>' % self.user_alias) return
[ "def", "flush", "(", "self", ")", ":", "if", "'dbcl2'", "not", "in", "self", ".", "cookies", ":", "return", "r", "=", "self", ".", "req", "(", "API_ACCOUNT_HOME", ")", "if", "RE_SESSION_EXPIRE", ".", "search", "(", "r", ".", "url", ")", ":", "return", "self", ".", "expire", "(", ")", "self", ".", "cookies", ".", "update", "(", "dict", "(", "r", ".", "cookies", ")", ")", "self", ".", "user_alias", "=", "slash_right", "(", "r", ".", "url", ")", "self", ".", "logger", ".", "debug", "(", "'flush with user_alias <%s>'", "%", "self", ".", "user_alias", ")", "return" ]
更新会话信息,主要是ck, user_alias
[ "更新会话信息,主要是ck", "user_alias" ]
8c1f85cb1a051daf7be1fc97a62c4499983e9898
https://github.com/acrazing/dbapi/blob/8c1f85cb1a051daf7be1fc97a62c4499983e9898/dbapi/base.py#L187-L199
train
acrazing/dbapi
dbapi/base.py
BaseAPI.login
def login(self, username, password): """ 登录 :type username: str :param username: 用户名(手机号或者邮箱) :type password: str :param password: 密码 """ r0 = self.req(API_HOME) time.sleep(1) cookies = dict(r0.cookies) data = { 'source': 'index_nav', 'form_email': username, 'form_password': password, 'remember': 'on', } r1 = self.req(API_ACCOUNT_LOGIN, method='post', data=data) cookies.update(dict(r1.cookies)) [cookies.update(dict(r.cookies)) for r in r1.history] if 'dbcl2' not in cookies: raise Exception('Authorization failed for <%s>: %s' % (username, r1.url)) cookies.update(dict(r1.cookies)) self.logger.info('login with username <%s>' % username) self.use(cookies) return self
python
def login(self, username, password): """ 登录 :type username: str :param username: 用户名(手机号或者邮箱) :type password: str :param password: 密码 """ r0 = self.req(API_HOME) time.sleep(1) cookies = dict(r0.cookies) data = { 'source': 'index_nav', 'form_email': username, 'form_password': password, 'remember': 'on', } r1 = self.req(API_ACCOUNT_LOGIN, method='post', data=data) cookies.update(dict(r1.cookies)) [cookies.update(dict(r.cookies)) for r in r1.history] if 'dbcl2' not in cookies: raise Exception('Authorization failed for <%s>: %s' % (username, r1.url)) cookies.update(dict(r1.cookies)) self.logger.info('login with username <%s>' % username) self.use(cookies) return self
[ "def", "login", "(", "self", ",", "username", ",", "password", ")", ":", "r0", "=", "self", ".", "req", "(", "API_HOME", ")", "time", ".", "sleep", "(", "1", ")", "cookies", "=", "dict", "(", "r0", ".", "cookies", ")", "data", "=", "{", "'source'", ":", "'index_nav'", ",", "'form_email'", ":", "username", ",", "'form_password'", ":", "password", ",", "'remember'", ":", "'on'", ",", "}", "r1", "=", "self", ".", "req", "(", "API_ACCOUNT_LOGIN", ",", "method", "=", "'post'", ",", "data", "=", "data", ")", "cookies", ".", "update", "(", "dict", "(", "r1", ".", "cookies", ")", ")", "[", "cookies", ".", "update", "(", "dict", "(", "r", ".", "cookies", ")", ")", "for", "r", "in", "r1", ".", "history", "]", "if", "'dbcl2'", "not", "in", "cookies", ":", "raise", "Exception", "(", "'Authorization failed for <%s>: %s'", "%", "(", "username", ",", "r1", ".", "url", ")", ")", "cookies", ".", "update", "(", "dict", "(", "r1", ".", "cookies", ")", ")", "self", ".", "logger", ".", "info", "(", "'login with username <%s>'", "%", "username", ")", "self", ".", "use", "(", "cookies", ")", "return", "self" ]
登录 :type username: str :param username: 用户名(手机号或者邮箱) :type password: str :param password: 密码
[ "登录", ":", "type", "username", ":", "str", ":", "param", "username", ":", "用户名(手机号或者邮箱)", ":", "type", "password", ":", "str", ":", "param", "password", ":", "密码" ]
8c1f85cb1a051daf7be1fc97a62c4499983e9898
https://github.com/acrazing/dbapi/blob/8c1f85cb1a051daf7be1fc97a62c4499983e9898/dbapi/base.py#L201-L228
train
acrazing/dbapi
dbapi/base.py
BaseAPI.use
def use(self, cookies): """ 如果遭遇验证码,用这个接口 :type cookies: str|dict :param cookies: cookie字符串或者字典 :return: self """ self.cookies = dict([item.split('=', 1) for item in re.split(r'; *', cookies)]) \ if isinstance(cookies, str) else cookies self.flush() self.persist() return self
python
def use(self, cookies): """ 如果遭遇验证码,用这个接口 :type cookies: str|dict :param cookies: cookie字符串或者字典 :return: self """ self.cookies = dict([item.split('=', 1) for item in re.split(r'; *', cookies)]) \ if isinstance(cookies, str) else cookies self.flush() self.persist() return self
[ "def", "use", "(", "self", ",", "cookies", ")", ":", "self", ".", "cookies", "=", "dict", "(", "[", "item", ".", "split", "(", "'='", ",", "1", ")", "for", "item", "in", "re", ".", "split", "(", "r'; *'", ",", "cookies", ")", "]", ")", "if", "isinstance", "(", "cookies", ",", "str", ")", "else", "cookies", "self", ".", "flush", "(", ")", "self", ".", "persist", "(", ")", "return", "self" ]
如果遭遇验证码,用这个接口 :type cookies: str|dict :param cookies: cookie字符串或者字典 :return: self
[ "如果遭遇验证码,用这个接口", ":", "type", "cookies", ":", "str|dict", ":", "param", "cookies", ":", "cookie字符串或者字典", ":", "return", ":", "self" ]
8c1f85cb1a051daf7be1fc97a62c4499983e9898
https://github.com/acrazing/dbapi/blob/8c1f85cb1a051daf7be1fc97a62c4499983e9898/dbapi/base.py#L230-L242
train
acrazing/dbapi
dbapi/base.py
BaseAPI.logout
def logout(self): """ 登出会话 :return: self """ self.req(API_ACCOUNT_LOGOUT % self.ck()) self.cookies = {} self.user_alias = None self.persist()
python
def logout(self): """ 登出会话 :return: self """ self.req(API_ACCOUNT_LOGOUT % self.ck()) self.cookies = {} self.user_alias = None self.persist()
[ "def", "logout", "(", "self", ")", ":", "self", ".", "req", "(", "API_ACCOUNT_LOGOUT", "%", "self", ".", "ck", "(", ")", ")", "self", ".", "cookies", "=", "{", "}", "self", ".", "user_alias", "=", "None", "self", ".", "persist", "(", ")" ]
登出会话 :return: self
[ "登出会话", ":", "return", ":", "self" ]
8c1f85cb1a051daf7be1fc97a62c4499983e9898
https://github.com/acrazing/dbapi/blob/8c1f85cb1a051daf7be1fc97a62c4499983e9898/dbapi/base.py#L244-L253
train
glomex/gcdt
gcdt/tenkai_core.py
deploy
def deploy(awsclient, applicationName, deploymentGroupName, deploymentConfigName, bucket, bundlefile): """Upload bundle and deploy to deployment group. This includes the bundle-action. :param applicationName: :param deploymentGroupName: :param deploymentConfigName: :param bucket: :param bundlefile: :return: deploymentId from create_deployment """ etag, version = upload_file_to_s3(awsclient, bucket, _build_bundle_key(applicationName), bundlefile) client_codedeploy = awsclient.get_client('codedeploy') response = client_codedeploy.create_deployment( applicationName=applicationName, deploymentGroupName=deploymentGroupName, revision={ 'revisionType': 'S3', 's3Location': { 'bucket': bucket, 'key': _build_bundle_key(applicationName), 'bundleType': 'tgz', 'eTag': etag, 'version': version, }, }, deploymentConfigName=deploymentConfigName, description='deploy with tenkai', ignoreApplicationStopFailures=True ) log.info( "Deployment: {} -> URL: https://{}.console.aws.amazon.com/codedeploy/home?region={}#/deployments/{}".format( Fore.MAGENTA + response['deploymentId'] + Fore.RESET, client_codedeploy.meta.region_name, client_codedeploy.meta.region_name, response['deploymentId'], )) return response['deploymentId']
python
def deploy(awsclient, applicationName, deploymentGroupName, deploymentConfigName, bucket, bundlefile): """Upload bundle and deploy to deployment group. This includes the bundle-action. :param applicationName: :param deploymentGroupName: :param deploymentConfigName: :param bucket: :param bundlefile: :return: deploymentId from create_deployment """ etag, version = upload_file_to_s3(awsclient, bucket, _build_bundle_key(applicationName), bundlefile) client_codedeploy = awsclient.get_client('codedeploy') response = client_codedeploy.create_deployment( applicationName=applicationName, deploymentGroupName=deploymentGroupName, revision={ 'revisionType': 'S3', 's3Location': { 'bucket': bucket, 'key': _build_bundle_key(applicationName), 'bundleType': 'tgz', 'eTag': etag, 'version': version, }, }, deploymentConfigName=deploymentConfigName, description='deploy with tenkai', ignoreApplicationStopFailures=True ) log.info( "Deployment: {} -> URL: https://{}.console.aws.amazon.com/codedeploy/home?region={}#/deployments/{}".format( Fore.MAGENTA + response['deploymentId'] + Fore.RESET, client_codedeploy.meta.region_name, client_codedeploy.meta.region_name, response['deploymentId'], )) return response['deploymentId']
[ "def", "deploy", "(", "awsclient", ",", "applicationName", ",", "deploymentGroupName", ",", "deploymentConfigName", ",", "bucket", ",", "bundlefile", ")", ":", "etag", ",", "version", "=", "upload_file_to_s3", "(", "awsclient", ",", "bucket", ",", "_build_bundle_key", "(", "applicationName", ")", ",", "bundlefile", ")", "client_codedeploy", "=", "awsclient", ".", "get_client", "(", "'codedeploy'", ")", "response", "=", "client_codedeploy", ".", "create_deployment", "(", "applicationName", "=", "applicationName", ",", "deploymentGroupName", "=", "deploymentGroupName", ",", "revision", "=", "{", "'revisionType'", ":", "'S3'", ",", "'s3Location'", ":", "{", "'bucket'", ":", "bucket", ",", "'key'", ":", "_build_bundle_key", "(", "applicationName", ")", ",", "'bundleType'", ":", "'tgz'", ",", "'eTag'", ":", "etag", ",", "'version'", ":", "version", ",", "}", ",", "}", ",", "deploymentConfigName", "=", "deploymentConfigName", ",", "description", "=", "'deploy with tenkai'", ",", "ignoreApplicationStopFailures", "=", "True", ")", "log", ".", "info", "(", "\"Deployment: {} -> URL: https://{}.console.aws.amazon.com/codedeploy/home?region={}#/deployments/{}\"", ".", "format", "(", "Fore", ".", "MAGENTA", "+", "response", "[", "'deploymentId'", "]", "+", "Fore", ".", "RESET", ",", "client_codedeploy", ".", "meta", ".", "region_name", ",", "client_codedeploy", ".", "meta", ".", "region_name", ",", "response", "[", "'deploymentId'", "]", ",", ")", ")", "return", "response", "[", "'deploymentId'", "]" ]
Upload bundle and deploy to deployment group. This includes the bundle-action. :param applicationName: :param deploymentGroupName: :param deploymentConfigName: :param bucket: :param bundlefile: :return: deploymentId from create_deployment
[ "Upload", "bundle", "and", "deploy", "to", "deployment", "group", ".", "This", "includes", "the", "bundle", "-", "action", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/tenkai_core.py#L18-L61
train
glomex/gcdt
gcdt/tenkai_core.py
output_deployment_status
def output_deployment_status(awsclient, deployment_id, iterations=100): """Wait until an deployment is in an steady state and output information. :param deployment_id: :param iterations: :return: exit_code """ counter = 0 steady_states = ['Succeeded', 'Failed', 'Stopped'] client_codedeploy = awsclient.get_client('codedeploy') while counter <= iterations: response = client_codedeploy.get_deployment(deploymentId=deployment_id) status = response['deploymentInfo']['status'] if status not in steady_states: log.info('Deployment: %s - State: %s' % (deployment_id, status)) time.sleep(10) elif status == 'Failed': log.info( colored.red('Deployment: {} failed: {}'.format( deployment_id, json.dumps(response['deploymentInfo']['errorInformation'], indent=2) )) ) return 1 else: log.info('Deployment: %s - State: %s' % (deployment_id, status)) break return 0
python
def output_deployment_status(awsclient, deployment_id, iterations=100): """Wait until an deployment is in an steady state and output information. :param deployment_id: :param iterations: :return: exit_code """ counter = 0 steady_states = ['Succeeded', 'Failed', 'Stopped'] client_codedeploy = awsclient.get_client('codedeploy') while counter <= iterations: response = client_codedeploy.get_deployment(deploymentId=deployment_id) status = response['deploymentInfo']['status'] if status not in steady_states: log.info('Deployment: %s - State: %s' % (deployment_id, status)) time.sleep(10) elif status == 'Failed': log.info( colored.red('Deployment: {} failed: {}'.format( deployment_id, json.dumps(response['deploymentInfo']['errorInformation'], indent=2) )) ) return 1 else: log.info('Deployment: %s - State: %s' % (deployment_id, status)) break return 0
[ "def", "output_deployment_status", "(", "awsclient", ",", "deployment_id", ",", "iterations", "=", "100", ")", ":", "counter", "=", "0", "steady_states", "=", "[", "'Succeeded'", ",", "'Failed'", ",", "'Stopped'", "]", "client_codedeploy", "=", "awsclient", ".", "get_client", "(", "'codedeploy'", ")", "while", "counter", "<=", "iterations", ":", "response", "=", "client_codedeploy", ".", "get_deployment", "(", "deploymentId", "=", "deployment_id", ")", "status", "=", "response", "[", "'deploymentInfo'", "]", "[", "'status'", "]", "if", "status", "not", "in", "steady_states", ":", "log", ".", "info", "(", "'Deployment: %s - State: %s'", "%", "(", "deployment_id", ",", "status", ")", ")", "time", ".", "sleep", "(", "10", ")", "elif", "status", "==", "'Failed'", ":", "log", ".", "info", "(", "colored", ".", "red", "(", "'Deployment: {} failed: {}'", ".", "format", "(", "deployment_id", ",", "json", ".", "dumps", "(", "response", "[", "'deploymentInfo'", "]", "[", "'errorInformation'", "]", ",", "indent", "=", "2", ")", ")", ")", ")", "return", "1", "else", ":", "log", ".", "info", "(", "'Deployment: %s - State: %s'", "%", "(", "deployment_id", ",", "status", ")", ")", "break", "return", "0" ]
Wait until an deployment is in an steady state and output information. :param deployment_id: :param iterations: :return: exit_code
[ "Wait", "until", "an", "deployment", "is", "in", "an", "steady", "state", "and", "output", "information", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/tenkai_core.py#L69-L100
train
glomex/gcdt
gcdt/tenkai_core.py
stop_deployment
def stop_deployment(awsclient, deployment_id): """stop tenkai deployment. :param awsclient: :param deployment_id: """ log.info('Deployment: %s - stopping active deployment.', deployment_id) client_codedeploy = awsclient.get_client('codedeploy') response = client_codedeploy.stop_deployment( deploymentId=deployment_id, autoRollbackEnabled=True )
python
def stop_deployment(awsclient, deployment_id): """stop tenkai deployment. :param awsclient: :param deployment_id: """ log.info('Deployment: %s - stopping active deployment.', deployment_id) client_codedeploy = awsclient.get_client('codedeploy') response = client_codedeploy.stop_deployment( deploymentId=deployment_id, autoRollbackEnabled=True )
[ "def", "stop_deployment", "(", "awsclient", ",", "deployment_id", ")", ":", "log", ".", "info", "(", "'Deployment: %s - stopping active deployment.'", ",", "deployment_id", ")", "client_codedeploy", "=", "awsclient", ".", "get_client", "(", "'codedeploy'", ")", "response", "=", "client_codedeploy", ".", "stop_deployment", "(", "deploymentId", "=", "deployment_id", ",", "autoRollbackEnabled", "=", "True", ")" ]
stop tenkai deployment. :param awsclient: :param deployment_id:
[ "stop", "tenkai", "deployment", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/tenkai_core.py#L103-L115
train
glomex/gcdt
gcdt/tenkai_core.py
_list_deployment_instances
def _list_deployment_instances(awsclient, deployment_id): """list deployment instances. :param awsclient: :param deployment_id: """ client_codedeploy = awsclient.get_client('codedeploy') instances = [] next_token = None # TODO refactor generic exhaust_function from this while True: request = { 'deploymentId': deployment_id } if next_token: request['nextToken'] = next_token response = client_codedeploy.list_deployment_instances(**request) instances.extend(response['instancesList']) if 'nextToken' not in response: break next_token = response['nextToken'] return instances
python
def _list_deployment_instances(awsclient, deployment_id): """list deployment instances. :param awsclient: :param deployment_id: """ client_codedeploy = awsclient.get_client('codedeploy') instances = [] next_token = None # TODO refactor generic exhaust_function from this while True: request = { 'deploymentId': deployment_id } if next_token: request['nextToken'] = next_token response = client_codedeploy.list_deployment_instances(**request) instances.extend(response['instancesList']) if 'nextToken' not in response: break next_token = response['nextToken'] return instances
[ "def", "_list_deployment_instances", "(", "awsclient", ",", "deployment_id", ")", ":", "client_codedeploy", "=", "awsclient", ".", "get_client", "(", "'codedeploy'", ")", "instances", "=", "[", "]", "next_token", "=", "None", "# TODO refactor generic exhaust_function from this", "while", "True", ":", "request", "=", "{", "'deploymentId'", ":", "deployment_id", "}", "if", "next_token", ":", "request", "[", "'nextToken'", "]", "=", "next_token", "response", "=", "client_codedeploy", ".", "list_deployment_instances", "(", "*", "*", "request", ")", "instances", ".", "extend", "(", "response", "[", "'instancesList'", "]", ")", "if", "'nextToken'", "not", "in", "response", ":", "break", "next_token", "=", "response", "[", "'nextToken'", "]", "return", "instances" ]
list deployment instances. :param awsclient: :param deployment_id:
[ "list", "deployment", "instances", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/tenkai_core.py#L118-L141
train
glomex/gcdt
gcdt/tenkai_core.py
_get_deployment_instance_summary
def _get_deployment_instance_summary(awsclient, deployment_id, instance_id): """instance summary. :param awsclient: :param deployment_id: :param instance_id: return: status, last_event """ client_codedeploy = awsclient.get_client('codedeploy') request = { 'deploymentId': deployment_id, 'instanceId': instance_id } response = client_codedeploy.get_deployment_instance(**request) return response['instanceSummary']['status'], \ response['instanceSummary']['lifecycleEvents'][-1]['lifecycleEventName']
python
def _get_deployment_instance_summary(awsclient, deployment_id, instance_id): """instance summary. :param awsclient: :param deployment_id: :param instance_id: return: status, last_event """ client_codedeploy = awsclient.get_client('codedeploy') request = { 'deploymentId': deployment_id, 'instanceId': instance_id } response = client_codedeploy.get_deployment_instance(**request) return response['instanceSummary']['status'], \ response['instanceSummary']['lifecycleEvents'][-1]['lifecycleEventName']
[ "def", "_get_deployment_instance_summary", "(", "awsclient", ",", "deployment_id", ",", "instance_id", ")", ":", "client_codedeploy", "=", "awsclient", ".", "get_client", "(", "'codedeploy'", ")", "request", "=", "{", "'deploymentId'", ":", "deployment_id", ",", "'instanceId'", ":", "instance_id", "}", "response", "=", "client_codedeploy", ".", "get_deployment_instance", "(", "*", "*", "request", ")", "return", "response", "[", "'instanceSummary'", "]", "[", "'status'", "]", ",", "response", "[", "'instanceSummary'", "]", "[", "'lifecycleEvents'", "]", "[", "-", "1", "]", "[", "'lifecycleEventName'", "]" ]
instance summary. :param awsclient: :param deployment_id: :param instance_id: return: status, last_event
[ "instance", "summary", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/tenkai_core.py#L144-L159
train
glomex/gcdt
gcdt/tenkai_core.py
_get_deployment_instance_diagnostics
def _get_deployment_instance_diagnostics(awsclient, deployment_id, instance_id): """Gets you the diagnostics details for the first 'Failed' event. :param awsclient: :param deployment_id: :param instance_id: return: None or (error_code, script_name, message, log_tail) """ client_codedeploy = awsclient.get_client('codedeploy') request = { 'deploymentId': deployment_id, 'instanceId': instance_id } response = client_codedeploy.get_deployment_instance(**request) # find first 'Failed' event for i, event in enumerate(response['instanceSummary']['lifecycleEvents']): if event['status'] == 'Failed': return event['diagnostics']['errorCode'], \ event['diagnostics']['scriptName'], \ event['diagnostics']['message'], \ event['diagnostics']['logTail'] return None
python
def _get_deployment_instance_diagnostics(awsclient, deployment_id, instance_id): """Gets you the diagnostics details for the first 'Failed' event. :param awsclient: :param deployment_id: :param instance_id: return: None or (error_code, script_name, message, log_tail) """ client_codedeploy = awsclient.get_client('codedeploy') request = { 'deploymentId': deployment_id, 'instanceId': instance_id } response = client_codedeploy.get_deployment_instance(**request) # find first 'Failed' event for i, event in enumerate(response['instanceSummary']['lifecycleEvents']): if event['status'] == 'Failed': return event['diagnostics']['errorCode'], \ event['diagnostics']['scriptName'], \ event['diagnostics']['message'], \ event['diagnostics']['logTail'] return None
[ "def", "_get_deployment_instance_diagnostics", "(", "awsclient", ",", "deployment_id", ",", "instance_id", ")", ":", "client_codedeploy", "=", "awsclient", ".", "get_client", "(", "'codedeploy'", ")", "request", "=", "{", "'deploymentId'", ":", "deployment_id", ",", "'instanceId'", ":", "instance_id", "}", "response", "=", "client_codedeploy", ".", "get_deployment_instance", "(", "*", "*", "request", ")", "# find first 'Failed' event", "for", "i", ",", "event", "in", "enumerate", "(", "response", "[", "'instanceSummary'", "]", "[", "'lifecycleEvents'", "]", ")", ":", "if", "event", "[", "'status'", "]", "==", "'Failed'", ":", "return", "event", "[", "'diagnostics'", "]", "[", "'errorCode'", "]", ",", "event", "[", "'diagnostics'", "]", "[", "'scriptName'", "]", ",", "event", "[", "'diagnostics'", "]", "[", "'message'", "]", ",", "event", "[", "'diagnostics'", "]", "[", "'logTail'", "]", "return", "None" ]
Gets you the diagnostics details for the first 'Failed' event. :param awsclient: :param deployment_id: :param instance_id: return: None or (error_code, script_name, message, log_tail)
[ "Gets", "you", "the", "diagnostics", "details", "for", "the", "first", "Failed", "event", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/tenkai_core.py#L162-L183
train
glomex/gcdt
gcdt/tenkai_core.py
output_deployment_summary
def output_deployment_summary(awsclient, deployment_id): """summary :param awsclient: :param deployment_id: """ log.info('\ndeployment summary:') log.info('%-22s %-12s %s', 'Instance ID', 'Status', 'Most recent event') for instance_id in _list_deployment_instances(awsclient, deployment_id): status, last_event = \ _get_deployment_instance_summary(awsclient, deployment_id, instance_id) log.info(Fore.MAGENTA + '%-22s' + Fore.RESET + ' %-12s %s', instance_id, status, last_event)
python
def output_deployment_summary(awsclient, deployment_id): """summary :param awsclient: :param deployment_id: """ log.info('\ndeployment summary:') log.info('%-22s %-12s %s', 'Instance ID', 'Status', 'Most recent event') for instance_id in _list_deployment_instances(awsclient, deployment_id): status, last_event = \ _get_deployment_instance_summary(awsclient, deployment_id, instance_id) log.info(Fore.MAGENTA + '%-22s' + Fore.RESET + ' %-12s %s', instance_id, status, last_event)
[ "def", "output_deployment_summary", "(", "awsclient", ",", "deployment_id", ")", ":", "log", ".", "info", "(", "'\\ndeployment summary:'", ")", "log", ".", "info", "(", "'%-22s %-12s %s'", ",", "'Instance ID'", ",", "'Status'", ",", "'Most recent event'", ")", "for", "instance_id", "in", "_list_deployment_instances", "(", "awsclient", ",", "deployment_id", ")", ":", "status", ",", "last_event", "=", "_get_deployment_instance_summary", "(", "awsclient", ",", "deployment_id", ",", "instance_id", ")", "log", ".", "info", "(", "Fore", ".", "MAGENTA", "+", "'%-22s'", "+", "Fore", ".", "RESET", "+", "' %-12s %s'", ",", "instance_id", ",", "status", ",", "last_event", ")" ]
summary :param awsclient: :param deployment_id:
[ "summary" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/tenkai_core.py#L186-L198
train
glomex/gcdt
gcdt/tenkai_core.py
output_deployment_diagnostics
def output_deployment_diagnostics(awsclient, deployment_id, log_group, start_time=None): """diagnostics :param awsclient: :param deployment_id: """ headline = False for instance_id in _list_deployment_instances(awsclient, deployment_id): diagnostics = _get_deployment_instance_diagnostics( awsclient, deployment_id, instance_id) #if error_code != 'Success': if diagnostics is not None: error_code, script_name, message, log_tail = diagnostics # header if not headline: headline = True log.info('\ndeployment diagnostics:') # event logs log.info('Instance ID: %s', Fore.MAGENTA + instance_id + Fore.RESET) log.info('Error Code: %s', error_code) log.info('Script Name: %s', script_name) log.info('Message: %s', message) log.info('Log Tail: %s', log_tail) # cloudwatch logs if check_log_stream_exists(awsclient, log_group, instance_id): logentries = get_log_events( awsclient, log_group, instance_id, datetime_to_timestamp(start_time)) if logentries: log.info('instance %s logentries', instance_id) for e in logentries: log.info(e['message'].strip())
python
def output_deployment_diagnostics(awsclient, deployment_id, log_group, start_time=None): """diagnostics :param awsclient: :param deployment_id: """ headline = False for instance_id in _list_deployment_instances(awsclient, deployment_id): diagnostics = _get_deployment_instance_diagnostics( awsclient, deployment_id, instance_id) #if error_code != 'Success': if diagnostics is not None: error_code, script_name, message, log_tail = diagnostics # header if not headline: headline = True log.info('\ndeployment diagnostics:') # event logs log.info('Instance ID: %s', Fore.MAGENTA + instance_id + Fore.RESET) log.info('Error Code: %s', error_code) log.info('Script Name: %s', script_name) log.info('Message: %s', message) log.info('Log Tail: %s', log_tail) # cloudwatch logs if check_log_stream_exists(awsclient, log_group, instance_id): logentries = get_log_events( awsclient, log_group, instance_id, datetime_to_timestamp(start_time)) if logentries: log.info('instance %s logentries', instance_id) for e in logentries: log.info(e['message'].strip())
[ "def", "output_deployment_diagnostics", "(", "awsclient", ",", "deployment_id", ",", "log_group", ",", "start_time", "=", "None", ")", ":", "headline", "=", "False", "for", "instance_id", "in", "_list_deployment_instances", "(", "awsclient", ",", "deployment_id", ")", ":", "diagnostics", "=", "_get_deployment_instance_diagnostics", "(", "awsclient", ",", "deployment_id", ",", "instance_id", ")", "#if error_code != 'Success':", "if", "diagnostics", "is", "not", "None", ":", "error_code", ",", "script_name", ",", "message", ",", "log_tail", "=", "diagnostics", "# header", "if", "not", "headline", ":", "headline", "=", "True", "log", ".", "info", "(", "'\\ndeployment diagnostics:'", ")", "# event logs", "log", ".", "info", "(", "'Instance ID: %s'", ",", "Fore", ".", "MAGENTA", "+", "instance_id", "+", "Fore", ".", "RESET", ")", "log", ".", "info", "(", "'Error Code: %s'", ",", "error_code", ")", "log", ".", "info", "(", "'Script Name: %s'", ",", "script_name", ")", "log", ".", "info", "(", "'Message: %s'", ",", "message", ")", "log", ".", "info", "(", "'Log Tail: %s'", ",", "log_tail", ")", "# cloudwatch logs", "if", "check_log_stream_exists", "(", "awsclient", ",", "log_group", ",", "instance_id", ")", ":", "logentries", "=", "get_log_events", "(", "awsclient", ",", "log_group", ",", "instance_id", ",", "datetime_to_timestamp", "(", "start_time", ")", ")", "if", "logentries", ":", "log", ".", "info", "(", "'instance %s logentries'", ",", "instance_id", ")", "for", "e", "in", "logentries", ":", "log", ".", "info", "(", "e", "[", "'message'", "]", ".", "strip", "(", ")", ")" ]
diagnostics :param awsclient: :param deployment_id:
[ "diagnostics" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/tenkai_core.py#L201-L232
train
thombashi/typepy
typepy/type/_base.py
AbstractType.is_type
def is_type(self): """ :return: :rtype: bool """ if self.__is_type_result is not None: return self.__is_type_result self.__is_type_result = self.__is_type() return self.__is_type_result
python
def is_type(self): """ :return: :rtype: bool """ if self.__is_type_result is not None: return self.__is_type_result self.__is_type_result = self.__is_type() return self.__is_type_result
[ "def", "is_type", "(", "self", ")", ":", "if", "self", ".", "__is_type_result", "is", "not", "None", ":", "return", "self", ".", "__is_type_result", "self", ".", "__is_type_result", "=", "self", ".", "__is_type", "(", ")", "return", "self", ".", "__is_type_result" ]
:return: :rtype: bool
[ ":", "return", ":", ":", "rtype", ":", "bool" ]
8209d1df4f2a7f196a9fa4bfb0708c5ff648461f
https://github.com/thombashi/typepy/blob/8209d1df4f2a7f196a9fa4bfb0708c5ff648461f/typepy/type/_base.py#L63-L74
train
thombashi/typepy
typepy/type/_base.py
AbstractType.validate
def validate(self, error_message=None): """ :raises TypeError: If the value is not matched the type that the class represented. """ if self.is_type(): return if not error_message: error_message = "invalid value type" raise TypeError( "{}: expected={}, actual={}".format(error_message, self.typename, type(self._data)) )
python
def validate(self, error_message=None): """ :raises TypeError: If the value is not matched the type that the class represented. """ if self.is_type(): return if not error_message: error_message = "invalid value type" raise TypeError( "{}: expected={}, actual={}".format(error_message, self.typename, type(self._data)) )
[ "def", "validate", "(", "self", ",", "error_message", "=", "None", ")", ":", "if", "self", ".", "is_type", "(", ")", ":", "return", "if", "not", "error_message", ":", "error_message", "=", "\"invalid value type\"", "raise", "TypeError", "(", "\"{}: expected={}, actual={}\"", ".", "format", "(", "error_message", ",", "self", ".", "typename", ",", "type", "(", "self", ".", "_data", ")", ")", ")" ]
:raises TypeError: If the value is not matched the type that the class represented.
[ ":", "raises", "TypeError", ":", "If", "the", "value", "is", "not", "matched", "the", "type", "that", "the", "class", "represented", "." ]
8209d1df4f2a7f196a9fa4bfb0708c5ff648461f
https://github.com/thombashi/typepy/blob/8209d1df4f2a7f196a9fa4bfb0708c5ff648461f/typepy/type/_base.py#L93-L107
train
thombashi/typepy
typepy/type/_base.py
AbstractType.convert
def convert(self): """ :return: Converted value. :raises typepy.TypeConversionError: If the value cannot convert. """ if self.is_type(): return self.force_convert() raise TypeConversionError( "failed to convert from {} to {}".format(type(self._data).__name__, self.typename) )
python
def convert(self): """ :return: Converted value. :raises typepy.TypeConversionError: If the value cannot convert. """ if self.is_type(): return self.force_convert() raise TypeConversionError( "failed to convert from {} to {}".format(type(self._data).__name__, self.typename) )
[ "def", "convert", "(", "self", ")", ":", "if", "self", ".", "is_type", "(", ")", ":", "return", "self", ".", "force_convert", "(", ")", "raise", "TypeConversionError", "(", "\"failed to convert from {} to {}\"", ".", "format", "(", "type", "(", "self", ".", "_data", ")", ".", "__name__", ",", "self", ".", "typename", ")", ")" ]
:return: Converted value. :raises typepy.TypeConversionError: If the value cannot convert.
[ ":", "return", ":", "Converted", "value", ".", ":", "raises", "typepy", ".", "TypeConversionError", ":", "If", "the", "value", "cannot", "convert", "." ]
8209d1df4f2a7f196a9fa4bfb0708c5ff648461f
https://github.com/thombashi/typepy/blob/8209d1df4f2a7f196a9fa4bfb0708c5ff648461f/typepy/type/_base.py#L109-L121
train
jay-johnson/celery-loaders
celery_loaders/work_tasks/always_fails_tasks.py
always_fails
def always_fails( self, work_dict): """always_fails :param work_dict: dictionary for key/values """ label = "always_fails" log.info(("task - {} - start " "work_dict={}") .format(label, work_dict)) raise Exception( work_dict.get( "test_failure", "simulating a failure")) log.info(("task - {} - done") .format(label)) return True
python
def always_fails( self, work_dict): """always_fails :param work_dict: dictionary for key/values """ label = "always_fails" log.info(("task - {} - start " "work_dict={}") .format(label, work_dict)) raise Exception( work_dict.get( "test_failure", "simulating a failure")) log.info(("task - {} - done") .format(label)) return True
[ "def", "always_fails", "(", "self", ",", "work_dict", ")", ":", "label", "=", "\"always_fails\"", "log", ".", "info", "(", "(", "\"task - {} - start \"", "\"work_dict={}\"", ")", ".", "format", "(", "label", ",", "work_dict", ")", ")", "raise", "Exception", "(", "work_dict", ".", "get", "(", "\"test_failure\"", ",", "\"simulating a failure\"", ")", ")", "log", ".", "info", "(", "(", "\"task - {} - done\"", ")", ".", "format", "(", "label", ")", ")", "return", "True" ]
always_fails :param work_dict: dictionary for key/values
[ "always_fails" ]
aca8169c774582af42a377c27cb3980020080814
https://github.com/jay-johnson/celery-loaders/blob/aca8169c774582af42a377c27cb3980020080814/celery_loaders/work_tasks/always_fails_tasks.py#L14-L37
train
glomex/gcdt
gcdt/iam.py
IAMRoleAndPolicies.name_build
def name_build(self, name, is_policy=False, prefix=True): """ Build name from prefix and name + type :param name: Name of the role/policy :param is_policy: True if policy should be added as suffix :param prefix: True if prefix should be added :return: Joined name """ str = name # Add prefix if prefix: str = self.__role_name_prefix + str # Add policy suffix if is_policy: str = str + "-policy" return str
python
def name_build(self, name, is_policy=False, prefix=True): """ Build name from prefix and name + type :param name: Name of the role/policy :param is_policy: True if policy should be added as suffix :param prefix: True if prefix should be added :return: Joined name """ str = name # Add prefix if prefix: str = self.__role_name_prefix + str # Add policy suffix if is_policy: str = str + "-policy" return str
[ "def", "name_build", "(", "self", ",", "name", ",", "is_policy", "=", "False", ",", "prefix", "=", "True", ")", ":", "str", "=", "name", "# Add prefix", "if", "prefix", ":", "str", "=", "self", ".", "__role_name_prefix", "+", "str", "# Add policy suffix", "if", "is_policy", ":", "str", "=", "str", "+", "\"-policy\"", "return", "str" ]
Build name from prefix and name + type :param name: Name of the role/policy :param is_policy: True if policy should be added as suffix :param prefix: True if prefix should be added :return: Joined name
[ "Build", "name", "from", "prefix", "and", "name", "+", "type", ":", "param", "name", ":", "Name", "of", "the", "role", "/", "policy", ":", "param", "is_policy", ":", "True", "if", "policy", "should", "be", "added", "as", "suffix", ":", "param", "prefix", ":", "True", "if", "prefix", "should", "be", "added", ":", "return", ":", "Joined", "name" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/iam.py#L47-L65
train
glomex/gcdt
gcdt/iam.py
IAMRoleAndPolicies.name_strip
def name_strip(self, name, is_policy=False, prefix=True): """ Transforms name to AWS valid characters and adds prefix and type :param name: Name of the role/policy :param is_policy: True if policy should be added as suffix :param prefix: True if prefix should be added :return: Transformed and joined name """ str = self.name_build(name, is_policy, prefix) str = str.title() str = str.replace('-', '') return str
python
def name_strip(self, name, is_policy=False, prefix=True): """ Transforms name to AWS valid characters and adds prefix and type :param name: Name of the role/policy :param is_policy: True if policy should be added as suffix :param prefix: True if prefix should be added :return: Transformed and joined name """ str = self.name_build(name, is_policy, prefix) str = str.title() str = str.replace('-', '') return str
[ "def", "name_strip", "(", "self", ",", "name", ",", "is_policy", "=", "False", ",", "prefix", "=", "True", ")", ":", "str", "=", "self", ".", "name_build", "(", "name", ",", "is_policy", ",", "prefix", ")", "str", "=", "str", ".", "title", "(", ")", "str", "=", "str", ".", "replace", "(", "'-'", ",", "''", ")", "return", "str" ]
Transforms name to AWS valid characters and adds prefix and type :param name: Name of the role/policy :param is_policy: True if policy should be added as suffix :param prefix: True if prefix should be added :return: Transformed and joined name
[ "Transforms", "name", "to", "AWS", "valid", "characters", "and", "adds", "prefix", "and", "type", ":", "param", "name", ":", "Name", "of", "the", "role", "/", "policy", ":", "param", "is_policy", ":", "True", "if", "policy", "should", "be", "added", "as", "suffix", ":", "param", "prefix", ":", "True", "if", "prefix", "should", "be", "added", ":", "return", ":", "Transformed", "and", "joined", "name" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/iam.py#L67-L78
train
glomex/gcdt
gcdt/iam.py
IAMRoleAndPolicies.build_policy
def build_policy(self, name, statements, roles, is_managed_policy=False): """ Generate policy for IAM cloudformation template :param name: Name of the policy :param statements: The "rules" the policy should have :param roles: The roles associated with this policy :param is_managed_policy: True if managed policy :return: Ref to new policy """ if is_managed_policy: policy = ManagedPolicy( self.name_strip(name, True), PolicyDocument={ "Version": self.VERSION_IAM, "Statement": statements, }, Roles=roles, Path=self.__role_path, ) else: policy = PolicyType( self.name_strip(name, True), PolicyName=self.name_strip(name, True), PolicyDocument={ "Version": self.VERSION_IAM, "Statement": statements, }, Roles=roles, ) self.__template.add_resource(policy) return policy
python
def build_policy(self, name, statements, roles, is_managed_policy=False): """ Generate policy for IAM cloudformation template :param name: Name of the policy :param statements: The "rules" the policy should have :param roles: The roles associated with this policy :param is_managed_policy: True if managed policy :return: Ref to new policy """ if is_managed_policy: policy = ManagedPolicy( self.name_strip(name, True), PolicyDocument={ "Version": self.VERSION_IAM, "Statement": statements, }, Roles=roles, Path=self.__role_path, ) else: policy = PolicyType( self.name_strip(name, True), PolicyName=self.name_strip(name, True), PolicyDocument={ "Version": self.VERSION_IAM, "Statement": statements, }, Roles=roles, ) self.__template.add_resource(policy) return policy
[ "def", "build_policy", "(", "self", ",", "name", ",", "statements", ",", "roles", ",", "is_managed_policy", "=", "False", ")", ":", "if", "is_managed_policy", ":", "policy", "=", "ManagedPolicy", "(", "self", ".", "name_strip", "(", "name", ",", "True", ")", ",", "PolicyDocument", "=", "{", "\"Version\"", ":", "self", ".", "VERSION_IAM", ",", "\"Statement\"", ":", "statements", ",", "}", ",", "Roles", "=", "roles", ",", "Path", "=", "self", ".", "__role_path", ",", ")", "else", ":", "policy", "=", "PolicyType", "(", "self", ".", "name_strip", "(", "name", ",", "True", ")", ",", "PolicyName", "=", "self", ".", "name_strip", "(", "name", ",", "True", ")", ",", "PolicyDocument", "=", "{", "\"Version\"", ":", "self", ".", "VERSION_IAM", ",", "\"Statement\"", ":", "statements", ",", "}", ",", "Roles", "=", "roles", ",", ")", "self", ".", "__template", ".", "add_resource", "(", "policy", ")", "return", "policy" ]
Generate policy for IAM cloudformation template :param name: Name of the policy :param statements: The "rules" the policy should have :param roles: The roles associated with this policy :param is_managed_policy: True if managed policy :return: Ref to new policy
[ "Generate", "policy", "for", "IAM", "cloudformation", "template", ":", "param", "name", ":", "Name", "of", "the", "policy", ":", "param", "statements", ":", "The", "rules", "the", "policy", "should", "have", ":", "param", "roles", ":", "The", "roles", "associated", "with", "this", "policy", ":", "param", "is_managed_policy", ":", "True", "if", "managed", "policy", ":", "return", ":", "Ref", "to", "new", "policy" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/iam.py#L80-L111
train
glomex/gcdt
gcdt/iam.py
IAMRoleAndPolicies.build_policy_bucket
def build_policy_bucket(self, bucket, name, statements): """ Generate bucket policy for S3 bucket :param bucket: The bucket to attach policy to :param name: The name of the bucket (to generate policy name from it) :param statements: The "rules" the policy should have :return: Ref to new policy """ policy = self.__template.add_resource( BucketPolicy( self.name_strip(name, True, False), Bucket=troposphere.Ref(bucket), DependsOn=[ troposphere.Name(bucket) ], PolicyDocument=Policy( Version=self.VERSION_IAM, Statement=statements ) ) ) return policy
python
def build_policy_bucket(self, bucket, name, statements): """ Generate bucket policy for S3 bucket :param bucket: The bucket to attach policy to :param name: The name of the bucket (to generate policy name from it) :param statements: The "rules" the policy should have :return: Ref to new policy """ policy = self.__template.add_resource( BucketPolicy( self.name_strip(name, True, False), Bucket=troposphere.Ref(bucket), DependsOn=[ troposphere.Name(bucket) ], PolicyDocument=Policy( Version=self.VERSION_IAM, Statement=statements ) ) ) return policy
[ "def", "build_policy_bucket", "(", "self", ",", "bucket", ",", "name", ",", "statements", ")", ":", "policy", "=", "self", ".", "__template", ".", "add_resource", "(", "BucketPolicy", "(", "self", ".", "name_strip", "(", "name", ",", "True", ",", "False", ")", ",", "Bucket", "=", "troposphere", ".", "Ref", "(", "bucket", ")", ",", "DependsOn", "=", "[", "troposphere", ".", "Name", "(", "bucket", ")", "]", ",", "PolicyDocument", "=", "Policy", "(", "Version", "=", "self", ".", "VERSION_IAM", ",", "Statement", "=", "statements", ")", ")", ")", "return", "policy" ]
Generate bucket policy for S3 bucket :param bucket: The bucket to attach policy to :param name: The name of the bucket (to generate policy name from it) :param statements: The "rules" the policy should have :return: Ref to new policy
[ "Generate", "bucket", "policy", "for", "S3", "bucket", ":", "param", "bucket", ":", "The", "bucket", "to", "attach", "policy", "to", ":", "param", "name", ":", "The", "name", "of", "the", "bucket", "(", "to", "generate", "policy", "name", "from", "it", ")", ":", "param", "statements", ":", "The", "rules", "the", "policy", "should", "have", ":", "return", ":", "Ref", "to", "new", "policy" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/iam.py#L113-L136
train
glomex/gcdt
gcdt/iam.py
IAMRoleAndPolicies.build_role
def build_role(self, name, policies=False): """ Generate role for IAM cloudformation template :param name: Name of role :param policies: List of policies to attach to this role (False = none) :return: Ref to new role """ # Build role template if policies: role = self.__template.add_resource( Role( self.name_strip(name), AssumeRolePolicyDocument=Policy( Version=self.VERSION_IAM, Statement=[ Statement( Effect=Allow, Principal=Principal( "Service", self.__role_principals ), Action=[AssumeRole], ) ] ), Path=self.__role_path, ManagedPolicyArns=policies, )) # Add role to list for default policy self.__roles_list.append(troposphere.Ref(role)) else: role = self.__template.add_resource( Role( self.name_strip(name), AssumeRolePolicyDocument=Policy( Version=self.VERSION_IAM, Statement=[ Statement( Effect=Allow, Principal=Principal( "Service", self.__role_principals ), Action=[AssumeRole], ) ] ), Path=self.__role_path, )) # Add role to list for default policy self.__roles_list.append(troposphere.Ref(role)) return role
python
def build_role(self, name, policies=False): """ Generate role for IAM cloudformation template :param name: Name of role :param policies: List of policies to attach to this role (False = none) :return: Ref to new role """ # Build role template if policies: role = self.__template.add_resource( Role( self.name_strip(name), AssumeRolePolicyDocument=Policy( Version=self.VERSION_IAM, Statement=[ Statement( Effect=Allow, Principal=Principal( "Service", self.__role_principals ), Action=[AssumeRole], ) ] ), Path=self.__role_path, ManagedPolicyArns=policies, )) # Add role to list for default policy self.__roles_list.append(troposphere.Ref(role)) else: role = self.__template.add_resource( Role( self.name_strip(name), AssumeRolePolicyDocument=Policy( Version=self.VERSION_IAM, Statement=[ Statement( Effect=Allow, Principal=Principal( "Service", self.__role_principals ), Action=[AssumeRole], ) ] ), Path=self.__role_path, )) # Add role to list for default policy self.__roles_list.append(troposphere.Ref(role)) return role
[ "def", "build_role", "(", "self", ",", "name", ",", "policies", "=", "False", ")", ":", "# Build role template", "if", "policies", ":", "role", "=", "self", ".", "__template", ".", "add_resource", "(", "Role", "(", "self", ".", "name_strip", "(", "name", ")", ",", "AssumeRolePolicyDocument", "=", "Policy", "(", "Version", "=", "self", ".", "VERSION_IAM", ",", "Statement", "=", "[", "Statement", "(", "Effect", "=", "Allow", ",", "Principal", "=", "Principal", "(", "\"Service\"", ",", "self", ".", "__role_principals", ")", ",", "Action", "=", "[", "AssumeRole", "]", ",", ")", "]", ")", ",", "Path", "=", "self", ".", "__role_path", ",", "ManagedPolicyArns", "=", "policies", ",", ")", ")", "# Add role to list for default policy", "self", ".", "__roles_list", ".", "append", "(", "troposphere", ".", "Ref", "(", "role", ")", ")", "else", ":", "role", "=", "self", ".", "__template", ".", "add_resource", "(", "Role", "(", "self", ".", "name_strip", "(", "name", ")", ",", "AssumeRolePolicyDocument", "=", "Policy", "(", "Version", "=", "self", ".", "VERSION_IAM", ",", "Statement", "=", "[", "Statement", "(", "Effect", "=", "Allow", ",", "Principal", "=", "Principal", "(", "\"Service\"", ",", "self", ".", "__role_principals", ")", ",", "Action", "=", "[", "AssumeRole", "]", ",", ")", "]", ")", ",", "Path", "=", "self", ".", "__role_path", ",", ")", ")", "# Add role to list for default policy", "self", ".", "__roles_list", ".", "append", "(", "troposphere", ".", "Ref", "(", "role", ")", ")", "return", "role" ]
Generate role for IAM cloudformation template :param name: Name of role :param policies: List of policies to attach to this role (False = none) :return: Ref to new role
[ "Generate", "role", "for", "IAM", "cloudformation", "template", ":", "param", "name", ":", "Name", "of", "role", ":", "param", "policies", ":", "List", "of", "policies", "to", "attach", "to", "this", "role", "(", "False", "=", "none", ")", ":", "return", ":", "Ref", "to", "new", "role" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/iam.py#L138-L188
train
glomex/gcdt
gcdt/iam.py
IAMRoleAndPolicies.build_bucket
def build_bucket(self, name, lifecycle_configuration=False, use_plain_name=False): """ Generate S3 bucket statement :param name: Name of the bucket :param lifecycle_configuration: Additional lifecycle configuration (default=False) :param use_plain_name: Just use the given name and do not add prefix :return: Ref to new bucket """ if use_plain_name: name_aws = name_bucket = name name_aws = name_aws.title() name_aws = name_aws.replace('-', '') else: name_aws = self.name_strip(name, False, False) name_bucket = self.name_build(name) if lifecycle_configuration: return self.__template.add_resource( Bucket( name_aws, BucketName=name_bucket, LifecycleConfiguration=lifecycle_configuration ) ) else: return self.__template.add_resource( Bucket( name_aws, BucketName=name_bucket, ) )
python
def build_bucket(self, name, lifecycle_configuration=False, use_plain_name=False): """ Generate S3 bucket statement :param name: Name of the bucket :param lifecycle_configuration: Additional lifecycle configuration (default=False) :param use_plain_name: Just use the given name and do not add prefix :return: Ref to new bucket """ if use_plain_name: name_aws = name_bucket = name name_aws = name_aws.title() name_aws = name_aws.replace('-', '') else: name_aws = self.name_strip(name, False, False) name_bucket = self.name_build(name) if lifecycle_configuration: return self.__template.add_resource( Bucket( name_aws, BucketName=name_bucket, LifecycleConfiguration=lifecycle_configuration ) ) else: return self.__template.add_resource( Bucket( name_aws, BucketName=name_bucket, ) )
[ "def", "build_bucket", "(", "self", ",", "name", ",", "lifecycle_configuration", "=", "False", ",", "use_plain_name", "=", "False", ")", ":", "if", "use_plain_name", ":", "name_aws", "=", "name_bucket", "=", "name", "name_aws", "=", "name_aws", ".", "title", "(", ")", "name_aws", "=", "name_aws", ".", "replace", "(", "'-'", ",", "''", ")", "else", ":", "name_aws", "=", "self", ".", "name_strip", "(", "name", ",", "False", ",", "False", ")", "name_bucket", "=", "self", ".", "name_build", "(", "name", ")", "if", "lifecycle_configuration", ":", "return", "self", ".", "__template", ".", "add_resource", "(", "Bucket", "(", "name_aws", ",", "BucketName", "=", "name_bucket", ",", "LifecycleConfiguration", "=", "lifecycle_configuration", ")", ")", "else", ":", "return", "self", ".", "__template", ".", "add_resource", "(", "Bucket", "(", "name_aws", ",", "BucketName", "=", "name_bucket", ",", ")", ")" ]
Generate S3 bucket statement :param name: Name of the bucket :param lifecycle_configuration: Additional lifecycle configuration (default=False) :param use_plain_name: Just use the given name and do not add prefix :return: Ref to new bucket
[ "Generate", "S3", "bucket", "statement", ":", "param", "name", ":", "Name", "of", "the", "bucket", ":", "param", "lifecycle_configuration", ":", "Additional", "lifecycle", "configuration", "(", "default", "=", "False", ")", ":", "param", "use_plain_name", ":", "Just", "use", "the", "given", "name", "and", "do", "not", "add", "prefix", ":", "return", ":", "Ref", "to", "new", "bucket" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/iam.py#L190-L221
train
DeepHorizons/iarm
iarm/arm_instructions/directives.py
Directives.directive_SPACE
def directive_SPACE(self, label, params): """ label SPACE num Allocate space on the stack. `num` is the number of bytes to allocate """ # TODO allow equations params = params.strip() try: self.convert_to_integer(params) except ValueError: warnings.warn("Unknown parameters; {}".format(params)) return self.labels[label] = self.space_pointer if params in self.equates: params = self.equates[params] self.space_pointer += self.convert_to_integer(params)
python
def directive_SPACE(self, label, params): """ label SPACE num Allocate space on the stack. `num` is the number of bytes to allocate """ # TODO allow equations params = params.strip() try: self.convert_to_integer(params) except ValueError: warnings.warn("Unknown parameters; {}".format(params)) return self.labels[label] = self.space_pointer if params in self.equates: params = self.equates[params] self.space_pointer += self.convert_to_integer(params)
[ "def", "directive_SPACE", "(", "self", ",", "label", ",", "params", ")", ":", "# TODO allow equations", "params", "=", "params", ".", "strip", "(", ")", "try", ":", "self", ".", "convert_to_integer", "(", "params", ")", "except", "ValueError", ":", "warnings", ".", "warn", "(", "\"Unknown parameters; {}\"", ".", "format", "(", "params", ")", ")", "return", "self", ".", "labels", "[", "label", "]", "=", "self", ".", "space_pointer", "if", "params", "in", "self", ".", "equates", ":", "params", "=", "self", ".", "equates", "[", "params", "]", "self", ".", "space_pointer", "+=", "self", ".", "convert_to_integer", "(", "params", ")" ]
label SPACE num Allocate space on the stack. `num` is the number of bytes to allocate
[ "label", "SPACE", "num" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/directives.py#L63-L81
train
DeepHorizons/iarm
iarm/arm_instructions/directives.py
Directives.directive_DCD
def directive_DCD(self, label, params): """ label DCD value[, value ...] Allocate a word space in read only memory for the value or list of values """ # TODO make this read only # TODO check for param size # TODO can take any length comma separated values (VAL DCD 1, 0x2, 3, 4 params = params.strip() try: self.convert_to_integer(params) except ValueError: # TODO allow word DCDs (like SP_INIT, Reset_Handler) warnings.warn("Cannot reserve constant words; {}".format(params)) return # Align address if self.space_pointer % 4 != 0: self.space_pointer += self.space_pointer % 4 self.labels[label] = self.space_pointer if params in self.equates: params = self.equates[params] for i in range(4): self.memory[self.space_pointer + i] = (self.convert_to_integer(params) >> (8*i)) & 0xFF self.space_pointer += 4
python
def directive_DCD(self, label, params): """ label DCD value[, value ...] Allocate a word space in read only memory for the value or list of values """ # TODO make this read only # TODO check for param size # TODO can take any length comma separated values (VAL DCD 1, 0x2, 3, 4 params = params.strip() try: self.convert_to_integer(params) except ValueError: # TODO allow word DCDs (like SP_INIT, Reset_Handler) warnings.warn("Cannot reserve constant words; {}".format(params)) return # Align address if self.space_pointer % 4 != 0: self.space_pointer += self.space_pointer % 4 self.labels[label] = self.space_pointer if params in self.equates: params = self.equates[params] for i in range(4): self.memory[self.space_pointer + i] = (self.convert_to_integer(params) >> (8*i)) & 0xFF self.space_pointer += 4
[ "def", "directive_DCD", "(", "self", ",", "label", ",", "params", ")", ":", "# TODO make this read only", "# TODO check for param size", "# TODO can take any length comma separated values (VAL DCD 1, 0x2, 3, 4", "params", "=", "params", ".", "strip", "(", ")", "try", ":", "self", ".", "convert_to_integer", "(", "params", ")", "except", "ValueError", ":", "# TODO allow word DCDs (like SP_INIT, Reset_Handler)", "warnings", ".", "warn", "(", "\"Cannot reserve constant words; {}\"", ".", "format", "(", "params", ")", ")", "return", "# Align address", "if", "self", ".", "space_pointer", "%", "4", "!=", "0", ":", "self", ".", "space_pointer", "+=", "self", ".", "space_pointer", "%", "4", "self", ".", "labels", "[", "label", "]", "=", "self", ".", "space_pointer", "if", "params", "in", "self", ".", "equates", ":", "params", "=", "self", ".", "equates", "[", "params", "]", "for", "i", "in", "range", "(", "4", ")", ":", "self", ".", "memory", "[", "self", ".", "space_pointer", "+", "i", "]", "=", "(", "self", ".", "convert_to_integer", "(", "params", ")", ">>", "(", "8", "*", "i", ")", ")", "&", "0xFF", "self", ".", "space_pointer", "+=", "4" ]
label DCD value[, value ...] Allocate a word space in read only memory for the value or list of values
[ "label", "DCD", "value", "[", "value", "...", "]" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/directives.py#L92-L118
train
DeepHorizons/iarm
iarm/arm_instructions/directives.py
Directives.directive_DCH
def directive_DCH(self, label, params): """ label DCH value[, value ...] Allocate a half word space in read only memory for the value or list of values """ # TODO make this read only # TODO check for word size # Align address if self.space_pointer % 2 != 0: self.space_pointer += self.space_pointer % 2 self.labels[label] = self.space_pointer if params in self.equates: params = self.equates[params] for i in range(2): self.memory[self.space_pointer + i] = (self.convert_to_integer(params) >> (8 * i)) & 0xFF self.space_pointer += 2
python
def directive_DCH(self, label, params): """ label DCH value[, value ...] Allocate a half word space in read only memory for the value or list of values """ # TODO make this read only # TODO check for word size # Align address if self.space_pointer % 2 != 0: self.space_pointer += self.space_pointer % 2 self.labels[label] = self.space_pointer if params in self.equates: params = self.equates[params] for i in range(2): self.memory[self.space_pointer + i] = (self.convert_to_integer(params) >> (8 * i)) & 0xFF self.space_pointer += 2
[ "def", "directive_DCH", "(", "self", ",", "label", ",", "params", ")", ":", "# TODO make this read only", "# TODO check for word size", "# Align address", "if", "self", ".", "space_pointer", "%", "2", "!=", "0", ":", "self", ".", "space_pointer", "+=", "self", ".", "space_pointer", "%", "2", "self", ".", "labels", "[", "label", "]", "=", "self", ".", "space_pointer", "if", "params", "in", "self", ".", "equates", ":", "params", "=", "self", ".", "equates", "[", "params", "]", "for", "i", "in", "range", "(", "2", ")", ":", "self", ".", "memory", "[", "self", ".", "space_pointer", "+", "i", "]", "=", "(", "self", ".", "convert_to_integer", "(", "params", ")", ">>", "(", "8", "*", "i", ")", ")", "&", "0xFF", "self", ".", "space_pointer", "+=", "2" ]
label DCH value[, value ...] Allocate a half word space in read only memory for the value or list of values
[ "label", "DCH", "value", "[", "value", "...", "]" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/directives.py#L120-L137
train
DeepHorizons/iarm
iarm/arm_instructions/directives.py
Directives.directive_DCB
def directive_DCB(self, label, params): """ label DCB value[, value ...] Allocate a byte space in read only memory for the value or list of values """ # TODO make this read only # TODO check for byte size self.labels[label] = self.space_pointer if params in self.equates: params = self.equates[params] self.memory[self.space_pointer] = self.convert_to_integer(params) & 0xFF self.space_pointer += 1
python
def directive_DCB(self, label, params): """ label DCB value[, value ...] Allocate a byte space in read only memory for the value or list of values """ # TODO make this read only # TODO check for byte size self.labels[label] = self.space_pointer if params in self.equates: params = self.equates[params] self.memory[self.space_pointer] = self.convert_to_integer(params) & 0xFF self.space_pointer += 1
[ "def", "directive_DCB", "(", "self", ",", "label", ",", "params", ")", ":", "# TODO make this read only", "# TODO check for byte size", "self", ".", "labels", "[", "label", "]", "=", "self", ".", "space_pointer", "if", "params", "in", "self", ".", "equates", ":", "params", "=", "self", ".", "equates", "[", "params", "]", "self", ".", "memory", "[", "self", ".", "space_pointer", "]", "=", "self", ".", "convert_to_integer", "(", "params", ")", "&", "0xFF", "self", ".", "space_pointer", "+=", "1" ]
label DCB value[, value ...] Allocate a byte space in read only memory for the value or list of values
[ "label", "DCB", "value", "[", "value", "...", "]" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/directives.py#L139-L151
train
jay-johnson/celery-loaders
celery_loaders/work_tasks/get_celery_app.py
get_celery_app
def get_celery_app( name=os.getenv( "CELERY_NAME", "worker"), auth_url=os.getenv( "BROKER_URL", "redis://localhost:6379/9"), backend_url=os.getenv( "BACKEND_URL", "redis://localhost:6379/10"), include_tasks=[], ssl_options=None, transport_options=None, path_to_config_module=os.getenv( "CONFIG_MODULE_PATH", "celery_loaders.work_tasks.celery_config"), worker_log_format=os.getenv( "WORKER_LOG_FORMAT", "%(asctime)s: %(levelname)s %(message)s"), **kwargs): """get_celery_app :param name: name for this app :param auth_url: celery broker :param backend_url: celery backend :param include_tasks: list of modules containing tasks to add :param ssl_options: security options dictionary :param trasport_options: transport options dictionary :param path_to_config_module: config module :param worker_log_format: format for logs """ if len(include_tasks) == 0: log.error(("creating celery app={} MISSING tasks={}") .format( name, include_tasks)) else: log.info(("creating celery app={} tasks={}") .format( name, include_tasks)) # get the Celery application app = celery.Celery( name, broker_url=auth_url, result_backend=backend_url, include=include_tasks) app.config_from_object( path_to_config_module, namespace="CELERY") app.conf.update(kwargs) if transport_options: log.info(("loading transport_options={}") .format(transport_options)) app.conf.update(**transport_options) # custom tranport options if ssl_options: log.info(("loading ssl_options={}") .format(ssl_options)) app.conf.update(**ssl_options) # custom ssl options if len(include_tasks) > 0: app.autodiscover_tasks(include_tasks) return app
python
def get_celery_app( name=os.getenv( "CELERY_NAME", "worker"), auth_url=os.getenv( "BROKER_URL", "redis://localhost:6379/9"), backend_url=os.getenv( "BACKEND_URL", "redis://localhost:6379/10"), include_tasks=[], ssl_options=None, transport_options=None, path_to_config_module=os.getenv( "CONFIG_MODULE_PATH", "celery_loaders.work_tasks.celery_config"), worker_log_format=os.getenv( "WORKER_LOG_FORMAT", "%(asctime)s: %(levelname)s %(message)s"), **kwargs): """get_celery_app :param name: name for this app :param auth_url: celery broker :param backend_url: celery backend :param include_tasks: list of modules containing tasks to add :param ssl_options: security options dictionary :param trasport_options: transport options dictionary :param path_to_config_module: config module :param worker_log_format: format for logs """ if len(include_tasks) == 0: log.error(("creating celery app={} MISSING tasks={}") .format( name, include_tasks)) else: log.info(("creating celery app={} tasks={}") .format( name, include_tasks)) # get the Celery application app = celery.Celery( name, broker_url=auth_url, result_backend=backend_url, include=include_tasks) app.config_from_object( path_to_config_module, namespace="CELERY") app.conf.update(kwargs) if transport_options: log.info(("loading transport_options={}") .format(transport_options)) app.conf.update(**transport_options) # custom tranport options if ssl_options: log.info(("loading ssl_options={}") .format(ssl_options)) app.conf.update(**ssl_options) # custom ssl options if len(include_tasks) > 0: app.autodiscover_tasks(include_tasks) return app
[ "def", "get_celery_app", "(", "name", "=", "os", ".", "getenv", "(", "\"CELERY_NAME\"", ",", "\"worker\"", ")", ",", "auth_url", "=", "os", ".", "getenv", "(", "\"BROKER_URL\"", ",", "\"redis://localhost:6379/9\"", ")", ",", "backend_url", "=", "os", ".", "getenv", "(", "\"BACKEND_URL\"", ",", "\"redis://localhost:6379/10\"", ")", ",", "include_tasks", "=", "[", "]", ",", "ssl_options", "=", "None", ",", "transport_options", "=", "None", ",", "path_to_config_module", "=", "os", ".", "getenv", "(", "\"CONFIG_MODULE_PATH\"", ",", "\"celery_loaders.work_tasks.celery_config\"", ")", ",", "worker_log_format", "=", "os", ".", "getenv", "(", "\"WORKER_LOG_FORMAT\"", ",", "\"%(asctime)s: %(levelname)s %(message)s\"", ")", ",", "*", "*", "kwargs", ")", ":", "if", "len", "(", "include_tasks", ")", "==", "0", ":", "log", ".", "error", "(", "(", "\"creating celery app={} MISSING tasks={}\"", ")", ".", "format", "(", "name", ",", "include_tasks", ")", ")", "else", ":", "log", ".", "info", "(", "(", "\"creating celery app={} tasks={}\"", ")", ".", "format", "(", "name", ",", "include_tasks", ")", ")", "# get the Celery application", "app", "=", "celery", ".", "Celery", "(", "name", ",", "broker_url", "=", "auth_url", ",", "result_backend", "=", "backend_url", ",", "include", "=", "include_tasks", ")", "app", ".", "config_from_object", "(", "path_to_config_module", ",", "namespace", "=", "\"CELERY\"", ")", "app", ".", "conf", ".", "update", "(", "kwargs", ")", "if", "transport_options", ":", "log", ".", "info", "(", "(", "\"loading transport_options={}\"", ")", ".", "format", "(", "transport_options", ")", ")", "app", ".", "conf", ".", "update", "(", "*", "*", "transport_options", ")", "# custom tranport options", "if", "ssl_options", ":", "log", ".", "info", "(", "(", "\"loading ssl_options={}\"", ")", ".", "format", "(", "ssl_options", ")", ")", "app", ".", "conf", ".", "update", "(", "*", "*", "ssl_options", ")", "# custom ssl options", "if", "len", "(", "include_tasks", ")", ">", "0", ":", "app", ".", "autodiscover_tasks", "(", "include_tasks", ")", "return", "app" ]
get_celery_app :param name: name for this app :param auth_url: celery broker :param backend_url: celery backend :param include_tasks: list of modules containing tasks to add :param ssl_options: security options dictionary :param trasport_options: transport options dictionary :param path_to_config_module: config module :param worker_log_format: format for logs
[ "get_celery_app" ]
aca8169c774582af42a377c27cb3980020080814
https://github.com/jay-johnson/celery-loaders/blob/aca8169c774582af42a377c27cb3980020080814/celery_loaders/work_tasks/get_celery_app.py#L10-L81
train
DeepHorizons/iarm
iarm/cpu.py
RegisterCpu.check_arguments
def check_arguments(self, **kwargs): """ Determine if the parameters meet the specifications kwargs contains lists grouped by their parameter rules are defined by methods starting with 'rule_' :param kwargs: :return: """ for key in kwargs: if key in self._rules: for val in kwargs[key]: self._rules[key](val) else: raise LookupError("Rule for {} does not exist. Make sure the rule starts with 'rule_'".format(key))
python
def check_arguments(self, **kwargs): """ Determine if the parameters meet the specifications kwargs contains lists grouped by their parameter rules are defined by methods starting with 'rule_' :param kwargs: :return: """ for key in kwargs: if key in self._rules: for val in kwargs[key]: self._rules[key](val) else: raise LookupError("Rule for {} does not exist. Make sure the rule starts with 'rule_'".format(key))
[ "def", "check_arguments", "(", "self", ",", "*", "*", "kwargs", ")", ":", "for", "key", "in", "kwargs", ":", "if", "key", "in", "self", ".", "_rules", ":", "for", "val", "in", "kwargs", "[", "key", "]", ":", "self", ".", "_rules", "[", "key", "]", "(", "val", ")", "else", ":", "raise", "LookupError", "(", "\"Rule for {} does not exist. Make sure the rule starts with 'rule_'\"", ".", "format", "(", "key", ")", ")" ]
Determine if the parameters meet the specifications kwargs contains lists grouped by their parameter rules are defined by methods starting with 'rule_' :param kwargs: :return:
[ "Determine", "if", "the", "parameters", "meet", "the", "specifications", "kwargs", "contains", "lists", "grouped", "by", "their", "parameter", "rules", "are", "defined", "by", "methods", "starting", "with", "rule_", ":", "param", "kwargs", ":", ":", "return", ":" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/cpu.py#L60-L73
train
DeepHorizons/iarm
iarm/cpu.py
RandomValueDict.link
def link(self, key1, key2): """ Make these two keys have the same value :param key1: :param key2: :return: """ # TODO make this have more than one key linked # TODO Maybe make the value a set? self._linked_keys[key1] = key2 self._linked_keys[key2] = key1
python
def link(self, key1, key2): """ Make these two keys have the same value :param key1: :param key2: :return: """ # TODO make this have more than one key linked # TODO Maybe make the value a set? self._linked_keys[key1] = key2 self._linked_keys[key2] = key1
[ "def", "link", "(", "self", ",", "key1", ",", "key2", ")", ":", "# TODO make this have more than one key linked", "# TODO Maybe make the value a set?", "self", ".", "_linked_keys", "[", "key1", "]", "=", "key2", "self", ".", "_linked_keys", "[", "key2", "]", "=", "key1" ]
Make these two keys have the same value :param key1: :param key2: :return:
[ "Make", "these", "two", "keys", "have", "the", "same", "value", ":", "param", "key1", ":", ":", "param", "key2", ":", ":", "return", ":" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/cpu.py#L130-L140
train
ninapavlich/django-imagekit-cropper
imagekit_cropper/utils.py
instance_ik_model_receiver
def instance_ik_model_receiver(fn): """ A method decorator that filters out sign_original_specals coming from models that don't have fields that function as ImageFieldSourceGroup sources. """ @wraps(fn) def receiver(self, sender, **kwargs): # print 'inspect.isclass(sender? %s'%(inspect.isclass(sender)) if not inspect.isclass(sender): return for src in self._source_groups: if issubclass(sender, src.model_class): fn(self, sender=sender, **kwargs) # If we find a match, return. We don't want to handle the signal # more than once. return return receiver
python
def instance_ik_model_receiver(fn): """ A method decorator that filters out sign_original_specals coming from models that don't have fields that function as ImageFieldSourceGroup sources. """ @wraps(fn) def receiver(self, sender, **kwargs): # print 'inspect.isclass(sender? %s'%(inspect.isclass(sender)) if not inspect.isclass(sender): return for src in self._source_groups: if issubclass(sender, src.model_class): fn(self, sender=sender, **kwargs) # If we find a match, return. We don't want to handle the signal # more than once. return return receiver
[ "def", "instance_ik_model_receiver", "(", "fn", ")", ":", "@", "wraps", "(", "fn", ")", "def", "receiver", "(", "self", ",", "sender", ",", "*", "*", "kwargs", ")", ":", "# print 'inspect.isclass(sender? %s'%(inspect.isclass(sender))", "if", "not", "inspect", ".", "isclass", "(", "sender", ")", ":", "return", "for", "src", "in", "self", ".", "_source_groups", ":", "if", "issubclass", "(", "sender", ",", "src", ".", "model_class", ")", ":", "fn", "(", "self", ",", "sender", "=", "sender", ",", "*", "*", "kwargs", ")", "# If we find a match, return. We don't want to handle the signal", "# more than once.", "return", "return", "receiver" ]
A method decorator that filters out sign_original_specals coming from models that don't have fields that function as ImageFieldSourceGroup sources.
[ "A", "method", "decorator", "that", "filters", "out", "sign_original_specals", "coming", "from", "models", "that", "don", "t", "have", "fields", "that", "function", "as", "ImageFieldSourceGroup", "sources", "." ]
c1c2dc5c3c4724492052e5d244e9de1cc362dbcc
https://github.com/ninapavlich/django-imagekit-cropper/blob/c1c2dc5c3c4724492052e5d244e9de1cc362dbcc/imagekit_cropper/utils.py#L32-L50
train
ninapavlich/django-imagekit-cropper
imagekit_cropper/utils.py
InstanceSourceGroupRegistry.source_group_receiver
def source_group_receiver(self, sender, source, signal, **kwargs): """ Relay source group signals to the appropriate spec strategy. """ from imagekit.cachefiles import ImageCacheFile source_group = sender instance = kwargs['instance'] # Ignore signals from unregistered groups. if source_group not in self._source_groups: return #HOOK -- update source to point to image file. for id in self._source_groups[source_group]: spec_to_update = generator_registry.get(id, source=source, instance=instance, field=hack_spec_field_hash[id]) specs = [generator_registry.get(id, source=source, instance=instance, field=hack_spec_field_hash[id]) for id in self._source_groups[source_group]] callback_name = self._signals[signal] # print 'callback_name? %s'%(callback_name) for spec in specs: file = ImageCacheFile(spec) # print 'SEPC %s file %s'%(spec, file) call_strategy_method(file, callback_name)
python
def source_group_receiver(self, sender, source, signal, **kwargs): """ Relay source group signals to the appropriate spec strategy. """ from imagekit.cachefiles import ImageCacheFile source_group = sender instance = kwargs['instance'] # Ignore signals from unregistered groups. if source_group not in self._source_groups: return #HOOK -- update source to point to image file. for id in self._source_groups[source_group]: spec_to_update = generator_registry.get(id, source=source, instance=instance, field=hack_spec_field_hash[id]) specs = [generator_registry.get(id, source=source, instance=instance, field=hack_spec_field_hash[id]) for id in self._source_groups[source_group]] callback_name = self._signals[signal] # print 'callback_name? %s'%(callback_name) for spec in specs: file = ImageCacheFile(spec) # print 'SEPC %s file %s'%(spec, file) call_strategy_method(file, callback_name)
[ "def", "source_group_receiver", "(", "self", ",", "sender", ",", "source", ",", "signal", ",", "*", "*", "kwargs", ")", ":", "from", "imagekit", ".", "cachefiles", "import", "ImageCacheFile", "source_group", "=", "sender", "instance", "=", "kwargs", "[", "'instance'", "]", "# Ignore signals from unregistered groups.", "if", "source_group", "not", "in", "self", ".", "_source_groups", ":", "return", "#HOOK -- update source to point to image file.", "for", "id", "in", "self", ".", "_source_groups", "[", "source_group", "]", ":", "spec_to_update", "=", "generator_registry", ".", "get", "(", "id", ",", "source", "=", "source", ",", "instance", "=", "instance", ",", "field", "=", "hack_spec_field_hash", "[", "id", "]", ")", "specs", "=", "[", "generator_registry", ".", "get", "(", "id", ",", "source", "=", "source", ",", "instance", "=", "instance", ",", "field", "=", "hack_spec_field_hash", "[", "id", "]", ")", "for", "id", "in", "self", ".", "_source_groups", "[", "source_group", "]", "]", "callback_name", "=", "self", ".", "_signals", "[", "signal", "]", "# print 'callback_name? %s'%(callback_name)", "for", "spec", "in", "specs", ":", "file", "=", "ImageCacheFile", "(", "spec", ")", "# print 'SEPC %s file %s'%(spec, file)", "call_strategy_method", "(", "file", ",", "callback_name", ")" ]
Relay source group signals to the appropriate spec strategy.
[ "Relay", "source", "group", "signals", "to", "the", "appropriate", "spec", "strategy", "." ]
c1c2dc5c3c4724492052e5d244e9de1cc362dbcc
https://github.com/ninapavlich/django-imagekit-cropper/blob/c1c2dc5c3c4724492052e5d244e9de1cc362dbcc/imagekit_cropper/utils.py#L87-L114
train
ninapavlich/django-imagekit-cropper
imagekit_cropper/utils.py
InstanceModelSignalRouter.update_source_hashes
def update_source_hashes(self, instance): """ Stores hashes of the source image files so that they can be compared later to see whether the source image has changed (and therefore whether the spec file needs to be regenerated). """ self.init_instance(instance) instance._ik['source_hashes'] = dict( (attname, hash(getattr(instance, attname))) for attname in self.get_source_fields(instance)) return instance._ik['source_hashes']
python
def update_source_hashes(self, instance): """ Stores hashes of the source image files so that they can be compared later to see whether the source image has changed (and therefore whether the spec file needs to be regenerated). """ self.init_instance(instance) instance._ik['source_hashes'] = dict( (attname, hash(getattr(instance, attname))) for attname in self.get_source_fields(instance)) return instance._ik['source_hashes']
[ "def", "update_source_hashes", "(", "self", ",", "instance", ")", ":", "self", ".", "init_instance", "(", "instance", ")", "instance", ".", "_ik", "[", "'source_hashes'", "]", "=", "dict", "(", "(", "attname", ",", "hash", "(", "getattr", "(", "instance", ",", "attname", ")", ")", ")", "for", "attname", "in", "self", ".", "get_source_fields", "(", "instance", ")", ")", "return", "instance", ".", "_ik", "[", "'source_hashes'", "]" ]
Stores hashes of the source image files so that they can be compared later to see whether the source image has changed (and therefore whether the spec file needs to be regenerated).
[ "Stores", "hashes", "of", "the", "source", "image", "files", "so", "that", "they", "can", "be", "compared", "later", "to", "see", "whether", "the", "source", "image", "has", "changed", "(", "and", "therefore", "whether", "the", "spec", "file", "needs", "to", "be", "regenerated", ")", "." ]
c1c2dc5c3c4724492052e5d244e9de1cc362dbcc
https://github.com/ninapavlich/django-imagekit-cropper/blob/c1c2dc5c3c4724492052e5d244e9de1cc362dbcc/imagekit_cropper/utils.py#L134-L145
train
ninapavlich/django-imagekit-cropper
imagekit_cropper/utils.py
InstanceModelSignalRouter.get_source_fields
def get_source_fields(self, instance): """ Returns a list of the source fields for the given instance. """ return set(src.image_field for src in self._source_groups if isinstance(instance, src.model_class))
python
def get_source_fields(self, instance): """ Returns a list of the source fields for the given instance. """ return set(src.image_field for src in self._source_groups if isinstance(instance, src.model_class))
[ "def", "get_source_fields", "(", "self", ",", "instance", ")", ":", "return", "set", "(", "src", ".", "image_field", "for", "src", "in", "self", ".", "_source_groups", "if", "isinstance", "(", "instance", ",", "src", ".", "model_class", ")", ")" ]
Returns a list of the source fields for the given instance.
[ "Returns", "a", "list", "of", "the", "source", "fields", "for", "the", "given", "instance", "." ]
c1c2dc5c3c4724492052e5d244e9de1cc362dbcc
https://github.com/ninapavlich/django-imagekit-cropper/blob/c1c2dc5c3c4724492052e5d244e9de1cc362dbcc/imagekit_cropper/utils.py#L147-L153
train
jay-johnson/celery-loaders
celery_loaders/work_tasks/custom_task.py
CustomTask.on_success
def on_success(self, retval, task_id, args, kwargs): """on_success http://docs.celeryproject.org/en/latest/reference/celery.app.task.html :param retval: return value :param task_id: celery task id :param args: arguments passed into task :param kwargs: keyword arguments passed into task """ log.info(("{} SUCCESS - retval={} task_id={} " "args={} kwargs={}") .format( self.log_label, retval, task_id, args, kwargs))
python
def on_success(self, retval, task_id, args, kwargs): """on_success http://docs.celeryproject.org/en/latest/reference/celery.app.task.html :param retval: return value :param task_id: celery task id :param args: arguments passed into task :param kwargs: keyword arguments passed into task """ log.info(("{} SUCCESS - retval={} task_id={} " "args={} kwargs={}") .format( self.log_label, retval, task_id, args, kwargs))
[ "def", "on_success", "(", "self", ",", "retval", ",", "task_id", ",", "args", ",", "kwargs", ")", ":", "log", ".", "info", "(", "(", "\"{} SUCCESS - retval={} task_id={} \"", "\"args={} kwargs={}\"", ")", ".", "format", "(", "self", ".", "log_label", ",", "retval", ",", "task_id", ",", "args", ",", "kwargs", ")", ")" ]
on_success http://docs.celeryproject.org/en/latest/reference/celery.app.task.html :param retval: return value :param task_id: celery task id :param args: arguments passed into task :param kwargs: keyword arguments passed into task
[ "on_success" ]
aca8169c774582af42a377c27cb3980020080814
https://github.com/jay-johnson/celery-loaders/blob/aca8169c774582af42a377c27cb3980020080814/celery_loaders/work_tasks/custom_task.py#L14-L32
train
jay-johnson/celery-loaders
celery_loaders/work_tasks/custom_task.py
CustomTask.on_failure
def on_failure(self, exc, task_id, args, kwargs, einfo): """on_failure http://docs.celeryproject.org/en/latest/userguide/tasks.html#task-inheritance :param exc: exception :param task_id: task id :param args: arguments passed into task :param kwargs: keyword arguments passed into task :param einfo: exception info """ use_exc = str(exc) log.error(("{} FAIL - exc={} " "args={} kwargs={}") .format( self.log_label, use_exc, args, kwargs))
python
def on_failure(self, exc, task_id, args, kwargs, einfo): """on_failure http://docs.celeryproject.org/en/latest/userguide/tasks.html#task-inheritance :param exc: exception :param task_id: task id :param args: arguments passed into task :param kwargs: keyword arguments passed into task :param einfo: exception info """ use_exc = str(exc) log.error(("{} FAIL - exc={} " "args={} kwargs={}") .format( self.log_label, use_exc, args, kwargs))
[ "def", "on_failure", "(", "self", ",", "exc", ",", "task_id", ",", "args", ",", "kwargs", ",", "einfo", ")", ":", "use_exc", "=", "str", "(", "exc", ")", "log", ".", "error", "(", "(", "\"{} FAIL - exc={} \"", "\"args={} kwargs={}\"", ")", ".", "format", "(", "self", ".", "log_label", ",", "use_exc", ",", "args", ",", "kwargs", ")", ")" ]
on_failure http://docs.celeryproject.org/en/latest/userguide/tasks.html#task-inheritance :param exc: exception :param task_id: task id :param args: arguments passed into task :param kwargs: keyword arguments passed into task :param einfo: exception info
[ "on_failure" ]
aca8169c774582af42a377c27cb3980020080814
https://github.com/jay-johnson/celery-loaders/blob/aca8169c774582af42a377c27cb3980020080814/celery_loaders/work_tasks/custom_task.py#L35-L54
train
glomex/gcdt
gcdt/gcdt_signals.py
check_hook_mechanism_is_intact
def check_hook_mechanism_is_intact(module): """Check if the hook configuration is absent or has both register AND deregister. :param module: :return: True if valid plugin / module. """ result = True if check_register_present(module): result = not result if check_deregister_present(module): result = not result return result
python
def check_hook_mechanism_is_intact(module): """Check if the hook configuration is absent or has both register AND deregister. :param module: :return: True if valid plugin / module. """ result = True if check_register_present(module): result = not result if check_deregister_present(module): result = not result return result
[ "def", "check_hook_mechanism_is_intact", "(", "module", ")", ":", "result", "=", "True", "if", "check_register_present", "(", "module", ")", ":", "result", "=", "not", "result", "if", "check_deregister_present", "(", "module", ")", ":", "result", "=", "not", "result", "return", "result" ]
Check if the hook configuration is absent or has both register AND deregister. :param module: :return: True if valid plugin / module.
[ "Check", "if", "the", "hook", "configuration", "is", "absent", "or", "has", "both", "register", "AND", "deregister", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/gcdt_signals.py#L59-L70
train
glomex/gcdt
gcdt/kumo_viz.py
cfn_viz
def cfn_viz(template, parameters={}, outputs={}, out=sys.stdout): """Render dot output for cloudformation.template in json format. """ known_sg, open_sg = _analyze_sg(template['Resources']) (graph, edges) = _extract_graph(template.get('Description', ''), template['Resources'], known_sg, open_sg) graph['edges'].extend(edges) _handle_terminals(template, graph, 'Parameters', 'source', parameters) _handle_terminals(template, graph, 'Outputs', 'sink', outputs) graph['subgraphs'].append(_handle_pseudo_params(graph['edges'])) _render(graph, out=out)
python
def cfn_viz(template, parameters={}, outputs={}, out=sys.stdout): """Render dot output for cloudformation.template in json format. """ known_sg, open_sg = _analyze_sg(template['Resources']) (graph, edges) = _extract_graph(template.get('Description', ''), template['Resources'], known_sg, open_sg) graph['edges'].extend(edges) _handle_terminals(template, graph, 'Parameters', 'source', parameters) _handle_terminals(template, graph, 'Outputs', 'sink', outputs) graph['subgraphs'].append(_handle_pseudo_params(graph['edges'])) _render(graph, out=out)
[ "def", "cfn_viz", "(", "template", ",", "parameters", "=", "{", "}", ",", "outputs", "=", "{", "}", ",", "out", "=", "sys", ".", "stdout", ")", ":", "known_sg", ",", "open_sg", "=", "_analyze_sg", "(", "template", "[", "'Resources'", "]", ")", "(", "graph", ",", "edges", ")", "=", "_extract_graph", "(", "template", ".", "get", "(", "'Description'", ",", "''", ")", ",", "template", "[", "'Resources'", "]", ",", "known_sg", ",", "open_sg", ")", "graph", "[", "'edges'", "]", ".", "extend", "(", "edges", ")", "_handle_terminals", "(", "template", ",", "graph", ",", "'Parameters'", ",", "'source'", ",", "parameters", ")", "_handle_terminals", "(", "template", ",", "graph", ",", "'Outputs'", ",", "'sink'", ",", "outputs", ")", "graph", "[", "'subgraphs'", "]", ".", "append", "(", "_handle_pseudo_params", "(", "graph", "[", "'edges'", "]", ")", ")", "_render", "(", "graph", ",", "out", "=", "out", ")" ]
Render dot output for cloudformation.template in json format.
[ "Render", "dot", "output", "for", "cloudformation", ".", "template", "in", "json", "format", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_viz.py#L30-L41
train
glomex/gcdt
gcdt/kumo_viz.py
_get_fillcolor
def _get_fillcolor(resource_type, properties, known_sg=[], open_sg=[]): """Determine fillcolor for resources (public ones in this case) """ fillcolor = None # check security groups if 'SecurityGroups' in properties: # check for external security groups for sg in properties['SecurityGroups']: if 'Ref' in sg and (sg['Ref'] not in known_sg): fillcolor = 'yellow' break # check for open security groups for osg in open_sg: if {'Ref': osg} in properties['SecurityGroups']: fillcolor = 'red' break # LoadBalancer if resource_type == 'LoadBalancer': if ('Scheme' not in properties) or \ properties['Scheme'] == 'internet-facing': fillcolor = 'red' return fillcolor
python
def _get_fillcolor(resource_type, properties, known_sg=[], open_sg=[]): """Determine fillcolor for resources (public ones in this case) """ fillcolor = None # check security groups if 'SecurityGroups' in properties: # check for external security groups for sg in properties['SecurityGroups']: if 'Ref' in sg and (sg['Ref'] not in known_sg): fillcolor = 'yellow' break # check for open security groups for osg in open_sg: if {'Ref': osg} in properties['SecurityGroups']: fillcolor = 'red' break # LoadBalancer if resource_type == 'LoadBalancer': if ('Scheme' not in properties) or \ properties['Scheme'] == 'internet-facing': fillcolor = 'red' return fillcolor
[ "def", "_get_fillcolor", "(", "resource_type", ",", "properties", ",", "known_sg", "=", "[", "]", ",", "open_sg", "=", "[", "]", ")", ":", "fillcolor", "=", "None", "# check security groups", "if", "'SecurityGroups'", "in", "properties", ":", "# check for external security groups", "for", "sg", "in", "properties", "[", "'SecurityGroups'", "]", ":", "if", "'Ref'", "in", "sg", "and", "(", "sg", "[", "'Ref'", "]", "not", "in", "known_sg", ")", ":", "fillcolor", "=", "'yellow'", "break", "# check for open security groups", "for", "osg", "in", "open_sg", ":", "if", "{", "'Ref'", ":", "osg", "}", "in", "properties", "[", "'SecurityGroups'", "]", ":", "fillcolor", "=", "'red'", "break", "# LoadBalancer", "if", "resource_type", "==", "'LoadBalancer'", ":", "if", "(", "'Scheme'", "not", "in", "properties", ")", "or", "properties", "[", "'Scheme'", "]", "==", "'internet-facing'", ":", "fillcolor", "=", "'red'", "return", "fillcolor" ]
Determine fillcolor for resources (public ones in this case)
[ "Determine", "fillcolor", "for", "resources", "(", "public", "ones", "in", "this", "case", ")" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_viz.py#L109-L133
train
glomex/gcdt
gcdt/kumo_viz.py
svg_output
def svg_output(dotfile, outfile='cloudformation.svg'): """Render template into svg file using the dot command (must be installed). :param dotfile: path to the dotfile :param outfile: filename for the output file :return: """ try: cmd = ['dot', '-Tsvg', '-o' + outfile, dotfile] subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: sys.stderr.write( '\033[01;31mError running command: %s resulted in the ' % e.cmd + 'following error: \033[01;32m %s' % e.output) return 1 return 0
python
def svg_output(dotfile, outfile='cloudformation.svg'): """Render template into svg file using the dot command (must be installed). :param dotfile: path to the dotfile :param outfile: filename for the output file :return: """ try: cmd = ['dot', '-Tsvg', '-o' + outfile, dotfile] subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: sys.stderr.write( '\033[01;31mError running command: %s resulted in the ' % e.cmd + 'following error: \033[01;32m %s' % e.output) return 1 return 0
[ "def", "svg_output", "(", "dotfile", ",", "outfile", "=", "'cloudformation.svg'", ")", ":", "try", ":", "cmd", "=", "[", "'dot'", ",", "'-Tsvg'", ",", "'-o'", "+", "outfile", ",", "dotfile", "]", "subprocess", ".", "check_output", "(", "cmd", ",", "stderr", "=", "subprocess", ".", "STDOUT", ")", "except", "subprocess", ".", "CalledProcessError", "as", "e", ":", "sys", ".", "stderr", ".", "write", "(", "'\\033[01;31mError running command: %s resulted in the '", "%", "e", ".", "cmd", "+", "'following error: \\033[01;32m %s'", "%", "e", ".", "output", ")", "return", "1", "return", "0" ]
Render template into svg file using the dot command (must be installed). :param dotfile: path to the dotfile :param outfile: filename for the output file :return:
[ "Render", "template", "into", "svg", "file", "using", "the", "dot", "command", "(", "must", "be", "installed", ")", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_viz.py#L238-L254
train
gmr/helper
helper/__init__.py
start
def start(controller_class): """Start the Helper controller either in the foreground or as a daemon process. :param controller_class: The controller class handle to create and run :type controller_class: callable """ args = parser.parse() obj = controller_class(args, platform.operating_system()) if args.foreground: try: obj.start() except KeyboardInterrupt: obj.stop() else: try: with platform.Daemon(obj) as daemon: daemon.start() except (OSError, ValueError) as error: sys.stderr.write('\nError starting %s: %s\n\n' % (sys.argv[0], error)) sys.exit(1)
python
def start(controller_class): """Start the Helper controller either in the foreground or as a daemon process. :param controller_class: The controller class handle to create and run :type controller_class: callable """ args = parser.parse() obj = controller_class(args, platform.operating_system()) if args.foreground: try: obj.start() except KeyboardInterrupt: obj.stop() else: try: with platform.Daemon(obj) as daemon: daemon.start() except (OSError, ValueError) as error: sys.stderr.write('\nError starting %s: %s\n\n' % (sys.argv[0], error)) sys.exit(1)
[ "def", "start", "(", "controller_class", ")", ":", "args", "=", "parser", ".", "parse", "(", ")", "obj", "=", "controller_class", "(", "args", ",", "platform", ".", "operating_system", "(", ")", ")", "if", "args", ".", "foreground", ":", "try", ":", "obj", ".", "start", "(", ")", "except", "KeyboardInterrupt", ":", "obj", ".", "stop", "(", ")", "else", ":", "try", ":", "with", "platform", ".", "Daemon", "(", "obj", ")", "as", "daemon", ":", "daemon", ".", "start", "(", ")", "except", "(", "OSError", ",", "ValueError", ")", "as", "error", ":", "sys", ".", "stderr", ".", "write", "(", "'\\nError starting %s: %s\\n\\n'", "%", "(", "sys", ".", "argv", "[", "0", "]", ",", "error", ")", ")", "sys", ".", "exit", "(", "1", ")" ]
Start the Helper controller either in the foreground or as a daemon process. :param controller_class: The controller class handle to create and run :type controller_class: callable
[ "Start", "the", "Helper", "controller", "either", "in", "the", "foreground", "or", "as", "a", "daemon", "process", "." ]
fe8e45fc8eabf619429b2940c682c252ee33c082
https://github.com/gmr/helper/blob/fe8e45fc8eabf619429b2940c682c252ee33c082/helper/__init__.py#L149-L171
train
DeepHorizons/iarm
iarm/arm.py
Arm.run
def run(self, steps=float('inf')): """ Run to the current end of the program or a number of steps :return: """ while len(self.program) > (self.register['PC'] - 1): steps -= 1 if steps < 0: break self.program[self.register['PC'] - 1]() self.register['PC'] += 1
python
def run(self, steps=float('inf')): """ Run to the current end of the program or a number of steps :return: """ while len(self.program) > (self.register['PC'] - 1): steps -= 1 if steps < 0: break self.program[self.register['PC'] - 1]() self.register['PC'] += 1
[ "def", "run", "(", "self", ",", "steps", "=", "float", "(", "'inf'", ")", ")", ":", "while", "len", "(", "self", ".", "program", ")", ">", "(", "self", ".", "register", "[", "'PC'", "]", "-", "1", ")", ":", "steps", "-=", "1", "if", "steps", "<", "0", ":", "break", "self", ".", "program", "[", "self", ".", "register", "[", "'PC'", "]", "-", "1", "]", "(", ")", "self", ".", "register", "[", "'PC'", "]", "+=", "1" ]
Run to the current end of the program or a number of steps :return:
[ "Run", "to", "the", "current", "end", "of", "the", "program", "or", "a", "number", "of", "steps", ":", "return", ":" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm.py#L91-L101
train
CitrineInformatics/pypif
pypif/obj/common/pio.py
Pio._validate_type
def _validate_type(self, name, obj, *args): """ Helper function that checks the input object type against each in a list of classes. This function also allows the input value to be equal to None. :param name: Name of the object. :param obj: Object to check the type of. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types. """ if obj is None: return for arg in args: if isinstance(obj, arg): return raise TypeError(self.__class__.__name__ + '.' + name + ' is of type ' + type(obj).__name__ + '. Must be equal to None or one of the following types: ' + str(args))
python
def _validate_type(self, name, obj, *args): """ Helper function that checks the input object type against each in a list of classes. This function also allows the input value to be equal to None. :param name: Name of the object. :param obj: Object to check the type of. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types. """ if obj is None: return for arg in args: if isinstance(obj, arg): return raise TypeError(self.__class__.__name__ + '.' + name + ' is of type ' + type(obj).__name__ + '. Must be equal to None or one of the following types: ' + str(args))
[ "def", "_validate_type", "(", "self", ",", "name", ",", "obj", ",", "*", "args", ")", ":", "if", "obj", "is", "None", ":", "return", "for", "arg", "in", "args", ":", "if", "isinstance", "(", "obj", ",", "arg", ")", ":", "return", "raise", "TypeError", "(", "self", ".", "__class__", ".", "__name__", "+", "'.'", "+", "name", "+", "' is of type '", "+", "type", "(", "obj", ")", ".", "__name__", "+", "'. Must be equal to None or one of the following types: '", "+", "str", "(", "args", ")", ")" ]
Helper function that checks the input object type against each in a list of classes. This function also allows the input value to be equal to None. :param name: Name of the object. :param obj: Object to check the type of. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types.
[ "Helper", "function", "that", "checks", "the", "input", "object", "type", "against", "each", "in", "a", "list", "of", "classes", ".", "This", "function", "also", "allows", "the", "input", "value", "to", "be", "equal", "to", "None", "." ]
938348a8ff7b10b330770cccaaeb2109922f681b
https://github.com/CitrineInformatics/pypif/blob/938348a8ff7b10b330770cccaaeb2109922f681b/pypif/obj/common/pio.py#L36-L52
train
CitrineInformatics/pypif
pypif/obj/common/pio.py
Pio._validate_list_type
def _validate_list_type(self, name, obj, *args): """ Helper function that checks the input object type against each in a list of classes, or if the input object is a list, each value that it contains against that list. :param name: Name of the object. :param obj: Object to check the type of. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types. """ if obj is None: return if isinstance(obj, list): for i in obj: self._validate_type_not_null(name, i, *args) else: self._validate_type(name, obj, *args)
python
def _validate_list_type(self, name, obj, *args): """ Helper function that checks the input object type against each in a list of classes, or if the input object is a list, each value that it contains against that list. :param name: Name of the object. :param obj: Object to check the type of. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types. """ if obj is None: return if isinstance(obj, list): for i in obj: self._validate_type_not_null(name, i, *args) else: self._validate_type(name, obj, *args)
[ "def", "_validate_list_type", "(", "self", ",", "name", ",", "obj", ",", "*", "args", ")", ":", "if", "obj", "is", "None", ":", "return", "if", "isinstance", "(", "obj", ",", "list", ")", ":", "for", "i", "in", "obj", ":", "self", ".", "_validate_type_not_null", "(", "name", ",", "i", ",", "*", "args", ")", "else", ":", "self", ".", "_validate_type", "(", "name", ",", "obj", ",", "*", "args", ")" ]
Helper function that checks the input object type against each in a list of classes, or if the input object is a list, each value that it contains against that list. :param name: Name of the object. :param obj: Object to check the type of. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types.
[ "Helper", "function", "that", "checks", "the", "input", "object", "type", "against", "each", "in", "a", "list", "of", "classes", "or", "if", "the", "input", "object", "is", "a", "list", "each", "value", "that", "it", "contains", "against", "that", "list", "." ]
938348a8ff7b10b330770cccaaeb2109922f681b
https://github.com/CitrineInformatics/pypif/blob/938348a8ff7b10b330770cccaaeb2109922f681b/pypif/obj/common/pio.py#L69-L85
train
CitrineInformatics/pypif
pypif/obj/common/pio.py
Pio._validate_nested_list_type
def _validate_nested_list_type(self, name, obj, nested_level, *args): """ Helper function that checks the input object as a list then recursively until nested_level is 1. :param name: Name of the object. :param obj: Object to check the type of. :param nested_level: Integer with the current nested level. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types. """ if nested_level <= 1: self._validate_list_type(name, obj, *args) else: if obj is None: return if not isinstance(obj, list): raise TypeError(self.__class__.__name__ + '.' + name + ' contains value of type ' + type(obj).__name__ + ' where a list is expected') for sub_obj in obj: self._validate_nested_list_type(name, sub_obj, nested_level - 1, *args)
python
def _validate_nested_list_type(self, name, obj, nested_level, *args): """ Helper function that checks the input object as a list then recursively until nested_level is 1. :param name: Name of the object. :param obj: Object to check the type of. :param nested_level: Integer with the current nested level. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types. """ if nested_level <= 1: self._validate_list_type(name, obj, *args) else: if obj is None: return if not isinstance(obj, list): raise TypeError(self.__class__.__name__ + '.' + name + ' contains value of type ' + type(obj).__name__ + ' where a list is expected') for sub_obj in obj: self._validate_nested_list_type(name, sub_obj, nested_level - 1, *args)
[ "def", "_validate_nested_list_type", "(", "self", ",", "name", ",", "obj", ",", "nested_level", ",", "*", "args", ")", ":", "if", "nested_level", "<=", "1", ":", "self", ".", "_validate_list_type", "(", "name", ",", "obj", ",", "*", "args", ")", "else", ":", "if", "obj", "is", "None", ":", "return", "if", "not", "isinstance", "(", "obj", ",", "list", ")", ":", "raise", "TypeError", "(", "self", ".", "__class__", ".", "__name__", "+", "'.'", "+", "name", "+", "' contains value of type '", "+", "type", "(", "obj", ")", ".", "__name__", "+", "' where a list is expected'", ")", "for", "sub_obj", "in", "obj", ":", "self", ".", "_validate_nested_list_type", "(", "name", ",", "sub_obj", ",", "nested_level", "-", "1", ",", "*", "args", ")" ]
Helper function that checks the input object as a list then recursively until nested_level is 1. :param name: Name of the object. :param obj: Object to check the type of. :param nested_level: Integer with the current nested level. :param args: List of classes. :raises TypeError: if the input object is not of any of the allowed types.
[ "Helper", "function", "that", "checks", "the", "input", "object", "as", "a", "list", "then", "recursively", "until", "nested_level", "is", "1", "." ]
938348a8ff7b10b330770cccaaeb2109922f681b
https://github.com/CitrineInformatics/pypif/blob/938348a8ff7b10b330770cccaaeb2109922f681b/pypif/obj/common/pio.py#L87-L106
train
DeepHorizons/iarm
iarm/arm_instructions/unconditional_branch.py
UnconditionalBranch.B
def B(self, params): """ B label Unconditional branch to the address at label """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # TODO check if label is within +- 2 KB # B label def B_func(): if label == '.': raise iarm.exceptions.EndOfProgram("You have reached an infinite loop") self.register['PC'] = self.labels[label] return B_func
python
def B(self, params): """ B label Unconditional branch to the address at label """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # TODO check if label is within +- 2 KB # B label def B_func(): if label == '.': raise iarm.exceptions.EndOfProgram("You have reached an infinite loop") self.register['PC'] = self.labels[label] return B_func
[ "def", "B", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# TODO check if label is within +- 2 KB", "# B label", "def", "B_func", "(", ")", ":", "if", "label", "==", "'.'", ":", "raise", "iarm", ".", "exceptions", ".", "EndOfProgram", "(", "\"You have reached an infinite loop\"", ")", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "B_func" ]
B label Unconditional branch to the address at label
[ "B", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/unconditional_branch.py#L6-L23
train
DeepHorizons/iarm
iarm/arm_instructions/unconditional_branch.py
UnconditionalBranch.BL
def BL(self, params): """ BL label Branch to the label, storing the next instruction in the Link Register """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # TODO check if label is within +- 16 MB # BL label def BL_func(): self.register['LR'] = self.register['PC'] # No need for the + 1, PC already points to the next instruction self.register['PC'] = self.labels[label] return BL_func
python
def BL(self, params): """ BL label Branch to the label, storing the next instruction in the Link Register """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # TODO check if label is within +- 16 MB # BL label def BL_func(): self.register['LR'] = self.register['PC'] # No need for the + 1, PC already points to the next instruction self.register['PC'] = self.labels[label] return BL_func
[ "def", "BL", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# TODO check if label is within +- 16 MB", "# BL label", "def", "BL_func", "(", ")", ":", "self", ".", "register", "[", "'LR'", "]", "=", "self", ".", "register", "[", "'PC'", "]", "# No need for the + 1, PC already points to the next instruction", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BL_func" ]
BL label Branch to the label, storing the next instruction in the Link Register
[ "BL", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/unconditional_branch.py#L33-L49
train
DeepHorizons/iarm
iarm/arm_instructions/unconditional_branch.py
UnconditionalBranch.BLX
def BLX(self, params): """ BLX Rj Branch to the address in Rj, storing the next instruction in the Link Register """ Rj = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(LR_or_general_purpose_registers=(Rj,)) def BLX_func(): self.register['LR'] = self.register['PC'] # No need for the + 1, PC already points to the next instruction self.register['PC'] = self.register[Rj] return BLX_func
python
def BLX(self, params): """ BLX Rj Branch to the address in Rj, storing the next instruction in the Link Register """ Rj = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(LR_or_general_purpose_registers=(Rj,)) def BLX_func(): self.register['LR'] = self.register['PC'] # No need for the + 1, PC already points to the next instruction self.register['PC'] = self.register[Rj] return BLX_func
[ "def", "BLX", "(", "self", ",", "params", ")", ":", "Rj", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "LR_or_general_purpose_registers", "=", "(", "Rj", ",", ")", ")", "def", "BLX_func", "(", ")", ":", "self", ".", "register", "[", "'LR'", "]", "=", "self", ".", "register", "[", "'PC'", "]", "# No need for the + 1, PC already points to the next instruction", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "register", "[", "Rj", "]", "return", "BLX_func" ]
BLX Rj Branch to the address in Rj, storing the next instruction in the Link Register
[ "BLX", "Rj" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/unconditional_branch.py#L51-L65
train
DeepHorizons/iarm
iarm/arm_instructions/unconditional_branch.py
UnconditionalBranch.BX
def BX(self, params): """ BX Rj Jump to the address in the Link Register """ Rj = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(LR_or_general_purpose_registers=(Rj,)) def BX_func(): self.register['PC'] = self.register[Rj] return BX_func
python
def BX(self, params): """ BX Rj Jump to the address in the Link Register """ Rj = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(LR_or_general_purpose_registers=(Rj,)) def BX_func(): self.register['PC'] = self.register[Rj] return BX_func
[ "def", "BX", "(", "self", ",", "params", ")", ":", "Rj", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "LR_or_general_purpose_registers", "=", "(", "Rj", ",", ")", ")", "def", "BX_func", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "register", "[", "Rj", "]", "return", "BX_func" ]
BX Rj Jump to the address in the Link Register
[ "BX", "Rj" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/unconditional_branch.py#L67-L80
train
clarkperkins/click-shell
click_shell/version.py
get_version
def get_version(version): """ Returns a PEP 440-compliant version number from VERSION. Created by modifying django.utils.version.get_version """ # Now build the two parts of the version number: # major = X.Y[.Z] # sub = .devN - for development releases # | {a|b|rc}N - for alpha, beta and rc releases # | .postN - for post-release releases assert len(version) == 5 version_parts = version[:2] if version[2] == 0 else version[:3] # Build the first part of the version major = '.'.join(str(x) for x in version_parts) # Just return it if this is a final release version if version[3] == 'final': return major # Add the rest sub = ''.join(str(x) for x in version[3:5]) if version[3] == 'dev': # Override the sub part. Add in a timestamp timestamp = get_git_changeset() sub = 'dev%s' % (timestamp if timestamp else version[4]) return '%s.%s' % (major, sub) if version[3] == 'post': # We need a dot for post return '%s.%s' % (major, sub) elif version[3] in ('a', 'b', 'rc'): # No dot for these return '%s%s' % (major, sub) else: raise ValueError('Invalid version: %s' % str(version))
python
def get_version(version): """ Returns a PEP 440-compliant version number from VERSION. Created by modifying django.utils.version.get_version """ # Now build the two parts of the version number: # major = X.Y[.Z] # sub = .devN - for development releases # | {a|b|rc}N - for alpha, beta and rc releases # | .postN - for post-release releases assert len(version) == 5 version_parts = version[:2] if version[2] == 0 else version[:3] # Build the first part of the version major = '.'.join(str(x) for x in version_parts) # Just return it if this is a final release version if version[3] == 'final': return major # Add the rest sub = ''.join(str(x) for x in version[3:5]) if version[3] == 'dev': # Override the sub part. Add in a timestamp timestamp = get_git_changeset() sub = 'dev%s' % (timestamp if timestamp else version[4]) return '%s.%s' % (major, sub) if version[3] == 'post': # We need a dot for post return '%s.%s' % (major, sub) elif version[3] in ('a', 'b', 'rc'): # No dot for these return '%s%s' % (major, sub) else: raise ValueError('Invalid version: %s' % str(version))
[ "def", "get_version", "(", "version", ")", ":", "# Now build the two parts of the version number:", "# major = X.Y[.Z]", "# sub = .devN - for development releases", "# | {a|b|rc}N - for alpha, beta and rc releases", "# | .postN - for post-release releases", "assert", "len", "(", "version", ")", "==", "5", "version_parts", "=", "version", "[", ":", "2", "]", "if", "version", "[", "2", "]", "==", "0", "else", "version", "[", ":", "3", "]", "# Build the first part of the version", "major", "=", "'.'", ".", "join", "(", "str", "(", "x", ")", "for", "x", "in", "version_parts", ")", "# Just return it if this is a final release version", "if", "version", "[", "3", "]", "==", "'final'", ":", "return", "major", "# Add the rest", "sub", "=", "''", ".", "join", "(", "str", "(", "x", ")", "for", "x", "in", "version", "[", "3", ":", "5", "]", ")", "if", "version", "[", "3", "]", "==", "'dev'", ":", "# Override the sub part. Add in a timestamp", "timestamp", "=", "get_git_changeset", "(", ")", "sub", "=", "'dev%s'", "%", "(", "timestamp", "if", "timestamp", "else", "version", "[", "4", "]", ")", "return", "'%s.%s'", "%", "(", "major", ",", "sub", ")", "if", "version", "[", "3", "]", "==", "'post'", ":", "# We need a dot for post", "return", "'%s.%s'", "%", "(", "major", ",", "sub", ")", "elif", "version", "[", "3", "]", "in", "(", "'a'", ",", "'b'", ",", "'rc'", ")", ":", "# No dot for these", "return", "'%s%s'", "%", "(", "major", ",", "sub", ")", "else", ":", "raise", "ValueError", "(", "'Invalid version: %s'", "%", "str", "(", "version", ")", ")" ]
Returns a PEP 440-compliant version number from VERSION. Created by modifying django.utils.version.get_version
[ "Returns", "a", "PEP", "440", "-", "compliant", "version", "number", "from", "VERSION", "." ]
8d6e1a492176bc79e029d714f19d3156409656ea
https://github.com/clarkperkins/click-shell/blob/8d6e1a492176bc79e029d714f19d3156409656ea/click_shell/version.py#L15-L54
train
clarkperkins/click-shell
click_shell/version.py
get_git_changeset
def get_git_changeset(): """Returns a numeric identifier of the latest git changeset. The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. This value isn't guaranteed to be unique, but collisions are very unlikely, so it's sufficient for generating the development version numbers. """ repo_dir = os.path.dirname(os.path.abspath(__file__)) git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=repo_dir, universal_newlines=True) timestamp = git_log.communicate()[0] try: timestamp = datetime.datetime.utcfromtimestamp(int(timestamp)) return timestamp.strftime('%Y%m%d%H%M%S') except ValueError: return None
python
def get_git_changeset(): """Returns a numeric identifier of the latest git changeset. The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. This value isn't guaranteed to be unique, but collisions are very unlikely, so it's sufficient for generating the development version numbers. """ repo_dir = os.path.dirname(os.path.abspath(__file__)) git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=repo_dir, universal_newlines=True) timestamp = git_log.communicate()[0] try: timestamp = datetime.datetime.utcfromtimestamp(int(timestamp)) return timestamp.strftime('%Y%m%d%H%M%S') except ValueError: return None
[ "def", "get_git_changeset", "(", ")", ":", "repo_dir", "=", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "abspath", "(", "__file__", ")", ")", "git_log", "=", "subprocess", ".", "Popen", "(", "'git log --pretty=format:%ct --quiet -1 HEAD'", ",", "stdout", "=", "subprocess", ".", "PIPE", ",", "stderr", "=", "subprocess", ".", "PIPE", ",", "shell", "=", "True", ",", "cwd", "=", "repo_dir", ",", "universal_newlines", "=", "True", ")", "timestamp", "=", "git_log", ".", "communicate", "(", ")", "[", "0", "]", "try", ":", "timestamp", "=", "datetime", ".", "datetime", ".", "utcfromtimestamp", "(", "int", "(", "timestamp", ")", ")", "return", "timestamp", ".", "strftime", "(", "'%Y%m%d%H%M%S'", ")", "except", "ValueError", ":", "return", "None" ]
Returns a numeric identifier of the latest git changeset. The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. This value isn't guaranteed to be unique, but collisions are very unlikely, so it's sufficient for generating the development version numbers.
[ "Returns", "a", "numeric", "identifier", "of", "the", "latest", "git", "changeset", "." ]
8d6e1a492176bc79e029d714f19d3156409656ea
https://github.com/clarkperkins/click-shell/blob/8d6e1a492176bc79e029d714f19d3156409656ea/click_shell/version.py#L58-L74
train
glomex/gcdt
gcdt/kumo_core.py
load_cloudformation_template
def load_cloudformation_template(path=None): """Load cloudformation template from path. :param path: Absolute or relative path of cloudformation template. Defaults to cwd. :return: module, success """ if not path: path = os.path.abspath('cloudformation.py') else: path = os.path.abspath(path) if isinstance(path, six.string_types): try: sp = sys.path # temporarily add folder to allow relative path sys.path.append(os.path.abspath(os.path.dirname(path))) cloudformation = imp.load_source('cloudformation', path) sys.path = sp # restore # use cfn template hooks if not check_hook_mechanism_is_intact(cloudformation): # no hooks - do nothing log.debug( 'No valid hook configuration: \'%s\'. Not using hooks!', path) else: if check_register_present(cloudformation): # register the template hooks so they listen to gcdt_signals cloudformation.register() return cloudformation, True except GracefulExit: raise except ImportError as e: print('could not find package for import: %s' % e) except Exception as e: print('could not import cloudformation.py, maybe something wrong ', 'with your code?') print(e) return None, False
python
def load_cloudformation_template(path=None): """Load cloudformation template from path. :param path: Absolute or relative path of cloudformation template. Defaults to cwd. :return: module, success """ if not path: path = os.path.abspath('cloudformation.py') else: path = os.path.abspath(path) if isinstance(path, six.string_types): try: sp = sys.path # temporarily add folder to allow relative path sys.path.append(os.path.abspath(os.path.dirname(path))) cloudformation = imp.load_source('cloudformation', path) sys.path = sp # restore # use cfn template hooks if not check_hook_mechanism_is_intact(cloudformation): # no hooks - do nothing log.debug( 'No valid hook configuration: \'%s\'. Not using hooks!', path) else: if check_register_present(cloudformation): # register the template hooks so they listen to gcdt_signals cloudformation.register() return cloudformation, True except GracefulExit: raise except ImportError as e: print('could not find package for import: %s' % e) except Exception as e: print('could not import cloudformation.py, maybe something wrong ', 'with your code?') print(e) return None, False
[ "def", "load_cloudformation_template", "(", "path", "=", "None", ")", ":", "if", "not", "path", ":", "path", "=", "os", ".", "path", ".", "abspath", "(", "'cloudformation.py'", ")", "else", ":", "path", "=", "os", ".", "path", ".", "abspath", "(", "path", ")", "if", "isinstance", "(", "path", ",", "six", ".", "string_types", ")", ":", "try", ":", "sp", "=", "sys", ".", "path", "# temporarily add folder to allow relative path", "sys", ".", "path", ".", "append", "(", "os", ".", "path", ".", "abspath", "(", "os", ".", "path", ".", "dirname", "(", "path", ")", ")", ")", "cloudformation", "=", "imp", ".", "load_source", "(", "'cloudformation'", ",", "path", ")", "sys", ".", "path", "=", "sp", "# restore", "# use cfn template hooks", "if", "not", "check_hook_mechanism_is_intact", "(", "cloudformation", ")", ":", "# no hooks - do nothing", "log", ".", "debug", "(", "'No valid hook configuration: \\'%s\\'. Not using hooks!'", ",", "path", ")", "else", ":", "if", "check_register_present", "(", "cloudformation", ")", ":", "# register the template hooks so they listen to gcdt_signals", "cloudformation", ".", "register", "(", ")", "return", "cloudformation", ",", "True", "except", "GracefulExit", ":", "raise", "except", "ImportError", "as", "e", ":", "print", "(", "'could not find package for import: %s'", "%", "e", ")", "except", "Exception", "as", "e", ":", "print", "(", "'could not import cloudformation.py, maybe something wrong '", ",", "'with your code?'", ")", "print", "(", "e", ")", "return", "None", ",", "False" ]
Load cloudformation template from path. :param path: Absolute or relative path of cloudformation template. Defaults to cwd. :return: module, success
[ "Load", "cloudformation", "template", "from", "path", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L28-L64
train
glomex/gcdt
gcdt/kumo_core.py
get_parameter_diff
def get_parameter_diff(awsclient, config): """get differences between local config and currently active config """ client_cf = awsclient.get_client('cloudformation') try: stack_name = config['stack']['StackName'] if stack_name: response = client_cf.describe_stacks(StackName=stack_name) if response['Stacks']: stack_id = response['Stacks'][0]['StackId'] stack = response['Stacks'][0] else: return None else: print( 'StackName is not configured, could not create parameter diff') return None except GracefulExit: raise except Exception: # probably the stack is not existent return None changed = 0 table = [] table.append(['Parameter', 'Current Value', 'New Value']) # Check if there are parameters for the stack if 'Parameters' in stack: for param in stack['Parameters']: try: old = str(param['ParameterValue']) # can not compare list with str!! # if ',' in old: # old = old.split(',') new = config['parameters'][param['ParameterKey']] if old != new: if old.startswith('***'): # parameter is configured with `NoEcho=True` # this means we can not really say if the value changed!! # for security reasons we block viewing the new value new = old table.append([param['ParameterKey'], old, new]) changed += 1 except GracefulExit: raise except Exception: print('Did not find %s in local config file' % param[ 'ParameterKey']) if changed > 0: print(tabulate(table, tablefmt='fancy_grid')) return changed > 0
python
def get_parameter_diff(awsclient, config): """get differences between local config and currently active config """ client_cf = awsclient.get_client('cloudformation') try: stack_name = config['stack']['StackName'] if stack_name: response = client_cf.describe_stacks(StackName=stack_name) if response['Stacks']: stack_id = response['Stacks'][0]['StackId'] stack = response['Stacks'][0] else: return None else: print( 'StackName is not configured, could not create parameter diff') return None except GracefulExit: raise except Exception: # probably the stack is not existent return None changed = 0 table = [] table.append(['Parameter', 'Current Value', 'New Value']) # Check if there are parameters for the stack if 'Parameters' in stack: for param in stack['Parameters']: try: old = str(param['ParameterValue']) # can not compare list with str!! # if ',' in old: # old = old.split(',') new = config['parameters'][param['ParameterKey']] if old != new: if old.startswith('***'): # parameter is configured with `NoEcho=True` # this means we can not really say if the value changed!! # for security reasons we block viewing the new value new = old table.append([param['ParameterKey'], old, new]) changed += 1 except GracefulExit: raise except Exception: print('Did not find %s in local config file' % param[ 'ParameterKey']) if changed > 0: print(tabulate(table, tablefmt='fancy_grid')) return changed > 0
[ "def", "get_parameter_diff", "(", "awsclient", ",", "config", ")", ":", "client_cf", "=", "awsclient", ".", "get_client", "(", "'cloudformation'", ")", "try", ":", "stack_name", "=", "config", "[", "'stack'", "]", "[", "'StackName'", "]", "if", "stack_name", ":", "response", "=", "client_cf", ".", "describe_stacks", "(", "StackName", "=", "stack_name", ")", "if", "response", "[", "'Stacks'", "]", ":", "stack_id", "=", "response", "[", "'Stacks'", "]", "[", "0", "]", "[", "'StackId'", "]", "stack", "=", "response", "[", "'Stacks'", "]", "[", "0", "]", "else", ":", "return", "None", "else", ":", "print", "(", "'StackName is not configured, could not create parameter diff'", ")", "return", "None", "except", "GracefulExit", ":", "raise", "except", "Exception", ":", "# probably the stack is not existent", "return", "None", "changed", "=", "0", "table", "=", "[", "]", "table", ".", "append", "(", "[", "'Parameter'", ",", "'Current Value'", ",", "'New Value'", "]", ")", "# Check if there are parameters for the stack", "if", "'Parameters'", "in", "stack", ":", "for", "param", "in", "stack", "[", "'Parameters'", "]", ":", "try", ":", "old", "=", "str", "(", "param", "[", "'ParameterValue'", "]", ")", "# can not compare list with str!!", "# if ',' in old:", "# old = old.split(',')", "new", "=", "config", "[", "'parameters'", "]", "[", "param", "[", "'ParameterKey'", "]", "]", "if", "old", "!=", "new", ":", "if", "old", ".", "startswith", "(", "'***'", ")", ":", "# parameter is configured with `NoEcho=True`", "# this means we can not really say if the value changed!!", "# for security reasons we block viewing the new value", "new", "=", "old", "table", ".", "append", "(", "[", "param", "[", "'ParameterKey'", "]", ",", "old", ",", "new", "]", ")", "changed", "+=", "1", "except", "GracefulExit", ":", "raise", "except", "Exception", ":", "print", "(", "'Did not find %s in local config file'", "%", "param", "[", "'ParameterKey'", "]", ")", "if", "changed", ">", "0", ":", "print", "(", "tabulate", "(", "table", ",", "tablefmt", "=", "'fancy_grid'", ")", ")", "return", "changed", ">", "0" ]
get differences between local config and currently active config
[ "get", "differences", "between", "local", "config", "and", "currently", "active", "config" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L67-L120
train
glomex/gcdt
gcdt/kumo_core.py
call_pre_hook
def call_pre_hook(awsclient, cloudformation): """Invoke the pre_hook BEFORE the config is read. :param awsclient: :param cloudformation: """ # TODO: this is deprecated!! move this to glomex_config_reader # no config available if not hasattr(cloudformation, 'pre_hook'): # hook is not present return hook_func = getattr(cloudformation, 'pre_hook') if not hook_func.func_code.co_argcount: hook_func() # for compatibility with existing templates else: log.error('pre_hock can not have any arguments. The pre_hook it is ' + 'executed BEFORE config is read')
python
def call_pre_hook(awsclient, cloudformation): """Invoke the pre_hook BEFORE the config is read. :param awsclient: :param cloudformation: """ # TODO: this is deprecated!! move this to glomex_config_reader # no config available if not hasattr(cloudformation, 'pre_hook'): # hook is not present return hook_func = getattr(cloudformation, 'pre_hook') if not hook_func.func_code.co_argcount: hook_func() # for compatibility with existing templates else: log.error('pre_hock can not have any arguments. The pre_hook it is ' + 'executed BEFORE config is read')
[ "def", "call_pre_hook", "(", "awsclient", ",", "cloudformation", ")", ":", "# TODO: this is deprecated!! move this to glomex_config_reader", "# no config available", "if", "not", "hasattr", "(", "cloudformation", ",", "'pre_hook'", ")", ":", "# hook is not present", "return", "hook_func", "=", "getattr", "(", "cloudformation", ",", "'pre_hook'", ")", "if", "not", "hook_func", ".", "func_code", ".", "co_argcount", ":", "hook_func", "(", ")", "# for compatibility with existing templates", "else", ":", "log", ".", "error", "(", "'pre_hock can not have any arguments. The pre_hook it is '", "+", "'executed BEFORE config is read'", ")" ]
Invoke the pre_hook BEFORE the config is read. :param awsclient: :param cloudformation:
[ "Invoke", "the", "pre_hook", "BEFORE", "the", "config", "is", "read", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L123-L139
train
glomex/gcdt
gcdt/kumo_core.py
deploy_stack
def deploy_stack(awsclient, context, conf, cloudformation, override_stack_policy=False): """Deploy the stack to AWS cloud. Does either create or update the stack. :param conf: :param override_stack_policy: :return: exit_code """ stack_name = _get_stack_name(conf) parameters = _generate_parameters(conf) if stack_exists(awsclient, stack_name): exit_code = _update_stack(awsclient, context, conf, cloudformation, parameters, override_stack_policy) else: exit_code = _create_stack(awsclient, context, conf, cloudformation, parameters) # add 'stack_output' to the context so it becomes available # in 'command_finalized' hook context['stack_output'] = _get_stack_outputs( awsclient.get_client('cloudformation'), stack_name) _call_hook(awsclient, conf, stack_name, parameters, cloudformation, hook='post_hook', message='CloudFormation is done, now executing post hook...') return exit_code
python
def deploy_stack(awsclient, context, conf, cloudformation, override_stack_policy=False): """Deploy the stack to AWS cloud. Does either create or update the stack. :param conf: :param override_stack_policy: :return: exit_code """ stack_name = _get_stack_name(conf) parameters = _generate_parameters(conf) if stack_exists(awsclient, stack_name): exit_code = _update_stack(awsclient, context, conf, cloudformation, parameters, override_stack_policy) else: exit_code = _create_stack(awsclient, context, conf, cloudformation, parameters) # add 'stack_output' to the context so it becomes available # in 'command_finalized' hook context['stack_output'] = _get_stack_outputs( awsclient.get_client('cloudformation'), stack_name) _call_hook(awsclient, conf, stack_name, parameters, cloudformation, hook='post_hook', message='CloudFormation is done, now executing post hook...') return exit_code
[ "def", "deploy_stack", "(", "awsclient", ",", "context", ",", "conf", ",", "cloudformation", ",", "override_stack_policy", "=", "False", ")", ":", "stack_name", "=", "_get_stack_name", "(", "conf", ")", "parameters", "=", "_generate_parameters", "(", "conf", ")", "if", "stack_exists", "(", "awsclient", ",", "stack_name", ")", ":", "exit_code", "=", "_update_stack", "(", "awsclient", ",", "context", ",", "conf", ",", "cloudformation", ",", "parameters", ",", "override_stack_policy", ")", "else", ":", "exit_code", "=", "_create_stack", "(", "awsclient", ",", "context", ",", "conf", ",", "cloudformation", ",", "parameters", ")", "# add 'stack_output' to the context so it becomes available", "# in 'command_finalized' hook", "context", "[", "'stack_output'", "]", "=", "_get_stack_outputs", "(", "awsclient", ".", "get_client", "(", "'cloudformation'", ")", ",", "stack_name", ")", "_call_hook", "(", "awsclient", ",", "conf", ",", "stack_name", ",", "parameters", ",", "cloudformation", ",", "hook", "=", "'post_hook'", ",", "message", "=", "'CloudFormation is done, now executing post hook...'", ")", "return", "exit_code" ]
Deploy the stack to AWS cloud. Does either create or update the stack. :param conf: :param override_stack_policy: :return: exit_code
[ "Deploy", "the", "stack", "to", "AWS", "cloud", ".", "Does", "either", "create", "or", "update", "the", "stack", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L322-L344
train
glomex/gcdt
gcdt/kumo_core.py
delete_stack
def delete_stack(awsclient, conf, feedback=True): """Delete the stack from AWS cloud. :param awsclient: :param conf: :param feedback: print out stack events (defaults to True) """ client_cf = awsclient.get_client('cloudformation') stack_name = _get_stack_name(conf) last_event = _get_stack_events_last_timestamp(awsclient, stack_name) request = {} dict_selective_merge(request, conf['stack'], ['StackName', 'RoleARN']) response = client_cf.delete_stack(**request) if feedback: return _poll_stack_events(awsclient, stack_name, last_event)
python
def delete_stack(awsclient, conf, feedback=True): """Delete the stack from AWS cloud. :param awsclient: :param conf: :param feedback: print out stack events (defaults to True) """ client_cf = awsclient.get_client('cloudformation') stack_name = _get_stack_name(conf) last_event = _get_stack_events_last_timestamp(awsclient, stack_name) request = {} dict_selective_merge(request, conf['stack'], ['StackName', 'RoleARN']) response = client_cf.delete_stack(**request) if feedback: return _poll_stack_events(awsclient, stack_name, last_event)
[ "def", "delete_stack", "(", "awsclient", ",", "conf", ",", "feedback", "=", "True", ")", ":", "client_cf", "=", "awsclient", ".", "get_client", "(", "'cloudformation'", ")", "stack_name", "=", "_get_stack_name", "(", "conf", ")", "last_event", "=", "_get_stack_events_last_timestamp", "(", "awsclient", ",", "stack_name", ")", "request", "=", "{", "}", "dict_selective_merge", "(", "request", ",", "conf", "[", "'stack'", "]", ",", "[", "'StackName'", ",", "'RoleARN'", "]", ")", "response", "=", "client_cf", ".", "delete_stack", "(", "*", "*", "request", ")", "if", "feedback", ":", "return", "_poll_stack_events", "(", "awsclient", ",", "stack_name", ",", "last_event", ")" ]
Delete the stack from AWS cloud. :param awsclient: :param conf: :param feedback: print out stack events (defaults to True)
[ "Delete", "the", "stack", "from", "AWS", "cloud", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L526-L543
train
glomex/gcdt
gcdt/kumo_core.py
list_stacks
def list_stacks(awsclient): """Print out the list of stacks deployed at AWS cloud. :param awsclient: :return: """ client_cf = awsclient.get_client('cloudformation') response = client_cf.list_stacks( StackStatusFilter=[ 'CREATE_IN_PROGRESS', 'CREATE_COMPLETE', 'ROLLBACK_IN_PROGRESS', 'ROLLBACK_COMPLETE', 'DELETE_IN_PROGRESS', 'DELETE_FAILED', 'UPDATE_IN_PROGRESS', 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_IN_PROGRESS', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS', 'UPDATE_ROLLBACK_COMPLETE', ] ) result = {} stack_sum = 0 for summary in response['StackSummaries']: result['StackName'] = summary["StackName"] result['CreationTime'] = summary['CreationTime'] result['StackStatus'] = summary['StackStatus'] print(json2table(result)) stack_sum += 1 print('listed %s stacks' % str(stack_sum))
python
def list_stacks(awsclient): """Print out the list of stacks deployed at AWS cloud. :param awsclient: :return: """ client_cf = awsclient.get_client('cloudformation') response = client_cf.list_stacks( StackStatusFilter=[ 'CREATE_IN_PROGRESS', 'CREATE_COMPLETE', 'ROLLBACK_IN_PROGRESS', 'ROLLBACK_COMPLETE', 'DELETE_IN_PROGRESS', 'DELETE_FAILED', 'UPDATE_IN_PROGRESS', 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_IN_PROGRESS', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS', 'UPDATE_ROLLBACK_COMPLETE', ] ) result = {} stack_sum = 0 for summary in response['StackSummaries']: result['StackName'] = summary["StackName"] result['CreationTime'] = summary['CreationTime'] result['StackStatus'] = summary['StackStatus'] print(json2table(result)) stack_sum += 1 print('listed %s stacks' % str(stack_sum))
[ "def", "list_stacks", "(", "awsclient", ")", ":", "client_cf", "=", "awsclient", ".", "get_client", "(", "'cloudformation'", ")", "response", "=", "client_cf", ".", "list_stacks", "(", "StackStatusFilter", "=", "[", "'CREATE_IN_PROGRESS'", ",", "'CREATE_COMPLETE'", ",", "'ROLLBACK_IN_PROGRESS'", ",", "'ROLLBACK_COMPLETE'", ",", "'DELETE_IN_PROGRESS'", ",", "'DELETE_FAILED'", ",", "'UPDATE_IN_PROGRESS'", ",", "'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS'", ",", "'UPDATE_COMPLETE'", ",", "'UPDATE_ROLLBACK_IN_PROGRESS'", ",", "'UPDATE_ROLLBACK_FAILED'", ",", "'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS'", ",", "'UPDATE_ROLLBACK_COMPLETE'", ",", "]", ")", "result", "=", "{", "}", "stack_sum", "=", "0", "for", "summary", "in", "response", "[", "'StackSummaries'", "]", ":", "result", "[", "'StackName'", "]", "=", "summary", "[", "\"StackName\"", "]", "result", "[", "'CreationTime'", "]", "=", "summary", "[", "'CreationTime'", "]", "result", "[", "'StackStatus'", "]", "=", "summary", "[", "'StackStatus'", "]", "print", "(", "json2table", "(", "result", ")", ")", "stack_sum", "+=", "1", "print", "(", "'listed %s stacks'", "%", "str", "(", "stack_sum", ")", ")" ]
Print out the list of stacks deployed at AWS cloud. :param awsclient: :return:
[ "Print", "out", "the", "list", "of", "stacks", "deployed", "at", "AWS", "cloud", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L554-L580
train
glomex/gcdt
gcdt/kumo_core.py
describe_change_set
def describe_change_set(awsclient, change_set_name, stack_name): """Print out the change_set to console. This needs to run create_change_set first. :param awsclient: :param change_set_name: :param stack_name: """ client = awsclient.get_client('cloudformation') status = None while status not in ['CREATE_COMPLETE', 'FAILED']: response = client.describe_change_set( ChangeSetName=change_set_name, StackName=stack_name) status = response['Status'] # print('##### %s' % status) if status == 'FAILED': print(response['StatusReason']) elif status == 'CREATE_COMPLETE': for change in response['Changes']: print(json2table(change['ResourceChange']))
python
def describe_change_set(awsclient, change_set_name, stack_name): """Print out the change_set to console. This needs to run create_change_set first. :param awsclient: :param change_set_name: :param stack_name: """ client = awsclient.get_client('cloudformation') status = None while status not in ['CREATE_COMPLETE', 'FAILED']: response = client.describe_change_set( ChangeSetName=change_set_name, StackName=stack_name) status = response['Status'] # print('##### %s' % status) if status == 'FAILED': print(response['StatusReason']) elif status == 'CREATE_COMPLETE': for change in response['Changes']: print(json2table(change['ResourceChange']))
[ "def", "describe_change_set", "(", "awsclient", ",", "change_set_name", ",", "stack_name", ")", ":", "client", "=", "awsclient", ".", "get_client", "(", "'cloudformation'", ")", "status", "=", "None", "while", "status", "not", "in", "[", "'CREATE_COMPLETE'", ",", "'FAILED'", "]", ":", "response", "=", "client", ".", "describe_change_set", "(", "ChangeSetName", "=", "change_set_name", ",", "StackName", "=", "stack_name", ")", "status", "=", "response", "[", "'Status'", "]", "# print('##### %s' % status)", "if", "status", "==", "'FAILED'", ":", "print", "(", "response", "[", "'StatusReason'", "]", ")", "elif", "status", "==", "'CREATE_COMPLETE'", ":", "for", "change", "in", "response", "[", "'Changes'", "]", ":", "print", "(", "json2table", "(", "change", "[", "'ResourceChange'", "]", ")", ")" ]
Print out the change_set to console. This needs to run create_change_set first. :param awsclient: :param change_set_name: :param stack_name:
[ "Print", "out", "the", "change_set", "to", "console", ".", "This", "needs", "to", "run", "create_change_set", "first", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L608-L629
train
glomex/gcdt
gcdt/kumo_core.py
delete_change_set
def delete_change_set(awsclient, change_set_name, stack_name): """Delete specified change set. Currently we only use this during automated regression testing. But we have plans so lets locate this functionality here :param awsclient: :param change_set_name: :param stack_name: """ client = awsclient.get_client('cloudformation') response = client.delete_change_set( ChangeSetName=change_set_name, StackName=stack_name)
python
def delete_change_set(awsclient, change_set_name, stack_name): """Delete specified change set. Currently we only use this during automated regression testing. But we have plans so lets locate this functionality here :param awsclient: :param change_set_name: :param stack_name: """ client = awsclient.get_client('cloudformation') response = client.delete_change_set( ChangeSetName=change_set_name, StackName=stack_name)
[ "def", "delete_change_set", "(", "awsclient", ",", "change_set_name", ",", "stack_name", ")", ":", "client", "=", "awsclient", ".", "get_client", "(", "'cloudformation'", ")", "response", "=", "client", ".", "delete_change_set", "(", "ChangeSetName", "=", "change_set_name", ",", "StackName", "=", "stack_name", ")" ]
Delete specified change set. Currently we only use this during automated regression testing. But we have plans so lets locate this functionality here :param awsclient: :param change_set_name: :param stack_name:
[ "Delete", "specified", "change", "set", ".", "Currently", "we", "only", "use", "this", "during", "automated", "regression", "testing", ".", "But", "we", "have", "plans", "so", "lets", "locate", "this", "functionality", "here" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L632-L645
train
glomex/gcdt
gcdt/kumo_core.py
write_template_to_file
def write_template_to_file(conf, template_body): """Writes the template to disk """ template_file_name = _get_stack_name(conf) + '-generated-cf-template.json' with open(template_file_name, 'w') as opened_file: opened_file.write(template_body) print('wrote cf-template for %s to disk: %s' % ( get_env(), template_file_name)) return template_file_name
python
def write_template_to_file(conf, template_body): """Writes the template to disk """ template_file_name = _get_stack_name(conf) + '-generated-cf-template.json' with open(template_file_name, 'w') as opened_file: opened_file.write(template_body) print('wrote cf-template for %s to disk: %s' % ( get_env(), template_file_name)) return template_file_name
[ "def", "write_template_to_file", "(", "conf", ",", "template_body", ")", ":", "template_file_name", "=", "_get_stack_name", "(", "conf", ")", "+", "'-generated-cf-template.json'", "with", "open", "(", "template_file_name", ",", "'w'", ")", "as", "opened_file", ":", "opened_file", ".", "write", "(", "template_body", ")", "print", "(", "'wrote cf-template for %s to disk: %s'", "%", "(", "get_env", "(", ")", ",", "template_file_name", ")", ")", "return", "template_file_name" ]
Writes the template to disk
[ "Writes", "the", "template", "to", "disk" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L658-L666
train
glomex/gcdt
gcdt/kumo_core.py
generate_template
def generate_template(context, config, cloudformation): """call cloudformation to generate the template (json format). :param context: :param config: :param cloudformation: :return: """ spec = inspect.getargspec(cloudformation.generate_template)[0] if len(spec) == 0: return cloudformation.generate_template() elif spec == ['context', 'config']: return cloudformation.generate_template(context, config) else: raise Exception('Arguments of \'generate_template\' not as expected: %s' % spec)
python
def generate_template(context, config, cloudformation): """call cloudformation to generate the template (json format). :param context: :param config: :param cloudformation: :return: """ spec = inspect.getargspec(cloudformation.generate_template)[0] if len(spec) == 0: return cloudformation.generate_template() elif spec == ['context', 'config']: return cloudformation.generate_template(context, config) else: raise Exception('Arguments of \'generate_template\' not as expected: %s' % spec)
[ "def", "generate_template", "(", "context", ",", "config", ",", "cloudformation", ")", ":", "spec", "=", "inspect", ".", "getargspec", "(", "cloudformation", ".", "generate_template", ")", "[", "0", "]", "if", "len", "(", "spec", ")", "==", "0", ":", "return", "cloudformation", ".", "generate_template", "(", ")", "elif", "spec", "==", "[", "'context'", ",", "'config'", "]", ":", "return", "cloudformation", ".", "generate_template", "(", "context", ",", "config", ")", "else", ":", "raise", "Exception", "(", "'Arguments of \\'generate_template\\' not as expected: %s'", "%", "spec", ")" ]
call cloudformation to generate the template (json format). :param context: :param config: :param cloudformation: :return:
[ "call", "cloudformation", "to", "generate", "the", "template", "(", "json", "format", ")", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L669-L683
train
glomex/gcdt
gcdt/kumo_core.py
info
def info(awsclient, config, format=None): """ collect info and output to console :param awsclient: :param config: :param json: True / False to use json format as output :return: """ if format is None: format = 'tabular' stack_name = _get_stack_name(config) client_cfn = awsclient.get_client('cloudformation') resources = all_pages( client_cfn.list_stack_resources, {'StackName': stack_name}, lambda x: [(r['ResourceType'], r['LogicalResourceId'], r['ResourceStatus']) for r in x['StackResourceSummaries']] ) infos = { 'stack_output': _get_stack_outputs(client_cfn, stack_name), 'stack_state': _get_stack_state(client_cfn, stack_name), 'resources': resources } if format == 'json': print(json.dumps(infos)) elif format == 'tabular': print('stack output:') print(tabulate(infos['stack_output'], tablefmt='fancy_grid')) print('\nstack_state: %s' % infos['stack_state']) print('\nresources:') print(tabulate(infos['resources'], tablefmt='fancy_grid'))
python
def info(awsclient, config, format=None): """ collect info and output to console :param awsclient: :param config: :param json: True / False to use json format as output :return: """ if format is None: format = 'tabular' stack_name = _get_stack_name(config) client_cfn = awsclient.get_client('cloudformation') resources = all_pages( client_cfn.list_stack_resources, {'StackName': stack_name}, lambda x: [(r['ResourceType'], r['LogicalResourceId'], r['ResourceStatus']) for r in x['StackResourceSummaries']] ) infos = { 'stack_output': _get_stack_outputs(client_cfn, stack_name), 'stack_state': _get_stack_state(client_cfn, stack_name), 'resources': resources } if format == 'json': print(json.dumps(infos)) elif format == 'tabular': print('stack output:') print(tabulate(infos['stack_output'], tablefmt='fancy_grid')) print('\nstack_state: %s' % infos['stack_state']) print('\nresources:') print(tabulate(infos['resources'], tablefmt='fancy_grid'))
[ "def", "info", "(", "awsclient", ",", "config", ",", "format", "=", "None", ")", ":", "if", "format", "is", "None", ":", "format", "=", "'tabular'", "stack_name", "=", "_get_stack_name", "(", "config", ")", "client_cfn", "=", "awsclient", ".", "get_client", "(", "'cloudformation'", ")", "resources", "=", "all_pages", "(", "client_cfn", ".", "list_stack_resources", ",", "{", "'StackName'", ":", "stack_name", "}", ",", "lambda", "x", ":", "[", "(", "r", "[", "'ResourceType'", "]", ",", "r", "[", "'LogicalResourceId'", "]", ",", "r", "[", "'ResourceStatus'", "]", ")", "for", "r", "in", "x", "[", "'StackResourceSummaries'", "]", "]", ")", "infos", "=", "{", "'stack_output'", ":", "_get_stack_outputs", "(", "client_cfn", ",", "stack_name", ")", ",", "'stack_state'", ":", "_get_stack_state", "(", "client_cfn", ",", "stack_name", ")", ",", "'resources'", ":", "resources", "}", "if", "format", "==", "'json'", ":", "print", "(", "json", ".", "dumps", "(", "infos", ")", ")", "elif", "format", "==", "'tabular'", ":", "print", "(", "'stack output:'", ")", "print", "(", "tabulate", "(", "infos", "[", "'stack_output'", "]", ",", "tablefmt", "=", "'fancy_grid'", ")", ")", "print", "(", "'\\nstack_state: %s'", "%", "infos", "[", "'stack_state'", "]", ")", "print", "(", "'\\nresources:'", ")", "print", "(", "tabulate", "(", "infos", "[", "'resources'", "]", ",", "tablefmt", "=", "'fancy_grid'", ")", ")" ]
collect info and output to console :param awsclient: :param config: :param json: True / False to use json format as output :return:
[ "collect", "info", "and", "output", "to", "console" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/kumo_core.py#L686-L719
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BCC
def BCC(self, params): """ BCC label Branch to the instruction at label if the C flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BCC label def BCC_func(): if not self.is_C_set(): self.register['PC'] = self.labels[label] return BCC_func
python
def BCC(self, params): """ BCC label Branch to the instruction at label if the C flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BCC label def BCC_func(): if not self.is_C_set(): self.register['PC'] = self.labels[label] return BCC_func
[ "def", "BCC", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BCC label", "def", "BCC_func", "(", ")", ":", "if", "not", "self", ".", "is_C_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BCC_func" ]
BCC label Branch to the instruction at label if the C flag is not set
[ "BCC", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L5-L20
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BCS
def BCS(self, params): """ BCS label Branch to the instruction at label if the C flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BCS label def BCS_func(): if self.is_C_set(): self.register['PC'] = self.labels[label] return BCS_func
python
def BCS(self, params): """ BCS label Branch to the instruction at label if the C flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BCS label def BCS_func(): if self.is_C_set(): self.register['PC'] = self.labels[label] return BCS_func
[ "def", "BCS", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BCS label", "def", "BCS_func", "(", ")", ":", "if", "self", ".", "is_C_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BCS_func" ]
BCS label Branch to the instruction at label if the C flag is set
[ "BCS", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L22-L37
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BEQ
def BEQ(self, params): """ BEQ label Branch to the instruction at label if the Z flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BEQ label def BEQ_func(): if self.is_Z_set(): self.register['PC'] = self.labels[label] return BEQ_func
python
def BEQ(self, params): """ BEQ label Branch to the instruction at label if the Z flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BEQ label def BEQ_func(): if self.is_Z_set(): self.register['PC'] = self.labels[label] return BEQ_func
[ "def", "BEQ", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BEQ label", "def", "BEQ_func", "(", ")", ":", "if", "self", ".", "is_Z_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BEQ_func" ]
BEQ label Branch to the instruction at label if the Z flag is set
[ "BEQ", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L39-L54
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BGE
def BGE(self, params): """ BGE label Branch to the instruction at label if the N flag is the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BGE label def BGE_func(): if self.is_N_set() == self.is_V_set(): self.register['PC'] = self.labels[label] return BGE_func
python
def BGE(self, params): """ BGE label Branch to the instruction at label if the N flag is the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BGE label def BGE_func(): if self.is_N_set() == self.is_V_set(): self.register['PC'] = self.labels[label] return BGE_func
[ "def", "BGE", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BGE label", "def", "BGE_func", "(", ")", ":", "if", "self", ".", "is_N_set", "(", ")", "==", "self", ".", "is_V_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BGE_func" ]
BGE label Branch to the instruction at label if the N flag is the same as the V flag
[ "BGE", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L56-L71
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BGT
def BGT(self, params): """ BGT label Branch to the instruction at label if the N flag is the same as the V flag and the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BGT label def BGT_func(): if (self.is_N_set() == self.is_V_set()) and not self.is_Z_set(): self.register['PC'] = self.labels[label] return BGT_func
python
def BGT(self, params): """ BGT label Branch to the instruction at label if the N flag is the same as the V flag and the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BGT label def BGT_func(): if (self.is_N_set() == self.is_V_set()) and not self.is_Z_set(): self.register['PC'] = self.labels[label] return BGT_func
[ "def", "BGT", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BGT label", "def", "BGT_func", "(", ")", ":", "if", "(", "self", ".", "is_N_set", "(", ")", "==", "self", ".", "is_V_set", "(", ")", ")", "and", "not", "self", ".", "is_Z_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BGT_func" ]
BGT label Branch to the instruction at label if the N flag is the same as the V flag and the Z flag is not set
[ "BGT", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L73-L88
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BHI
def BHI(self, params): """ BHI label Branch to the instruction at label if the C flag is set and the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BHI label def BHI_func(): if self.is_C_set() and not self.is_Z_set(): self.register['PC'] = self.labels[label] return BHI_func
python
def BHI(self, params): """ BHI label Branch to the instruction at label if the C flag is set and the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BHI label def BHI_func(): if self.is_C_set() and not self.is_Z_set(): self.register['PC'] = self.labels[label] return BHI_func
[ "def", "BHI", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BHI label", "def", "BHI_func", "(", ")", ":", "if", "self", ".", "is_C_set", "(", ")", "and", "not", "self", ".", "is_Z_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BHI_func" ]
BHI label Branch to the instruction at label if the C flag is set and the Z flag is not set
[ "BHI", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L90-L105
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BHS
def BHS(self, params): """ BHS label Branch to the instruction at label if the C flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BHS label def BHS_func(): if self.is_C_set(): self.register['PC'] = self.labels[label] return BHS_func
python
def BHS(self, params): """ BHS label Branch to the instruction at label if the C flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BHS label def BHS_func(): if self.is_C_set(): self.register['PC'] = self.labels[label] return BHS_func
[ "def", "BHS", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BHS label", "def", "BHS_func", "(", ")", ":", "if", "self", ".", "is_C_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BHS_func" ]
BHS label Branch to the instruction at label if the C flag is set
[ "BHS", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L107-L122
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BLE
def BLE(self, params): """ BLE label Branch to the instruction at label if the Z flag is set or if the N flag is not the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLE label def BLE_func(): if self.is_Z_set() or (self.is_N_set() != self.is_V_set()): self.register['PC'] = self.labels[label] return BLE_func
python
def BLE(self, params): """ BLE label Branch to the instruction at label if the Z flag is set or if the N flag is not the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLE label def BLE_func(): if self.is_Z_set() or (self.is_N_set() != self.is_V_set()): self.register['PC'] = self.labels[label] return BLE_func
[ "def", "BLE", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BLE label", "def", "BLE_func", "(", ")", ":", "if", "self", ".", "is_Z_set", "(", ")", "or", "(", "self", ".", "is_N_set", "(", ")", "!=", "self", ".", "is_V_set", "(", ")", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BLE_func" ]
BLE label Branch to the instruction at label if the Z flag is set or if the N flag is not the same as the V flag
[ "BLE", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L124-L139
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BLO
def BLO(self, params): """ BLO label Branch to the instruction at label if the C flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLO label def BLO_func(): if not self.is_C_set(): self.register['PC'] = self.labels[label] return BLO_func
python
def BLO(self, params): """ BLO label Branch to the instruction at label if the C flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLO label def BLO_func(): if not self.is_C_set(): self.register['PC'] = self.labels[label] return BLO_func
[ "def", "BLO", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BLO label", "def", "BLO_func", "(", ")", ":", "if", "not", "self", ".", "is_C_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BLO_func" ]
BLO label Branch to the instruction at label if the C flag is not set
[ "BLO", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L141-L156
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BLS
def BLS(self, params): """ BLS label Branch to the instruction at label if the C flag is not set or the Z flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLS label def BLS_func(): if (not self.is_C_set()) or self.is_Z_set(): self.register['PC'] = self.labels[label] return BLS_func
python
def BLS(self, params): """ BLS label Branch to the instruction at label if the C flag is not set or the Z flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLS label def BLS_func(): if (not self.is_C_set()) or self.is_Z_set(): self.register['PC'] = self.labels[label] return BLS_func
[ "def", "BLS", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BLS label", "def", "BLS_func", "(", ")", ":", "if", "(", "not", "self", ".", "is_C_set", "(", ")", ")", "or", "self", ".", "is_Z_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BLS_func" ]
BLS label Branch to the instruction at label if the C flag is not set or the Z flag is set
[ "BLS", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L158-L173
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BLT
def BLT(self, params): """ BLT label Branch to the instruction at label if the N flag is not the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLT label def BLT_func(): if self.is_N_set() != self.is_V_set(): self.register['PC'] = self.labels[label] return BLT_func
python
def BLT(self, params): """ BLT label Branch to the instruction at label if the N flag is not the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLT label def BLT_func(): if self.is_N_set() != self.is_V_set(): self.register['PC'] = self.labels[label] return BLT_func
[ "def", "BLT", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BLT label", "def", "BLT_func", "(", ")", ":", "if", "self", ".", "is_N_set", "(", ")", "!=", "self", ".", "is_V_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BLT_func" ]
BLT label Branch to the instruction at label if the N flag is not the same as the V flag
[ "BLT", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L175-L190
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BMI
def BMI(self, params): """ BMI label Branch to the instruction at label if the N flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BMI label def BMI_func(): if self.is_N_set(): self.register['PC'] = self.labels[label] return BMI_func
python
def BMI(self, params): """ BMI label Branch to the instruction at label if the N flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BMI label def BMI_func(): if self.is_N_set(): self.register['PC'] = self.labels[label] return BMI_func
[ "def", "BMI", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BMI label", "def", "BMI_func", "(", ")", ":", "if", "self", ".", "is_N_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BMI_func" ]
BMI label Branch to the instruction at label if the N flag is set
[ "BMI", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L192-L207
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BNE
def BNE(self, params): """ BNE label Branch to the instruction at label if the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BNE label def BNE_func(): if not self.is_Z_set(): self.register['PC'] = self.labels[label] return BNE_func
python
def BNE(self, params): """ BNE label Branch to the instruction at label if the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BNE label def BNE_func(): if not self.is_Z_set(): self.register['PC'] = self.labels[label] return BNE_func
[ "def", "BNE", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BNE label", "def", "BNE_func", "(", ")", ":", "if", "not", "self", ".", "is_Z_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BNE_func" ]
BNE label Branch to the instruction at label if the Z flag is not set
[ "BNE", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L209-L224
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BPL
def BPL(self, params): """ BPL label Branch to the instruction at label if the N flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BPL label def BPL_func(): if not self.is_N_set(): self.register['PC'] = self.labels[label] return BPL_func
python
def BPL(self, params): """ BPL label Branch to the instruction at label if the N flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BPL label def BPL_func(): if not self.is_N_set(): self.register['PC'] = self.labels[label] return BPL_func
[ "def", "BPL", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BPL label", "def", "BPL_func", "(", ")", ":", "if", "not", "self", ".", "is_N_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BPL_func" ]
BPL label Branch to the instruction at label if the N flag is set
[ "BPL", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L226-L241
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BVC
def BVC(self, params): """ BVC label Branch to the instruction at label if the V flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BVC label def BVC_func(): if not self.is_V_set(): self.register['PC'] = self.labels[label] return BVC_func
python
def BVC(self, params): """ BVC label Branch to the instruction at label if the V flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BVC label def BVC_func(): if not self.is_V_set(): self.register['PC'] = self.labels[label] return BVC_func
[ "def", "BVC", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BVC label", "def", "BVC_func", "(", ")", ":", "if", "not", "self", ".", "is_V_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BVC_func" ]
BVC label Branch to the instruction at label if the V flag is not set
[ "BVC", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L243-L258
train
DeepHorizons/iarm
iarm/arm_instructions/conditional_branch.py
ConditionalBranch.BVS
def BVS(self, params): """ BVS label Branch to the instruction at label if the V flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BVS label def BVS_func(): if self.is_V_set(): self.register['PC'] = self.labels[label] return BVS_func
python
def BVS(self, params): """ BVS label Branch to the instruction at label if the V flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BVS label def BVS_func(): if self.is_V_set(): self.register['PC'] = self.labels[label] return BVS_func
[ "def", "BVS", "(", "self", ",", "params", ")", ":", "label", "=", "self", ".", "get_one_parameter", "(", "self", ".", "ONE_PARAMETER", ",", "params", ")", "self", ".", "check_arguments", "(", "label_exists", "=", "(", "label", ",", ")", ")", "# BVS label", "def", "BVS_func", "(", ")", ":", "if", "self", ".", "is_V_set", "(", ")", ":", "self", ".", "register", "[", "'PC'", "]", "=", "self", ".", "labels", "[", "label", "]", "return", "BVS_func" ]
BVS label Branch to the instruction at label if the V flag is set
[ "BVS", "label" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/conditional_branch.py#L260-L275
train
lincolnloop/salmon
salmon/metrics/admin.py
MetricGroupAdmin.get_queryset
def get_queryset(self, request): """Shows one entry per distinct metric name""" queryset = super(MetricGroupAdmin, self).get_queryset(request) # poor-man's DISTINCT ON for Sqlite3 qs_values = queryset.values('id', 'name') # 2.7+ only :( # = {metric['name']: metric['id'] for metric in qs_values} distinct_names = {} for metric in qs_values: distinct_names[metric['name']] = metric['id'] queryset = self.model.objects.filter(id__in=distinct_names.values()) return queryset
python
def get_queryset(self, request): """Shows one entry per distinct metric name""" queryset = super(MetricGroupAdmin, self).get_queryset(request) # poor-man's DISTINCT ON for Sqlite3 qs_values = queryset.values('id', 'name') # 2.7+ only :( # = {metric['name']: metric['id'] for metric in qs_values} distinct_names = {} for metric in qs_values: distinct_names[metric['name']] = metric['id'] queryset = self.model.objects.filter(id__in=distinct_names.values()) return queryset
[ "def", "get_queryset", "(", "self", ",", "request", ")", ":", "queryset", "=", "super", "(", "MetricGroupAdmin", ",", "self", ")", ".", "get_queryset", "(", "request", ")", "# poor-man's DISTINCT ON for Sqlite3", "qs_values", "=", "queryset", ".", "values", "(", "'id'", ",", "'name'", ")", "# 2.7+ only :(", "# = {metric['name']: metric['id'] for metric in qs_values}", "distinct_names", "=", "{", "}", "for", "metric", "in", "qs_values", ":", "distinct_names", "[", "metric", "[", "'name'", "]", "]", "=", "metric", "[", "'id'", "]", "queryset", "=", "self", ".", "model", ".", "objects", ".", "filter", "(", "id__in", "=", "distinct_names", ".", "values", "(", ")", ")", "return", "queryset" ]
Shows one entry per distinct metric name
[ "Shows", "one", "entry", "per", "distinct", "metric", "name" ]
62a965ad9716707ea1db4afb5d9646766f29b64b
https://github.com/lincolnloop/salmon/blob/62a965ad9716707ea1db4afb5d9646766f29b64b/salmon/metrics/admin.py#L34-L45
train
lincolnloop/salmon
salmon/metrics/admin.py
MetricGroupAdmin.save_model
def save_model(self, request, obj, form, change): """Updates all metrics with the same name""" like_metrics = self.model.objects.filter(name=obj.name) # 2.7+ only :( # = {key: form.cleaned_data[key] for key in form.changed_data} updates = {} for key in form.changed_data: updates[key] = form.cleaned_data[key] like_metrics.update(**updates)
python
def save_model(self, request, obj, form, change): """Updates all metrics with the same name""" like_metrics = self.model.objects.filter(name=obj.name) # 2.7+ only :( # = {key: form.cleaned_data[key] for key in form.changed_data} updates = {} for key in form.changed_data: updates[key] = form.cleaned_data[key] like_metrics.update(**updates)
[ "def", "save_model", "(", "self", ",", "request", ",", "obj", ",", "form", ",", "change", ")", ":", "like_metrics", "=", "self", ".", "model", ".", "objects", ".", "filter", "(", "name", "=", "obj", ".", "name", ")", "# 2.7+ only :(", "# = {key: form.cleaned_data[key] for key in form.changed_data}", "updates", "=", "{", "}", "for", "key", "in", "form", ".", "changed_data", ":", "updates", "[", "key", "]", "=", "form", ".", "cleaned_data", "[", "key", "]", "like_metrics", ".", "update", "(", "*", "*", "updates", ")" ]
Updates all metrics with the same name
[ "Updates", "all", "metrics", "with", "the", "same", "name" ]
62a965ad9716707ea1db4afb5d9646766f29b64b
https://github.com/lincolnloop/salmon/blob/62a965ad9716707ea1db4afb5d9646766f29b64b/salmon/metrics/admin.py#L47-L55
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.parse_lines
def parse_lines(self, code): """ Return a list of the parsed code For each line, return a three-tuple containing: 1. The label 2. The instruction 3. Any arguments or parameters An element in the tuple may be None or '' if it did not find anything :param code: The code to parse :return: A list of tuples in the form of (label, instruction, parameters) """ remove_comments = re.compile(r'^([^;@\n]*);?.*$', re.MULTILINE) code = '\n'.join(remove_comments.findall(code)) # TODO can probably do this better # TODO labels with spaces between pipes is allowed `|label with space| INST OPER` parser = re.compile(r'^(\S*)?[\s]*(\S*)([^\n]*)$', re.MULTILINE) res = parser.findall(code) # Make all parsing of labels and instructions adhere to all uppercase res = [(label.upper(), instruction.upper(), parameters.strip()) for (label, instruction, parameters) in res] return res
python
def parse_lines(self, code): """ Return a list of the parsed code For each line, return a three-tuple containing: 1. The label 2. The instruction 3. Any arguments or parameters An element in the tuple may be None or '' if it did not find anything :param code: The code to parse :return: A list of tuples in the form of (label, instruction, parameters) """ remove_comments = re.compile(r'^([^;@\n]*);?.*$', re.MULTILINE) code = '\n'.join(remove_comments.findall(code)) # TODO can probably do this better # TODO labels with spaces between pipes is allowed `|label with space| INST OPER` parser = re.compile(r'^(\S*)?[\s]*(\S*)([^\n]*)$', re.MULTILINE) res = parser.findall(code) # Make all parsing of labels and instructions adhere to all uppercase res = [(label.upper(), instruction.upper(), parameters.strip()) for (label, instruction, parameters) in res] return res
[ "def", "parse_lines", "(", "self", ",", "code", ")", ":", "remove_comments", "=", "re", ".", "compile", "(", "r'^([^;@\\n]*);?.*$'", ",", "re", ".", "MULTILINE", ")", "code", "=", "'\\n'", ".", "join", "(", "remove_comments", ".", "findall", "(", "code", ")", ")", "# TODO can probably do this better", "# TODO labels with spaces between pipes is allowed `|label with space| INST OPER`", "parser", "=", "re", ".", "compile", "(", "r'^(\\S*)?[\\s]*(\\S*)([^\\n]*)$'", ",", "re", ".", "MULTILINE", ")", "res", "=", "parser", ".", "findall", "(", "code", ")", "# Make all parsing of labels and instructions adhere to all uppercase", "res", "=", "[", "(", "label", ".", "upper", "(", ")", ",", "instruction", ".", "upper", "(", ")", ",", "parameters", ".", "strip", "(", ")", ")", "for", "(", "label", ",", "instruction", ",", "parameters", ")", "in", "res", "]", "return", "res" ]
Return a list of the parsed code For each line, return a three-tuple containing: 1. The label 2. The instruction 3. Any arguments or parameters An element in the tuple may be None or '' if it did not find anything :param code: The code to parse :return: A list of tuples in the form of (label, instruction, parameters)
[ "Return", "a", "list", "of", "the", "parsed", "code" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L20-L40
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.check_register
def check_register(self, arg): """ Is the parameter a register in the form of 'R<d>', and if so is it within the bounds of registers defined Raises an exception if 1. The parameter is not in the form of 'R<d>' 2. <d> is outside the range of registers defined in the init value registers or _max_registers :param arg: The parameter to check :return: The number of the register """ self.check_parameter(arg) match = re.search(self.REGISTER_REGEX, arg) if match is None: raise iarm.exceptions.RuleError("Parameter {} is not a register".format(arg)) try: r_num = int(match.groups()[0]) except ValueError: r_num = int(match.groups()[0], 16) except TypeError: if arg in 'lr|LR': return 14 elif arg in 'sp|SP': return 13 elif arg in 'fp|FP': return 7 ## TODO this could be 7 or 11 depending on THUMB and ARM mode http://www.keil.com/support/man/docs/armcc/armcc_chr1359124947957.htm else: raise if r_num > self._max_registers: raise iarm.exceptions.RuleError( "Register {} is greater than defined registers of {}".format(arg, self._max_registers)) return r_num
python
def check_register(self, arg): """ Is the parameter a register in the form of 'R<d>', and if so is it within the bounds of registers defined Raises an exception if 1. The parameter is not in the form of 'R<d>' 2. <d> is outside the range of registers defined in the init value registers or _max_registers :param arg: The parameter to check :return: The number of the register """ self.check_parameter(arg) match = re.search(self.REGISTER_REGEX, arg) if match is None: raise iarm.exceptions.RuleError("Parameter {} is not a register".format(arg)) try: r_num = int(match.groups()[0]) except ValueError: r_num = int(match.groups()[0], 16) except TypeError: if arg in 'lr|LR': return 14 elif arg in 'sp|SP': return 13 elif arg in 'fp|FP': return 7 ## TODO this could be 7 or 11 depending on THUMB and ARM mode http://www.keil.com/support/man/docs/armcc/armcc_chr1359124947957.htm else: raise if r_num > self._max_registers: raise iarm.exceptions.RuleError( "Register {} is greater than defined registers of {}".format(arg, self._max_registers)) return r_num
[ "def", "check_register", "(", "self", ",", "arg", ")", ":", "self", ".", "check_parameter", "(", "arg", ")", "match", "=", "re", ".", "search", "(", "self", ".", "REGISTER_REGEX", ",", "arg", ")", "if", "match", "is", "None", ":", "raise", "iarm", ".", "exceptions", ".", "RuleError", "(", "\"Parameter {} is not a register\"", ".", "format", "(", "arg", ")", ")", "try", ":", "r_num", "=", "int", "(", "match", ".", "groups", "(", ")", "[", "0", "]", ")", "except", "ValueError", ":", "r_num", "=", "int", "(", "match", ".", "groups", "(", ")", "[", "0", "]", ",", "16", ")", "except", "TypeError", ":", "if", "arg", "in", "'lr|LR'", ":", "return", "14", "elif", "arg", "in", "'sp|SP'", ":", "return", "13", "elif", "arg", "in", "'fp|FP'", ":", "return", "7", "## TODO this could be 7 or 11 depending on THUMB and ARM mode http://www.keil.com/support/man/docs/armcc/armcc_chr1359124947957.htm", "else", ":", "raise", "if", "r_num", ">", "self", ".", "_max_registers", ":", "raise", "iarm", ".", "exceptions", ".", "RuleError", "(", "\"Register {} is greater than defined registers of {}\"", ".", "format", "(", "arg", ",", "self", ".", "_max_registers", ")", ")", "return", "r_num" ]
Is the parameter a register in the form of 'R<d>', and if so is it within the bounds of registers defined Raises an exception if 1. The parameter is not in the form of 'R<d>' 2. <d> is outside the range of registers defined in the init value registers or _max_registers :param arg: The parameter to check :return: The number of the register
[ "Is", "the", "parameter", "a", "register", "in", "the", "form", "of", "R<d", ">", "and", "if", "so", "is", "it", "within", "the", "bounds", "of", "registers", "defined" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L76-L109
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.check_immediate
def check_immediate(self, arg): """ Is the parameter an immediate in the form of '#<d>', Raises an exception if 1. The parameter is not in the form of '#<d>' :param arg: The parameter to check :return: The value of the immediate """ self.check_parameter(arg) match = re.search(self.IMMEDIATE_REGEX, arg) if match is None: raise iarm.exceptions.RuleError("Parameter {} is not an immediate".format(arg)) return self.convert_to_integer(match.groups()[0])
python
def check_immediate(self, arg): """ Is the parameter an immediate in the form of '#<d>', Raises an exception if 1. The parameter is not in the form of '#<d>' :param arg: The parameter to check :return: The value of the immediate """ self.check_parameter(arg) match = re.search(self.IMMEDIATE_REGEX, arg) if match is None: raise iarm.exceptions.RuleError("Parameter {} is not an immediate".format(arg)) return self.convert_to_integer(match.groups()[0])
[ "def", "check_immediate", "(", "self", ",", "arg", ")", ":", "self", ".", "check_parameter", "(", "arg", ")", "match", "=", "re", ".", "search", "(", "self", ".", "IMMEDIATE_REGEX", ",", "arg", ")", "if", "match", "is", "None", ":", "raise", "iarm", ".", "exceptions", ".", "RuleError", "(", "\"Parameter {} is not an immediate\"", ".", "format", "(", "arg", ")", ")", "return", "self", ".", "convert_to_integer", "(", "match", ".", "groups", "(", ")", "[", "0", "]", ")" ]
Is the parameter an immediate in the form of '#<d>', Raises an exception if 1. The parameter is not in the form of '#<d>' :param arg: The parameter to check :return: The value of the immediate
[ "Is", "the", "parameter", "an", "immediate", "in", "the", "form", "of", "#<d", ">" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L111-L124
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.check_immediate_unsigned_value
def check_immediate_unsigned_value(self, arg, bit): """ Is the immediate within the unsigned value of 2**bit - 1 Raises an exception if 1. The immediate value is > 2**bit - 1 :param arg: The parameter to check :param bit: The number of bits to use in 2**bit :return: The value of the immediate """ i_num = self.check_immediate(arg) if (i_num > (2 ** bit - 1)) or (i_num < 0): raise iarm.exceptions.RuleError("Immediate {} is not an unsigned {} bit value".format(arg, bit)) return i_num
python
def check_immediate_unsigned_value(self, arg, bit): """ Is the immediate within the unsigned value of 2**bit - 1 Raises an exception if 1. The immediate value is > 2**bit - 1 :param arg: The parameter to check :param bit: The number of bits to use in 2**bit :return: The value of the immediate """ i_num = self.check_immediate(arg) if (i_num > (2 ** bit - 1)) or (i_num < 0): raise iarm.exceptions.RuleError("Immediate {} is not an unsigned {} bit value".format(arg, bit)) return i_num
[ "def", "check_immediate_unsigned_value", "(", "self", ",", "arg", ",", "bit", ")", ":", "i_num", "=", "self", ".", "check_immediate", "(", "arg", ")", "if", "(", "i_num", ">", "(", "2", "**", "bit", "-", "1", ")", ")", "or", "(", "i_num", "<", "0", ")", ":", "raise", "iarm", ".", "exceptions", ".", "RuleError", "(", "\"Immediate {} is not an unsigned {} bit value\"", ".", "format", "(", "arg", ",", "bit", ")", ")", "return", "i_num" ]
Is the immediate within the unsigned value of 2**bit - 1 Raises an exception if 1. The immediate value is > 2**bit - 1 :param arg: The parameter to check :param bit: The number of bits to use in 2**bit :return: The value of the immediate
[ "Is", "the", "immediate", "within", "the", "unsigned", "value", "of", "2", "**", "bit", "-", "1" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L134-L147
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.check_immediate_value
def check_immediate_value(self, arg, _max, _min=0): """ Is the immediate within the range of [_min, _max] Raises an exception if 1. The immediate value is < _min or > _max :param arg: The parameter to check :param _max: The maximum value :param _min: The minimum value, optional, default is zero :return: The immediate value """ i_num = self.check_immediate(arg) if (i_num > _max) or (i_num < _min): raise iarm.exceptions.RuleError("Immediate {} is not within the range of [{}, {}]".format(arg, _min, _max)) return i_num
python
def check_immediate_value(self, arg, _max, _min=0): """ Is the immediate within the range of [_min, _max] Raises an exception if 1. The immediate value is < _min or > _max :param arg: The parameter to check :param _max: The maximum value :param _min: The minimum value, optional, default is zero :return: The immediate value """ i_num = self.check_immediate(arg) if (i_num > _max) or (i_num < _min): raise iarm.exceptions.RuleError("Immediate {} is not within the range of [{}, {}]".format(arg, _min, _max)) return i_num
[ "def", "check_immediate_value", "(", "self", ",", "arg", ",", "_max", ",", "_min", "=", "0", ")", ":", "i_num", "=", "self", ".", "check_immediate", "(", "arg", ")", "if", "(", "i_num", ">", "_max", ")", "or", "(", "i_num", "<", "_min", ")", ":", "raise", "iarm", ".", "exceptions", ".", "RuleError", "(", "\"Immediate {} is not within the range of [{}, {}]\"", ".", "format", "(", "arg", ",", "_min", ",", "_max", ")", ")", "return", "i_num" ]
Is the immediate within the range of [_min, _max] Raises an exception if 1. The immediate value is < _min or > _max :param arg: The parameter to check :param _max: The maximum value :param _min: The minimum value, optional, default is zero :return: The immediate value
[ "Is", "the", "immediate", "within", "the", "range", "of", "[", "_min", "_max", "]" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L149-L163
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.rule_low_registers
def rule_low_registers(self, arg): """Low registers are R0 - R7""" r_num = self.check_register(arg) if r_num > 7: raise iarm.exceptions.RuleError( "Register {} is not a low register".format(arg))
python
def rule_low_registers(self, arg): """Low registers are R0 - R7""" r_num = self.check_register(arg) if r_num > 7: raise iarm.exceptions.RuleError( "Register {} is not a low register".format(arg))
[ "def", "rule_low_registers", "(", "self", ",", "arg", ")", ":", "r_num", "=", "self", ".", "check_register", "(", "arg", ")", "if", "r_num", ">", "7", ":", "raise", "iarm", ".", "exceptions", ".", "RuleError", "(", "\"Register {} is not a low register\"", ".", "format", "(", "arg", ")", ")" ]
Low registers are R0 - R7
[ "Low", "registers", "are", "R0", "-", "R7" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L170-L175
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.get_parameters
def get_parameters(self, regex_exp, parameters): """ Given a regex expression and the string with the paramers, either return a regex match object or raise an exception if the regex did not find a match :param regex_exp: :param parameters: :return: """ # TODO find a better way to do the equate replacement for rep in self.equates: parameters = parameters.replace(rep, str(self.equates[rep])) match = re.match(regex_exp, parameters) if not match: raise iarm.exceptions.ParsingError("Parameters are None, did you miss a comma?") return match.groups()
python
def get_parameters(self, regex_exp, parameters): """ Given a regex expression and the string with the paramers, either return a regex match object or raise an exception if the regex did not find a match :param regex_exp: :param parameters: :return: """ # TODO find a better way to do the equate replacement for rep in self.equates: parameters = parameters.replace(rep, str(self.equates[rep])) match = re.match(regex_exp, parameters) if not match: raise iarm.exceptions.ParsingError("Parameters are None, did you miss a comma?") return match.groups()
[ "def", "get_parameters", "(", "self", ",", "regex_exp", ",", "parameters", ")", ":", "# TODO find a better way to do the equate replacement", "for", "rep", "in", "self", ".", "equates", ":", "parameters", "=", "parameters", ".", "replace", "(", "rep", ",", "str", "(", "self", ".", "equates", "[", "rep", "]", ")", ")", "match", "=", "re", ".", "match", "(", "regex_exp", ",", "parameters", ")", "if", "not", "match", ":", "raise", "iarm", ".", "exceptions", ".", "ParsingError", "(", "\"Parameters are None, did you miss a comma?\"", ")", "return", "match", ".", "groups", "(", ")" ]
Given a regex expression and the string with the paramers, either return a regex match object or raise an exception if the regex did not find a match :param regex_exp: :param parameters: :return:
[ "Given", "a", "regex", "expression", "and", "the", "string", "with", "the", "paramers", "either", "return", "a", "regex", "match", "object", "or", "raise", "an", "exception", "if", "the", "regex", "did", "not", "find", "a", "match", ":", "param", "regex_exp", ":", ":", "param", "parameters", ":", ":", "return", ":" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L241-L257
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.get_one_parameter
def get_one_parameter(self, regex_exp, parameters): """ Get three parameters from a given regex expression Raise an exception if more than three were found :param regex_exp: :param parameters: :return: """ Rx, other = self.get_parameters(regex_exp, parameters) if other is not None and other.strip(): raise iarm.exceptions.ParsingError("Extra arguments found: {}".format(other)) return Rx.upper()
python
def get_one_parameter(self, regex_exp, parameters): """ Get three parameters from a given regex expression Raise an exception if more than three were found :param regex_exp: :param parameters: :return: """ Rx, other = self.get_parameters(regex_exp, parameters) if other is not None and other.strip(): raise iarm.exceptions.ParsingError("Extra arguments found: {}".format(other)) return Rx.upper()
[ "def", "get_one_parameter", "(", "self", ",", "regex_exp", ",", "parameters", ")", ":", "Rx", ",", "other", "=", "self", ".", "get_parameters", "(", "regex_exp", ",", "parameters", ")", "if", "other", "is", "not", "None", "and", "other", ".", "strip", "(", ")", ":", "raise", "iarm", ".", "exceptions", ".", "ParsingError", "(", "\"Extra arguments found: {}\"", ".", "format", "(", "other", ")", ")", "return", "Rx", ".", "upper", "(", ")" ]
Get three parameters from a given regex expression Raise an exception if more than three were found :param regex_exp: :param parameters: :return:
[ "Get", "three", "parameters", "from", "a", "given", "regex", "expression" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L259-L271
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.get_two_parameters
def get_two_parameters(self, regex_exp, parameters): """ Get two parameters from a given regex expression Raise an exception if more than two were found :param regex_exp: :param parameters: :return: """ Rx, Ry, other = self.get_parameters(regex_exp, parameters) if other is not None and other.strip(): raise iarm.exceptions.ParsingError("Extra arguments found: {}".format(other)) if Rx and Ry: return Rx.upper(), Ry.upper() elif not Rx: raise iarm.exceptions.ParsingError("Missing first positional argument") else: raise iarm.exceptions.ParsingError("Missing second positional argument")
python
def get_two_parameters(self, regex_exp, parameters): """ Get two parameters from a given regex expression Raise an exception if more than two were found :param regex_exp: :param parameters: :return: """ Rx, Ry, other = self.get_parameters(regex_exp, parameters) if other is not None and other.strip(): raise iarm.exceptions.ParsingError("Extra arguments found: {}".format(other)) if Rx and Ry: return Rx.upper(), Ry.upper() elif not Rx: raise iarm.exceptions.ParsingError("Missing first positional argument") else: raise iarm.exceptions.ParsingError("Missing second positional argument")
[ "def", "get_two_parameters", "(", "self", ",", "regex_exp", ",", "parameters", ")", ":", "Rx", ",", "Ry", ",", "other", "=", "self", ".", "get_parameters", "(", "regex_exp", ",", "parameters", ")", "if", "other", "is", "not", "None", "and", "other", ".", "strip", "(", ")", ":", "raise", "iarm", ".", "exceptions", ".", "ParsingError", "(", "\"Extra arguments found: {}\"", ".", "format", "(", "other", ")", ")", "if", "Rx", "and", "Ry", ":", "return", "Rx", ".", "upper", "(", ")", ",", "Ry", ".", "upper", "(", ")", "elif", "not", "Rx", ":", "raise", "iarm", ".", "exceptions", ".", "ParsingError", "(", "\"Missing first positional argument\"", ")", "else", ":", "raise", "iarm", ".", "exceptions", ".", "ParsingError", "(", "\"Missing second positional argument\"", ")" ]
Get two parameters from a given regex expression Raise an exception if more than two were found :param regex_exp: :param parameters: :return:
[ "Get", "two", "parameters", "from", "a", "given", "regex", "expression" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L273-L290
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.get_three_parameters
def get_three_parameters(self, regex_exp, parameters): """ Get three parameters from a given regex expression Raise an exception if more than three were found :param regex_exp: :param parameters: :return: """ Rx, Ry, Rz, other = self.get_parameters(regex_exp, parameters) if other is not None and other.strip(): raise iarm.exceptions.ParsingError("Extra arguments found: {}".format(other)) return Rx.upper(), Ry.upper(), Rz.upper()
python
def get_three_parameters(self, regex_exp, parameters): """ Get three parameters from a given regex expression Raise an exception if more than three were found :param regex_exp: :param parameters: :return: """ Rx, Ry, Rz, other = self.get_parameters(regex_exp, parameters) if other is not None and other.strip(): raise iarm.exceptions.ParsingError("Extra arguments found: {}".format(other)) return Rx.upper(), Ry.upper(), Rz.upper()
[ "def", "get_three_parameters", "(", "self", ",", "regex_exp", ",", "parameters", ")", ":", "Rx", ",", "Ry", ",", "Rz", ",", "other", "=", "self", ".", "get_parameters", "(", "regex_exp", ",", "parameters", ")", "if", "other", "is", "not", "None", "and", "other", ".", "strip", "(", ")", ":", "raise", "iarm", ".", "exceptions", ".", "ParsingError", "(", "\"Extra arguments found: {}\"", ".", "format", "(", "other", ")", ")", "return", "Rx", ".", "upper", "(", ")", ",", "Ry", ".", "upper", "(", ")", ",", "Rz", ".", "upper", "(", ")" ]
Get three parameters from a given regex expression Raise an exception if more than three were found :param regex_exp: :param parameters: :return:
[ "Get", "three", "parameters", "from", "a", "given", "regex", "expression" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L292-L304
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.set_APSR_flag_to_value
def set_APSR_flag_to_value(self, flag, value): """ Set or clear flag in ASPR :param flag: The flag to set :param value: If value evaulates to true, it is set, cleared otherwise :return: """ if flag == 'N': bit = 31 elif flag == 'Z': bit = 30 elif flag == 'C': bit = 29 elif flag == 'V': bit = 28 else: raise AttributeError("Flag {} does not exist in the APSR".format(flag)) if value: self.register['APSR'] |= (1 << bit) else: self.register['APSR'] -= (1 << bit) if (self.register['APSR'] & (1 << bit)) else 0
python
def set_APSR_flag_to_value(self, flag, value): """ Set or clear flag in ASPR :param flag: The flag to set :param value: If value evaulates to true, it is set, cleared otherwise :return: """ if flag == 'N': bit = 31 elif flag == 'Z': bit = 30 elif flag == 'C': bit = 29 elif flag == 'V': bit = 28 else: raise AttributeError("Flag {} does not exist in the APSR".format(flag)) if value: self.register['APSR'] |= (1 << bit) else: self.register['APSR'] -= (1 << bit) if (self.register['APSR'] & (1 << bit)) else 0
[ "def", "set_APSR_flag_to_value", "(", "self", ",", "flag", ",", "value", ")", ":", "if", "flag", "==", "'N'", ":", "bit", "=", "31", "elif", "flag", "==", "'Z'", ":", "bit", "=", "30", "elif", "flag", "==", "'C'", ":", "bit", "=", "29", "elif", "flag", "==", "'V'", ":", "bit", "=", "28", "else", ":", "raise", "AttributeError", "(", "\"Flag {} does not exist in the APSR\"", ".", "format", "(", "flag", ")", ")", "if", "value", ":", "self", ".", "register", "[", "'APSR'", "]", "|=", "(", "1", "<<", "bit", ")", "else", ":", "self", ".", "register", "[", "'APSR'", "]", "-=", "(", "1", "<<", "bit", ")", "if", "(", "self", ".", "register", "[", "'APSR'", "]", "&", "(", "1", "<<", "bit", ")", ")", "else", "0" ]
Set or clear flag in ASPR :param flag: The flag to set :param value: If value evaulates to true, it is set, cleared otherwise :return:
[ "Set", "or", "clear", "flag", "in", "ASPR", ":", "param", "flag", ":", "The", "flag", "to", "set", ":", "param", "value", ":", "If", "value", "evaulates", "to", "true", "it", "is", "set", "cleared", "otherwise", ":", "return", ":" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L306-L327
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.rule_special_registers
def rule_special_registers(self, arg): """Raises an exception if the register is not a special register""" # TODO is PSR supposed to be here? special_registers = "PSR APSR IPSR EPSR PRIMASK FAULTMASK BASEPRI CONTROL" if arg not in special_registers.split(): raise iarm.exceptions.RuleError("{} is not a special register; Must be [{}]".format(arg, special_registers))
python
def rule_special_registers(self, arg): """Raises an exception if the register is not a special register""" # TODO is PSR supposed to be here? special_registers = "PSR APSR IPSR EPSR PRIMASK FAULTMASK BASEPRI CONTROL" if arg not in special_registers.split(): raise iarm.exceptions.RuleError("{} is not a special register; Must be [{}]".format(arg, special_registers))
[ "def", "rule_special_registers", "(", "self", ",", "arg", ")", ":", "# TODO is PSR supposed to be here?", "special_registers", "=", "\"PSR APSR IPSR EPSR PRIMASK FAULTMASK BASEPRI CONTROL\"", "if", "arg", "not", "in", "special_registers", ".", "split", "(", ")", ":", "raise", "iarm", ".", "exceptions", ".", "RuleError", "(", "\"{} is not a special register; Must be [{}]\"", ".", "format", "(", "arg", ",", "special_registers", ")", ")" ]
Raises an exception if the register is not a special register
[ "Raises", "an", "exception", "if", "the", "register", "is", "not", "a", "special", "register" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L329-L334
train
DeepHorizons/iarm
iarm/arm_instructions/_meta.py
_Meta.set_C_flag
def set_C_flag(self, oper_1, oper_2, result, type): """ Set C flag C flag is set if the unsigned number overflows This condition is obtained if: 1. In addition, the result is smaller than either of the operands 2. In subtraction, if the second operand is larger than the first This should not be used for shifting as each shift will need to set the C flag differently """ # TODO is this correct? if type == 'add': if result < oper_1: self.set_APSR_flag_to_value('C', 1) else: self.set_APSR_flag_to_value('C', 0) elif type == 'sub': if oper_1 < oper_2: # If there was a borrow, then set to zero self.set_APSR_flag_to_value('C', 0) else: self.set_APSR_flag_to_value('C', 1) elif type == 'shift-left': if (oper_2 > 0) and (oper_2 < (self._bit_width - 1)): self.set_APSR_flag_to_value('C', oper_1 & (1 << (self._bit_width - oper_2))) else: self.set_APSR_flag_to_value('C', 0) else: raise iarm.exceptions.BrainFart("_type is not 'add' or 'sub'")
python
def set_C_flag(self, oper_1, oper_2, result, type): """ Set C flag C flag is set if the unsigned number overflows This condition is obtained if: 1. In addition, the result is smaller than either of the operands 2. In subtraction, if the second operand is larger than the first This should not be used for shifting as each shift will need to set the C flag differently """ # TODO is this correct? if type == 'add': if result < oper_1: self.set_APSR_flag_to_value('C', 1) else: self.set_APSR_flag_to_value('C', 0) elif type == 'sub': if oper_1 < oper_2: # If there was a borrow, then set to zero self.set_APSR_flag_to_value('C', 0) else: self.set_APSR_flag_to_value('C', 1) elif type == 'shift-left': if (oper_2 > 0) and (oper_2 < (self._bit_width - 1)): self.set_APSR_flag_to_value('C', oper_1 & (1 << (self._bit_width - oper_2))) else: self.set_APSR_flag_to_value('C', 0) else: raise iarm.exceptions.BrainFart("_type is not 'add' or 'sub'")
[ "def", "set_C_flag", "(", "self", ",", "oper_1", ",", "oper_2", ",", "result", ",", "type", ")", ":", "# TODO is this correct?", "if", "type", "==", "'add'", ":", "if", "result", "<", "oper_1", ":", "self", ".", "set_APSR_flag_to_value", "(", "'C'", ",", "1", ")", "else", ":", "self", ".", "set_APSR_flag_to_value", "(", "'C'", ",", "0", ")", "elif", "type", "==", "'sub'", ":", "if", "oper_1", "<", "oper_2", ":", "# If there was a borrow, then set to zero", "self", ".", "set_APSR_flag_to_value", "(", "'C'", ",", "0", ")", "else", ":", "self", ".", "set_APSR_flag_to_value", "(", "'C'", ",", "1", ")", "elif", "type", "==", "'shift-left'", ":", "if", "(", "oper_2", ">", "0", ")", "and", "(", "oper_2", "<", "(", "self", ".", "_bit_width", "-", "1", ")", ")", ":", "self", ".", "set_APSR_flag_to_value", "(", "'C'", ",", "oper_1", "&", "(", "1", "<<", "(", "self", ".", "_bit_width", "-", "oper_2", ")", ")", ")", "else", ":", "self", ".", "set_APSR_flag_to_value", "(", "'C'", ",", "0", ")", "else", ":", "raise", "iarm", ".", "exceptions", ".", "BrainFart", "(", "\"_type is not 'add' or 'sub'\"", ")" ]
Set C flag C flag is set if the unsigned number overflows This condition is obtained if: 1. In addition, the result is smaller than either of the operands 2. In subtraction, if the second operand is larger than the first This should not be used for shifting as each shift will need to set the C flag differently
[ "Set", "C", "flag", "C", "flag", "is", "set", "if", "the", "unsigned", "number", "overflows", "This", "condition", "is", "obtained", "if", ":", "1", ".", "In", "addition", "the", "result", "is", "smaller", "than", "either", "of", "the", "operands", "2", ".", "In", "subtraction", "if", "the", "second", "operand", "is", "larger", "than", "the", "first" ]
b913c9fd577b793a6bbced78b78a5d8d7cd88de4
https://github.com/DeepHorizons/iarm/blob/b913c9fd577b793a6bbced78b78a5d8d7cd88de4/iarm/arm_instructions/_meta.py#L352-L381
train
glomex/gcdt
gcdt/utils.py
version
def version(): """Output version of gcdt tools and plugins.""" log.info('gcdt version %s' % __version__) tools = get_plugin_versions('gcdttool10') if tools: log.info('gcdt tools:') for p, v in tools.items(): log.info(' * %s version %s' % (p, v)) log.info('gcdt plugins:') for p, v in get_plugin_versions().items(): log.info(' * %s version %s' % (p, v)) generators = get_plugin_versions('gcdtgen10') if generators: log.info('gcdt scaffolding generators:') for p, v in generators.items(): log.info(' * %s version %s' % (p, v))
python
def version(): """Output version of gcdt tools and plugins.""" log.info('gcdt version %s' % __version__) tools = get_plugin_versions('gcdttool10') if tools: log.info('gcdt tools:') for p, v in tools.items(): log.info(' * %s version %s' % (p, v)) log.info('gcdt plugins:') for p, v in get_plugin_versions().items(): log.info(' * %s version %s' % (p, v)) generators = get_plugin_versions('gcdtgen10') if generators: log.info('gcdt scaffolding generators:') for p, v in generators.items(): log.info(' * %s version %s' % (p, v))
[ "def", "version", "(", ")", ":", "log", ".", "info", "(", "'gcdt version %s'", "%", "__version__", ")", "tools", "=", "get_plugin_versions", "(", "'gcdttool10'", ")", "if", "tools", ":", "log", ".", "info", "(", "'gcdt tools:'", ")", "for", "p", ",", "v", "in", "tools", ".", "items", "(", ")", ":", "log", ".", "info", "(", "' * %s version %s'", "%", "(", "p", ",", "v", ")", ")", "log", ".", "info", "(", "'gcdt plugins:'", ")", "for", "p", ",", "v", "in", "get_plugin_versions", "(", ")", ".", "items", "(", ")", ":", "log", ".", "info", "(", "' * %s version %s'", "%", "(", "p", ",", "v", ")", ")", "generators", "=", "get_plugin_versions", "(", "'gcdtgen10'", ")", "if", "generators", ":", "log", ".", "info", "(", "'gcdt scaffolding generators:'", ")", "for", "p", ",", "v", "in", "generators", ".", "items", "(", ")", ":", "log", ".", "info", "(", "' * %s version %s'", "%", "(", "p", ",", "v", ")", ")" ]
Output version of gcdt tools and plugins.
[ "Output", "version", "of", "gcdt", "tools", "and", "plugins", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/utils.py#L32-L47
train
glomex/gcdt
gcdt/utils.py
retries
def retries(max_tries, delay=1, backoff=2, exceptions=(Exception,), hook=None): """Function decorator implementing retrying logic. delay: Sleep this many seconds * backoff * try number after failure backoff: Multiply delay by this factor after each failure exceptions: A tuple of exception classes; default (Exception,) hook: A function with the signature: (tries_remaining, exception, mydelay) """ """ def example_hook(tries_remaining, exception, delay): '''Example exception handler; prints a warning to stderr. tries_remaining: The number of tries remaining. exception: The exception instance which was raised. ''' print >> sys.stderr, "Caught '%s', %d tries remaining, sleeping for %s seconds" % (exception, tries_remaining, delay) The decorator will call the function up to max_tries times if it raises an exception. By default it catches instances of the Exception class and subclasses. This will recover after all but the most fatal errors. You may specify a custom tuple of exception classes with the 'exceptions' argument; the function will only be retried if it raises one of the specified exceptions. Additionally you may specify a hook function which will be called prior to retrying with the number of remaining tries and the exception instance; see given example. This is primarily intended to give the opportunity to log the failure. Hook is not called after failure if no retries remain. """ def dec(func): def f2(*args, **kwargs): mydelay = delay #tries = range(max_tries) #tries.reverse() tries = range(max_tries-1, -1, -1) for tries_remaining in tries: try: return func(*args, **kwargs) except GracefulExit: raise except exceptions as e: if tries_remaining > 0: if hook is not None: hook(tries_remaining, e, mydelay) sleep(mydelay) mydelay *= backoff else: raise return f2 return dec
python
def retries(max_tries, delay=1, backoff=2, exceptions=(Exception,), hook=None): """Function decorator implementing retrying logic. delay: Sleep this many seconds * backoff * try number after failure backoff: Multiply delay by this factor after each failure exceptions: A tuple of exception classes; default (Exception,) hook: A function with the signature: (tries_remaining, exception, mydelay) """ """ def example_hook(tries_remaining, exception, delay): '''Example exception handler; prints a warning to stderr. tries_remaining: The number of tries remaining. exception: The exception instance which was raised. ''' print >> sys.stderr, "Caught '%s', %d tries remaining, sleeping for %s seconds" % (exception, tries_remaining, delay) The decorator will call the function up to max_tries times if it raises an exception. By default it catches instances of the Exception class and subclasses. This will recover after all but the most fatal errors. You may specify a custom tuple of exception classes with the 'exceptions' argument; the function will only be retried if it raises one of the specified exceptions. Additionally you may specify a hook function which will be called prior to retrying with the number of remaining tries and the exception instance; see given example. This is primarily intended to give the opportunity to log the failure. Hook is not called after failure if no retries remain. """ def dec(func): def f2(*args, **kwargs): mydelay = delay #tries = range(max_tries) #tries.reverse() tries = range(max_tries-1, -1, -1) for tries_remaining in tries: try: return func(*args, **kwargs) except GracefulExit: raise except exceptions as e: if tries_remaining > 0: if hook is not None: hook(tries_remaining, e, mydelay) sleep(mydelay) mydelay *= backoff else: raise return f2 return dec
[ "def", "retries", "(", "max_tries", ",", "delay", "=", "1", ",", "backoff", "=", "2", ",", "exceptions", "=", "(", "Exception", ",", ")", ",", "hook", "=", "None", ")", ":", "\"\"\"\n def example_hook(tries_remaining, exception, delay):\n '''Example exception handler; prints a warning to stderr.\n\n tries_remaining: The number of tries remaining.\n exception: The exception instance which was raised.\n '''\n print >> sys.stderr, \"Caught '%s', %d tries remaining, sleeping for %s seconds\" % (exception, tries_remaining, delay)\n\n The decorator will call the function up to max_tries times if it raises\n an exception.\n\n By default it catches instances of the Exception class and subclasses.\n This will recover after all but the most fatal errors. You may specify a\n custom tuple of exception classes with the 'exceptions' argument; the\n function will only be retried if it raises one of the specified\n exceptions.\n\n Additionally you may specify a hook function which will be called prior\n to retrying with the number of remaining tries and the exception instance;\n see given example. This is primarily intended to give the opportunity to\n log the failure. Hook is not called after failure if no retries remain.\n \"\"\"", "def", "dec", "(", "func", ")", ":", "def", "f2", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "mydelay", "=", "delay", "#tries = range(max_tries)", "#tries.reverse()", "tries", "=", "range", "(", "max_tries", "-", "1", ",", "-", "1", ",", "-", "1", ")", "for", "tries_remaining", "in", "tries", ":", "try", ":", "return", "func", "(", "*", "args", ",", "*", "*", "kwargs", ")", "except", "GracefulExit", ":", "raise", "except", "exceptions", "as", "e", ":", "if", "tries_remaining", ">", "0", ":", "if", "hook", "is", "not", "None", ":", "hook", "(", "tries_remaining", ",", "e", ",", "mydelay", ")", "sleep", "(", "mydelay", ")", "mydelay", "*=", "backoff", "else", ":", "raise", "return", "f2", "return", "dec" ]
Function decorator implementing retrying logic. delay: Sleep this many seconds * backoff * try number after failure backoff: Multiply delay by this factor after each failure exceptions: A tuple of exception classes; default (Exception,) hook: A function with the signature: (tries_remaining, exception, mydelay)
[ "Function", "decorator", "implementing", "retrying", "logic", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/utils.py#L50-L102
train
glomex/gcdt
gcdt/utils.py
get_env
def get_env(): """ Read environment from ENV and mangle it to a (lower case) representation Note: gcdt.utils get_env() is used in many cloudformation.py templates :return: Environment as lower case string (or None if not matched) """ env = os.getenv('ENV', os.getenv('env', None)) if env: env = env.lower() return env
python
def get_env(): """ Read environment from ENV and mangle it to a (lower case) representation Note: gcdt.utils get_env() is used in many cloudformation.py templates :return: Environment as lower case string (or None if not matched) """ env = os.getenv('ENV', os.getenv('env', None)) if env: env = env.lower() return env
[ "def", "get_env", "(", ")", ":", "env", "=", "os", ".", "getenv", "(", "'ENV'", ",", "os", ".", "getenv", "(", "'env'", ",", "None", ")", ")", "if", "env", ":", "env", "=", "env", ".", "lower", "(", ")", "return", "env" ]
Read environment from ENV and mangle it to a (lower case) representation Note: gcdt.utils get_env() is used in many cloudformation.py templates :return: Environment as lower case string (or None if not matched)
[ "Read", "environment", "from", "ENV", "and", "mangle", "it", "to", "a", "(", "lower", "case", ")", "representation", "Note", ":", "gcdt", ".", "utils", "get_env", "()", "is", "used", "in", "many", "cloudformation", ".", "py", "templates", ":", "return", ":", "Environment", "as", "lower", "case", "string", "(", "or", "None", "if", "not", "matched", ")" ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/utils.py#L109-L118
train
glomex/gcdt
gcdt/utils.py
get_context
def get_context(awsclient, env, tool, command, arguments=None): """This assembles the tool context. Private members are preceded by a '_'. :param tool: :param command: :return: dictionary containing the gcdt tool context """ # TODO: elapsed, artifact(stack, depl-grp, lambda, api) if arguments is None: arguments = {} context = { '_awsclient': awsclient, 'env': env, 'tool': tool, 'command': command, '_arguments': arguments, # TODO clean up arguments -> args 'version': __version__, 'user': _get_user(), 'plugins': get_plugin_versions().keys() } return context
python
def get_context(awsclient, env, tool, command, arguments=None): """This assembles the tool context. Private members are preceded by a '_'. :param tool: :param command: :return: dictionary containing the gcdt tool context """ # TODO: elapsed, artifact(stack, depl-grp, lambda, api) if arguments is None: arguments = {} context = { '_awsclient': awsclient, 'env': env, 'tool': tool, 'command': command, '_arguments': arguments, # TODO clean up arguments -> args 'version': __version__, 'user': _get_user(), 'plugins': get_plugin_versions().keys() } return context
[ "def", "get_context", "(", "awsclient", ",", "env", ",", "tool", ",", "command", ",", "arguments", "=", "None", ")", ":", "# TODO: elapsed, artifact(stack, depl-grp, lambda, api)", "if", "arguments", "is", "None", ":", "arguments", "=", "{", "}", "context", "=", "{", "'_awsclient'", ":", "awsclient", ",", "'env'", ":", "env", ",", "'tool'", ":", "tool", ",", "'command'", ":", "command", ",", "'_arguments'", ":", "arguments", ",", "# TODO clean up arguments -> args", "'version'", ":", "__version__", ",", "'user'", ":", "_get_user", "(", ")", ",", "'plugins'", ":", "get_plugin_versions", "(", ")", ".", "keys", "(", ")", "}", "return", "context" ]
This assembles the tool context. Private members are preceded by a '_'. :param tool: :param command: :return: dictionary containing the gcdt tool context
[ "This", "assembles", "the", "tool", "context", ".", "Private", "members", "are", "preceded", "by", "a", "_", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/utils.py#L121-L142
train
glomex/gcdt
gcdt/utils.py
get_command
def get_command(arguments): """Extract the first argument from arguments parsed by docopt. :param arguments parsed by docopt: :return: command """ return [k for k, v in arguments.items() if not k.startswith('-') and v is True][0]
python
def get_command(arguments): """Extract the first argument from arguments parsed by docopt. :param arguments parsed by docopt: :return: command """ return [k for k, v in arguments.items() if not k.startswith('-') and v is True][0]
[ "def", "get_command", "(", "arguments", ")", ":", "return", "[", "k", "for", "k", ",", "v", "in", "arguments", ".", "items", "(", ")", "if", "not", "k", ".", "startswith", "(", "'-'", ")", "and", "v", "is", "True", "]", "[", "0", "]" ]
Extract the first argument from arguments parsed by docopt. :param arguments parsed by docopt: :return: command
[ "Extract", "the", "first", "argument", "from", "arguments", "parsed", "by", "docopt", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/utils.py#L145-L152
train
glomex/gcdt
gcdt/utils.py
check_gcdt_update
def check_gcdt_update(): """Check whether a newer gcdt is available and output a warning. """ try: inst_version, latest_version = get_package_versions('gcdt') if inst_version < latest_version: log.warn('Please consider an update to gcdt version: %s' % latest_version) except GracefulExit: raise except Exception: log.warn('PyPi appears to be down - we currently can\'t check for newer gcdt versions')
python
def check_gcdt_update(): """Check whether a newer gcdt is available and output a warning. """ try: inst_version, latest_version = get_package_versions('gcdt') if inst_version < latest_version: log.warn('Please consider an update to gcdt version: %s' % latest_version) except GracefulExit: raise except Exception: log.warn('PyPi appears to be down - we currently can\'t check for newer gcdt versions')
[ "def", "check_gcdt_update", "(", ")", ":", "try", ":", "inst_version", ",", "latest_version", "=", "get_package_versions", "(", "'gcdt'", ")", "if", "inst_version", "<", "latest_version", ":", "log", ".", "warn", "(", "'Please consider an update to gcdt version: %s'", "%", "latest_version", ")", "except", "GracefulExit", ":", "raise", "except", "Exception", ":", "log", ".", "warn", "(", "'PyPi appears to be down - we currently can\\'t check for newer gcdt versions'", ")" ]
Check whether a newer gcdt is available and output a warning.
[ "Check", "whether", "a", "newer", "gcdt", "is", "available", "and", "output", "a", "warning", "." ]
cd67cf416371337b83cb9ca3f696277125703339
https://github.com/glomex/gcdt/blob/cd67cf416371337b83cb9ca3f696277125703339/gcdt/utils.py#L173-L185
train