query stringlengths 5 1.23k | positive stringlengths 53 15.2k | id_ int64 0 252k | task_name stringlengths 87 242 | negative listlengths 20 553 |
|---|---|---|---|---|
For application NAME leave SIZE crashlogs or remove all crashlogs with timestamp > TIMESTAMP . | def crashlog_clean ( name , timestamp , size , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'crashlog:clean' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'size' : size , 'timestamp' : timestamp , } ) | 6,400 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1231-L1241 | [
"def",
"pin_channel",
"(",
"current",
")",
":",
"try",
":",
"Subscriber",
"(",
"current",
")",
".",
"objects",
".",
"filter",
"(",
"user_id",
"=",
"current",
".",
"user_id",
",",
"channel_id",
"=",
"current",
".",
"input",
"[",
"'channel_key'",
"]",
")",
".",
"update",
"(",
"pinned",
"=",
"True",
")",
"current",
".",
"output",
"=",
"{",
"'status'",
":",
"'OK'",
",",
"'code'",
":",
"200",
"}",
"except",
"ObjectDoesNotExist",
":",
"raise",
"HTTPError",
"(",
"404",
",",
"\"\"",
")"
] |
Remove all crashlogs from one date up to another . | def crashlog_cleanrange ( from_day , up_to_day , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'crashlog:cleanwhen' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'from_day' : from_day , 'to_day' : up_to_day , } ) | 6,401 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1248-L1262 | [
"def",
"revoke_member",
"(",
"context",
",",
"request",
")",
":",
"mapping",
"=",
"request",
".",
"json",
"[",
"'mapping'",
"]",
"for",
"entry",
"in",
"mapping",
":",
"user",
"=",
"entry",
"[",
"'user'",
"]",
"roles",
"=",
"entry",
"[",
"'roles'",
"]",
"username",
"=",
"user",
".",
"get",
"(",
"'username'",
",",
"None",
")",
"userid",
"=",
"user",
".",
"get",
"(",
"'userid'",
",",
"None",
")",
"if",
"userid",
":",
"u",
"=",
"context",
".",
"get_user_by_userid",
"(",
"userid",
")",
"elif",
"username",
":",
"u",
"=",
"context",
".",
"get_user_by_username",
"(",
"username",
")",
"else",
":",
"u",
"=",
"None",
"if",
"u",
"is",
"None",
":",
"raise",
"UnprocessableError",
"(",
"'User %s does not exists'",
"%",
"(",
"userid",
"or",
"username",
")",
")",
"for",
"rolename",
"in",
"roles",
":",
"context",
".",
"revoke_member_role",
"(",
"u",
".",
"userid",
",",
"rolename",
")",
"return",
"{",
"'status'",
":",
"'success'",
"}"
] |
Show available routing groups . | def group_list ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'group:list' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , } ) | 6,402 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1267-L1274 | [
"def",
"upload_crop",
"(",
"self",
",",
"ims_host",
",",
"filename",
",",
"id_annot",
",",
"id_storage",
",",
"id_project",
"=",
"None",
",",
"sync",
"=",
"False",
",",
"protocol",
"=",
"None",
")",
":",
"if",
"not",
"protocol",
":",
"protocol",
"=",
"self",
".",
"_protocol",
"ims_host",
",",
"protocol",
"=",
"self",
".",
"_parse_url",
"(",
"ims_host",
",",
"protocol",
")",
"ims_host",
"=",
"\"{}://{}\"",
".",
"format",
"(",
"protocol",
",",
"ims_host",
")",
"query_parameters",
"=",
"{",
"\"annotation\"",
":",
"id_annot",
",",
"\"storage\"",
":",
"id_storage",
",",
"\"cytomine\"",
":",
"\"{}://{}\"",
".",
"format",
"(",
"self",
".",
"_protocol",
",",
"self",
".",
"_host",
")",
",",
"\"name\"",
":",
"filename",
",",
"\"sync\"",
":",
"sync",
"}",
"if",
"id_project",
":",
"query_parameters",
"[",
"\"project\"",
"]",
"=",
"id_project",
"response",
"=",
"self",
".",
"_session",
".",
"post",
"(",
"\"{}/uploadCrop\"",
".",
"format",
"(",
"ims_host",
")",
",",
"auth",
"=",
"CytomineAuth",
"(",
"self",
".",
"_public_key",
",",
"self",
".",
"_private_key",
",",
"ims_host",
",",
"\"\"",
")",
",",
"headers",
"=",
"self",
".",
"_headers",
"(",
")",
",",
"params",
"=",
"query_parameters",
")",
"if",
"response",
".",
"status_code",
"==",
"requests",
".",
"codes",
".",
"ok",
":",
"uf",
"=",
"self",
".",
"_process_upload_response",
"(",
"response",
".",
"json",
"(",
")",
")",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Image crop uploaded successfully to {}\"",
".",
"format",
"(",
"ims_host",
")",
")",
"return",
"uf",
"else",
":",
"self",
".",
"_logger",
".",
"error",
"(",
"\"Error during crop upload. Response: %s\"",
",",
"response",
")",
"return",
"False"
] |
Show specified routing group . | def group_view ( name , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'group:view' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , } ) | 6,403 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1280-L1288 | [
"def",
"upload_crop",
"(",
"self",
",",
"ims_host",
",",
"filename",
",",
"id_annot",
",",
"id_storage",
",",
"id_project",
"=",
"None",
",",
"sync",
"=",
"False",
",",
"protocol",
"=",
"None",
")",
":",
"if",
"not",
"protocol",
":",
"protocol",
"=",
"self",
".",
"_protocol",
"ims_host",
",",
"protocol",
"=",
"self",
".",
"_parse_url",
"(",
"ims_host",
",",
"protocol",
")",
"ims_host",
"=",
"\"{}://{}\"",
".",
"format",
"(",
"protocol",
",",
"ims_host",
")",
"query_parameters",
"=",
"{",
"\"annotation\"",
":",
"id_annot",
",",
"\"storage\"",
":",
"id_storage",
",",
"\"cytomine\"",
":",
"\"{}://{}\"",
".",
"format",
"(",
"self",
".",
"_protocol",
",",
"self",
".",
"_host",
")",
",",
"\"name\"",
":",
"filename",
",",
"\"sync\"",
":",
"sync",
"}",
"if",
"id_project",
":",
"query_parameters",
"[",
"\"project\"",
"]",
"=",
"id_project",
"response",
"=",
"self",
".",
"_session",
".",
"post",
"(",
"\"{}/uploadCrop\"",
".",
"format",
"(",
"ims_host",
")",
",",
"auth",
"=",
"CytomineAuth",
"(",
"self",
".",
"_public_key",
",",
"self",
".",
"_private_key",
",",
"ims_host",
",",
"\"\"",
")",
",",
"headers",
"=",
"self",
".",
"_headers",
"(",
")",
",",
"params",
"=",
"query_parameters",
")",
"if",
"response",
".",
"status_code",
"==",
"requests",
".",
"codes",
".",
"ok",
":",
"uf",
"=",
"self",
".",
"_process_upload_response",
"(",
"response",
".",
"json",
"(",
")",
")",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Image crop uploaded successfully to {}\"",
".",
"format",
"(",
"ims_host",
")",
")",
"return",
"uf",
"else",
":",
"self",
".",
"_logger",
".",
"error",
"(",
"\"Error during crop upload. Response: %s\"",
",",
"response",
")",
"return",
"False"
] |
Create routing group . | def group_create ( name , content , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'group:create' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'content' : content , } ) | 6,404 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1295-L1317 | [
"def",
"returnJobReqs",
"(",
"self",
",",
"jobReqs",
")",
":",
"# Since we are only reading this job's specific values from the state file, we don't",
"# need a lock",
"jobState",
"=",
"self",
".",
"_JobState",
"(",
"self",
".",
"_CacheState",
".",
"_load",
"(",
"self",
".",
"cacheStateFile",
")",
".",
"jobState",
"[",
"self",
".",
"jobID",
"]",
")",
"for",
"x",
"in",
"list",
"(",
"jobState",
".",
"jobSpecificFiles",
".",
"keys",
"(",
")",
")",
":",
"self",
".",
"deleteLocalFile",
"(",
"x",
")",
"with",
"self",
".",
"_CacheState",
".",
"open",
"(",
"self",
")",
"as",
"cacheInfo",
":",
"cacheInfo",
".",
"sigmaJob",
"-=",
"jobReqs"
] |
Remove routing group from the storage . | def group_remove ( name , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'group:remove' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , } ) | 6,405 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1323-L1331 | [
"def",
"genargs",
"(",
")",
"->",
"ArgumentParser",
":",
"parser",
"=",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"\"spec\"",
",",
"help",
"=",
"\"JSG specification - can be file name, URI or string\"",
")",
"parser",
".",
"add_argument",
"(",
"\"-o\"",
",",
"\"--outfile\"",
",",
"help",
"=",
"\"Output python file - if omitted, python is not saved\"",
")",
"parser",
".",
"add_argument",
"(",
"\"-p\"",
",",
"\"--print\"",
",",
"help",
"=",
"\"Print python file to stdout\"",
")",
"parser",
".",
"add_argument",
"(",
"\"-id\"",
",",
"\"--inputdir\"",
",",
"help",
"=",
"\"Input directory with JSON files\"",
")",
"parser",
".",
"add_argument",
"(",
"\"-i\"",
",",
"\"--json\"",
",",
"help",
"=",
"\"URL, file name or json text\"",
",",
"nargs",
"=",
"'*'",
")",
"return",
"parser"
] |
Copy routing group . | def group_copy ( name , copyname , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'group:copy' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'copyname' : copyname , } ) | 6,406 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1338-L1347 | [
"def",
"returnJobReqs",
"(",
"self",
",",
"jobReqs",
")",
":",
"# Since we are only reading this job's specific values from the state file, we don't",
"# need a lock",
"jobState",
"=",
"self",
".",
"_JobState",
"(",
"self",
".",
"_CacheState",
".",
"_load",
"(",
"self",
".",
"cacheStateFile",
")",
".",
"jobState",
"[",
"self",
".",
"jobID",
"]",
")",
"for",
"x",
"in",
"list",
"(",
"jobState",
".",
"jobSpecificFiles",
".",
"keys",
"(",
")",
")",
":",
"self",
".",
"deleteLocalFile",
"(",
"x",
")",
"with",
"self",
".",
"_CacheState",
".",
"open",
"(",
"self",
")",
"as",
"cacheInfo",
":",
"cacheInfo",
".",
"sigmaJob",
"-=",
"jobReqs"
] |
Refresh routing group . | def group_refresh ( name , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'group:refresh' , * * { 'locator' : ctx . locator , 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , } ) | 6,407 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1369-L1380 | [
"def",
"returnJobReqs",
"(",
"self",
",",
"jobReqs",
")",
":",
"# Since we are only reading this job's specific values from the state file, we don't",
"# need a lock",
"jobState",
"=",
"self",
".",
"_JobState",
"(",
"self",
".",
"_CacheState",
".",
"_load",
"(",
"self",
".",
"cacheStateFile",
")",
".",
"jobState",
"[",
"self",
".",
"jobID",
"]",
")",
"for",
"x",
"in",
"list",
"(",
"jobState",
".",
"jobSpecificFiles",
".",
"keys",
"(",
")",
")",
":",
"self",
".",
"deleteLocalFile",
"(",
"x",
")",
"with",
"self",
".",
"_CacheState",
".",
"open",
"(",
"self",
")",
"as",
"cacheInfo",
":",
"cacheInfo",
".",
"sigmaJob",
"-=",
"jobReqs"
] |
Add application with its weight into the routing group . | def group_push ( name , app , weight , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'group:app:add' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'app' : app , 'weight' : weight , } ) | 6,408 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1388-L1400 | [
"def",
"highlight_block",
"(",
"self",
",",
"text",
",",
"block",
")",
":",
"if",
"self",
".",
"color_scheme",
".",
"name",
"!=",
"self",
".",
"_pygments_style",
":",
"self",
".",
"_pygments_style",
"=",
"self",
".",
"color_scheme",
".",
"name",
"self",
".",
"_update_style",
"(",
")",
"original_text",
"=",
"text",
"if",
"self",
".",
"editor",
"and",
"self",
".",
"_lexer",
"and",
"self",
".",
"enabled",
":",
"if",
"block",
".",
"blockNumber",
"(",
")",
":",
"prev_data",
"=",
"self",
".",
"_prev_block",
".",
"userData",
"(",
")",
"if",
"prev_data",
":",
"if",
"hasattr",
"(",
"prev_data",
",",
"\"syntax_stack\"",
")",
":",
"self",
".",
"_lexer",
".",
"_saved_state_stack",
"=",
"prev_data",
".",
"syntax_stack",
"elif",
"hasattr",
"(",
"self",
".",
"_lexer",
",",
"'_saved_state_stack'",
")",
":",
"del",
"self",
".",
"_lexer",
".",
"_saved_state_stack",
"# Lex the text using Pygments",
"index",
"=",
"0",
"usd",
"=",
"block",
".",
"userData",
"(",
")",
"if",
"usd",
"is",
"None",
":",
"usd",
"=",
"TextBlockUserData",
"(",
")",
"block",
".",
"setUserData",
"(",
"usd",
")",
"tokens",
"=",
"list",
"(",
"self",
".",
"_lexer",
".",
"get_tokens",
"(",
"text",
")",
")",
"for",
"token",
",",
"text",
"in",
"tokens",
":",
"length",
"=",
"len",
"(",
"text",
")",
"fmt",
"=",
"self",
".",
"_get_format",
"(",
"token",
")",
"if",
"token",
"in",
"[",
"Token",
".",
"Literal",
".",
"String",
",",
"Token",
".",
"Literal",
".",
"String",
".",
"Doc",
",",
"Token",
".",
"Comment",
"]",
":",
"fmt",
".",
"setObjectType",
"(",
"fmt",
".",
"UserObject",
")",
"self",
".",
"setFormat",
"(",
"index",
",",
"length",
",",
"fmt",
")",
"index",
"+=",
"length",
"if",
"hasattr",
"(",
"self",
".",
"_lexer",
",",
"'_saved_state_stack'",
")",
":",
"setattr",
"(",
"usd",
",",
"\"syntax_stack\"",
",",
"self",
".",
"_lexer",
".",
"_saved_state_stack",
")",
"# Clean up for the next go-round.",
"del",
"self",
".",
"_lexer",
".",
"_saved_state_stack",
"# spaces",
"text",
"=",
"original_text",
"expression",
"=",
"QRegExp",
"(",
"r'\\s+'",
")",
"index",
"=",
"expression",
".",
"indexIn",
"(",
"text",
",",
"0",
")",
"while",
"index",
">=",
"0",
":",
"index",
"=",
"expression",
".",
"pos",
"(",
"0",
")",
"length",
"=",
"len",
"(",
"expression",
".",
"cap",
"(",
"0",
")",
")",
"self",
".",
"setFormat",
"(",
"index",
",",
"length",
",",
"self",
".",
"_get_format",
"(",
"Whitespace",
")",
")",
"index",
"=",
"expression",
".",
"indexIn",
"(",
"text",
",",
"index",
"+",
"length",
")",
"self",
".",
"_prev_block",
"=",
"block"
] |
Remove application from the specified routing group . | def group_pop ( name , app , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'group:app:remove' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'app' : app , } ) | 6,409 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1407-L1416 | [
"def",
"savedocx",
"(",
"document",
",",
"coreprops",
",",
"appprops",
",",
"contenttypes",
",",
"websettings",
",",
"wordrelationships",
",",
"output",
",",
"imagefiledict",
"=",
"None",
")",
":",
"if",
"imagefiledict",
"is",
"None",
":",
"warn",
"(",
"'Using savedocx() without imagefiledict parameter will be deprec'",
"'ated in the future.'",
",",
"PendingDeprecationWarning",
")",
"assert",
"os",
".",
"path",
".",
"isdir",
"(",
"template_dir",
")",
"docxfile",
"=",
"zipfile",
".",
"ZipFile",
"(",
"output",
",",
"mode",
"=",
"'w'",
",",
"compression",
"=",
"zipfile",
".",
"ZIP_DEFLATED",
")",
"# Move to the template data path",
"prev_dir",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"'.'",
")",
"# save previous working dir",
"os",
".",
"chdir",
"(",
"template_dir",
")",
"# Serialize our trees into out zip file",
"treesandfiles",
"=",
"{",
"document",
":",
"'word/document.xml'",
",",
"coreprops",
":",
"'docProps/core.xml'",
",",
"appprops",
":",
"'docProps/app.xml'",
",",
"contenttypes",
":",
"'[Content_Types].xml'",
",",
"websettings",
":",
"'word/webSettings.xml'",
",",
"wordrelationships",
":",
"'word/_rels/document.xml.rels'",
"}",
"for",
"tree",
"in",
"treesandfiles",
":",
"log",
".",
"info",
"(",
"'Saving: %s'",
"%",
"treesandfiles",
"[",
"tree",
"]",
")",
"treestring",
"=",
"etree",
".",
"tostring",
"(",
"tree",
",",
"pretty_print",
"=",
"True",
")",
"docxfile",
".",
"writestr",
"(",
"treesandfiles",
"[",
"tree",
"]",
",",
"treestring",
")",
"# Add & compress images, if applicable",
"if",
"imagefiledict",
"is",
"not",
"None",
":",
"for",
"imagepath",
",",
"picrelid",
"in",
"imagefiledict",
".",
"items",
"(",
")",
":",
"archivename",
"=",
"'word/media/%s_%s'",
"%",
"(",
"picrelid",
",",
"basename",
"(",
"imagepath",
")",
")",
"log",
".",
"info",
"(",
"'Saving: %s'",
",",
"archivename",
")",
"docxfile",
".",
"write",
"(",
"imagepath",
",",
"archivename",
")",
"# Add & compress support files",
"files_to_ignore",
"=",
"[",
"'.DS_Store'",
"]",
"# nuisance from some os's",
"for",
"dirpath",
",",
"dirnames",
",",
"filenames",
"in",
"os",
".",
"walk",
"(",
"'.'",
")",
":",
"for",
"filename",
"in",
"filenames",
":",
"if",
"filename",
"in",
"files_to_ignore",
":",
"continue",
"templatefile",
"=",
"join",
"(",
"dirpath",
",",
"filename",
")",
"archivename",
"=",
"templatefile",
"[",
"2",
":",
"]",
"log",
".",
"info",
"(",
"'Saving: %s'",
",",
"archivename",
")",
"docxfile",
".",
"write",
"(",
"templatefile",
",",
"archivename",
")",
"log",
".",
"info",
"(",
"'Saved new file to: %r'",
",",
"output",
")",
"docxfile",
".",
"close",
"(",
")",
"os",
".",
"chdir",
"(",
"prev_dir",
")",
"# restore previous working dir",
"return"
] |
Edit Unicorn node interactively . | def unicorn_edit ( path , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . timeout = None ctx . execute_action ( 'unicorn:edit' , * * { 'unicorn' : ctx . repo . create_secure_service ( 'unicorn' ) , 'path' : path , } ) | 6,410 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1472-L1480 | [
"def",
"relative_humidity",
"(",
"self",
",",
"value",
"=",
"999",
")",
":",
"if",
"value",
"is",
"not",
"None",
":",
"try",
":",
"value",
"=",
"int",
"(",
"value",
")",
"except",
"ValueError",
":",
"raise",
"ValueError",
"(",
"'value {} need to be of type int '",
"'for field `relative_humidity`'",
".",
"format",
"(",
"value",
")",
")",
"if",
"value",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"'value need to be greater or equal 0 '",
"'for field `relative_humidity`'",
")",
"if",
"value",
">",
"110",
":",
"raise",
"ValueError",
"(",
"'value need to be smaller 110 '",
"'for field `relative_humidity`'",
")",
"self",
".",
"_relative_humidity",
"=",
"value"
] |
List all registered logger names . | def logging_list_loggers ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'logging:list_loggers' , * * { 'logging_service' : ctx . repo . create_secure_service ( 'logging' ) , } ) | 6,411 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1579-L1586 | [
"def",
"parse_torrent_properties",
"(",
"table_datas",
")",
":",
"output",
"=",
"{",
"'category'",
":",
"table_datas",
"[",
"0",
"]",
".",
"text",
",",
"'subcategory'",
":",
"None",
",",
"'quality'",
":",
"None",
",",
"'language'",
":",
"None",
"}",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"table_datas",
")",
")",
":",
"td",
"=",
"table_datas",
"[",
"i",
"]",
"url",
"=",
"td",
".",
"get",
"(",
"'href'",
")",
"params",
"=",
"Parser",
".",
"get_params",
"(",
"url",
")",
"if",
"Parser",
".",
"is_subcategory",
"(",
"params",
")",
"and",
"not",
"output",
"[",
"'subcategory'",
"]",
":",
"output",
"[",
"'subcategory'",
"]",
"=",
"td",
".",
"text",
"elif",
"Parser",
".",
"is_quality",
"(",
"params",
")",
"and",
"not",
"output",
"[",
"'quality'",
"]",
":",
"output",
"[",
"'quality'",
"]",
"=",
"td",
".",
"text",
"elif",
"Parser",
".",
"is_language",
"(",
"params",
")",
"and",
"not",
"output",
"[",
"'language'",
"]",
":",
"output",
"[",
"'language'",
"]",
"=",
"td",
".",
"text",
"return",
"output"
] |
Set local filter . | def logging_set_filter ( name , filter_def , ttl , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'logging:set_filter' , * * { 'logging_service' : ctx . repo . create_secure_service ( 'logging' ) , 'logger_name' : name , 'filter_def' : filter_def , 'ttl' : ttl , } ) | 6,412 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1594-L1604 | [
"def",
"unbind",
"(",
"self",
",",
"devices_to_unbind",
")",
":",
"if",
"self",
".",
"entity_api_key",
"==",
"\"\"",
":",
"return",
"{",
"'status'",
":",
"'failure'",
",",
"'response'",
":",
"'No API key found in request'",
"}",
"url",
"=",
"self",
".",
"base_url",
"+",
"\"api/0.1.0/subscribe/unbind\"",
"headers",
"=",
"{",
"\"apikey\"",
":",
"self",
".",
"entity_api_key",
"}",
"data",
"=",
"{",
"\"exchange\"",
":",
"\"amq.topic\"",
",",
"\"keys\"",
":",
"devices_to_unbind",
",",
"\"queue\"",
":",
"self",
".",
"entity_id",
"}",
"with",
"self",
".",
"no_ssl_verification",
"(",
")",
":",
"r",
"=",
"requests",
".",
"delete",
"(",
"url",
",",
"json",
"=",
"data",
",",
"headers",
"=",
"headers",
")",
"print",
"(",
"r",
")",
"response",
"=",
"dict",
"(",
")",
"if",
"\"No API key\"",
"in",
"str",
"(",
"r",
".",
"content",
".",
"decode",
"(",
"\"utf-8\"",
")",
")",
":",
"response",
"[",
"\"status\"",
"]",
"=",
"\"failure\"",
"r",
"=",
"json",
".",
"loads",
"(",
"r",
".",
"content",
".",
"decode",
"(",
"\"utf-8\"",
")",
")",
"[",
"'message'",
"]",
"elif",
"'unbind'",
"in",
"str",
"(",
"r",
".",
"content",
".",
"decode",
"(",
"\"utf-8\"",
")",
")",
":",
"response",
"[",
"\"status\"",
"]",
"=",
"\"success\"",
"r",
"=",
"r",
".",
"content",
".",
"decode",
"(",
"\"utf-8\"",
")",
"else",
":",
"response",
"[",
"\"status\"",
"]",
"=",
"\"failure\"",
"r",
"=",
"r",
".",
"content",
".",
"decode",
"(",
"\"utf-8\"",
")",
"response",
"[",
"\"response\"",
"]",
"=",
"str",
"(",
"r",
")",
"return",
"response"
] |
Remove filter by filter id . | def logging_remove_filter ( filter_id , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'logging:remove_filter' , * * { 'logging_service' : ctx . repo . create_secure_service ( 'logging' ) , 'filter_id' : filter_id , } ) | 6,413 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1610-L1618 | [
"def",
"_send_register_payload",
"(",
"self",
",",
"websocket",
")",
":",
"file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"HANDSHAKE_FILE_NAME",
")",
"data",
"=",
"codecs",
".",
"open",
"(",
"file",
",",
"'r'",
",",
"'utf-8'",
")",
"raw_handshake",
"=",
"data",
".",
"read",
"(",
")",
"handshake",
"=",
"json",
".",
"loads",
"(",
"raw_handshake",
")",
"handshake",
"[",
"'payload'",
"]",
"[",
"'client-key'",
"]",
"=",
"self",
".",
"client_key",
"yield",
"from",
"websocket",
".",
"send",
"(",
"json",
".",
"dumps",
"(",
"handshake",
")",
")",
"raw_response",
"=",
"yield",
"from",
"websocket",
".",
"recv",
"(",
")",
"response",
"=",
"json",
".",
"loads",
"(",
"raw_response",
")",
"if",
"response",
"[",
"'type'",
"]",
"==",
"'response'",
"and",
"response",
"[",
"'payload'",
"]",
"[",
"'pairingType'",
"]",
"==",
"'PROMPT'",
":",
"raw_response",
"=",
"yield",
"from",
"websocket",
".",
"recv",
"(",
")",
"response",
"=",
"json",
".",
"loads",
"(",
"raw_response",
")",
"if",
"response",
"[",
"'type'",
"]",
"==",
"'registered'",
":",
"self",
".",
"client_key",
"=",
"response",
"[",
"'payload'",
"]",
"[",
"'client-key'",
"]",
"self",
".",
"save_key_file",
"(",
")"
] |
List all available filters . | def logging_list_filters ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'logging:list_filters' , * * { 'logging_service' : ctx . repo . create_secure_service ( 'logging' ) , } ) | 6,414 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1623-L1630 | [
"def",
"reassign_comment_to_book",
"(",
"self",
",",
"comment_id",
",",
"from_book_id",
",",
"to_book_id",
")",
":",
"# Implemented from template for",
"# osid.resource.ResourceBinAssignmentSession.reassign_resource_to_bin",
"self",
".",
"assign_comment_to_book",
"(",
"comment_id",
",",
"to_book_id",
")",
"try",
":",
"self",
".",
"unassign_comment_from_book",
"(",
"comment_id",
",",
"from_book_id",
")",
"except",
":",
"# something went wrong, roll back assignment to to_book_id",
"self",
".",
"unassign_comment_from_book",
"(",
"comment_id",
",",
"to_book_id",
")",
"raise"
] |
Shows available authorization groups . | def auth_list ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'auth:group:list' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , } ) | 6,415 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1653-L1660 | [
"def",
"OnAdjustVolume",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"volume",
"=",
"self",
".",
"player",
".",
"audio_get_volume",
"(",
")",
"if",
"event",
".",
"GetWheelRotation",
"(",
")",
"<",
"0",
":",
"self",
".",
"volume",
"=",
"max",
"(",
"0",
",",
"self",
".",
"volume",
"-",
"10",
")",
"elif",
"event",
".",
"GetWheelRotation",
"(",
")",
">",
"0",
":",
"self",
".",
"volume",
"=",
"min",
"(",
"200",
",",
"self",
".",
"volume",
"+",
"10",
")",
"self",
".",
"player",
".",
"audio_set_volume",
"(",
"self",
".",
"volume",
")"
] |
Creates an authorization group . | def auth_create ( name , token , force , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'auth:group:create' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'token' : token , 'force' : force , } ) | 6,416 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1668-L1681 | [
"def",
"OnAdjustVolume",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"volume",
"=",
"self",
".",
"player",
".",
"audio_get_volume",
"(",
")",
"if",
"event",
".",
"GetWheelRotation",
"(",
")",
"<",
"0",
":",
"self",
".",
"volume",
"=",
"max",
"(",
"0",
",",
"self",
".",
"volume",
"-",
"10",
")",
"elif",
"event",
".",
"GetWheelRotation",
"(",
")",
">",
"0",
":",
"self",
".",
"volume",
"=",
"min",
"(",
"200",
",",
"self",
".",
"volume",
"+",
"10",
")",
"self",
".",
"player",
".",
"audio_set_volume",
"(",
"self",
".",
"volume",
")"
] |
Interactively edits an authorization group . | def auth_edit ( name , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . timeout = None ctx . execute_action ( 'auth:group:edit' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , } ) | 6,417 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1687-L1696 | [
"def",
"_shape_list",
"(",
"tensor",
")",
":",
"# Get statically known shape (may contain None's for unknown dimensions)",
"shape",
"=",
"tensor",
".",
"get_shape",
"(",
")",
".",
"as_list",
"(",
")",
"# Ensure that the shape values are not None",
"dynamic_shape",
"=",
"tf",
".",
"shape",
"(",
"tensor",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"shape",
")",
")",
":",
"if",
"shape",
"[",
"i",
"]",
"is",
"None",
":",
"shape",
"[",
"i",
"]",
"=",
"dynamic_shape",
"[",
"i",
"]",
"return",
"shape"
] |
Removes an authorization group . | def auth_remove ( name , drop , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'auth:group:remove' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'drop' : drop , } ) | 6,418 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1703-L1715 | [
"def",
"OnAdjustVolume",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"volume",
"=",
"self",
".",
"player",
".",
"audio_get_volume",
"(",
")",
"if",
"event",
".",
"GetWheelRotation",
"(",
")",
"<",
"0",
":",
"self",
".",
"volume",
"=",
"max",
"(",
"0",
",",
"self",
".",
"volume",
"-",
"10",
")",
"elif",
"event",
".",
"GetWheelRotation",
"(",
")",
">",
"0",
":",
"self",
".",
"volume",
"=",
"min",
"(",
"200",
",",
"self",
".",
"volume",
"+",
"10",
")",
"self",
".",
"player",
".",
"audio_set_volume",
"(",
"self",
".",
"volume",
")"
] |
Shows an authorization group s content . | def auth_view ( name , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'auth:group:view' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , } ) | 6,419 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1721-L1729 | [
"def",
"superclasses_bug_fix",
"(",
"data",
")",
":",
"for",
"i",
",",
"value",
"in",
"enumerate",
"(",
"data",
"[",
"'superclasses'",
"]",
")",
":",
"data",
"[",
"'superclasses'",
"]",
"[",
"i",
"]",
"[",
"'superclass_tid'",
"]",
"=",
"data",
"[",
"'superclasses'",
"]",
"[",
"i",
"]",
".",
"pop",
"(",
"'id'",
")",
"return",
"data"
] |
Adds a member of an authorization group . | def auth_add ( name , service , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'auth:group:members:add' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'service' : service , } ) | 6,420 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1736-L1745 | [
"def",
"_archive_self",
"(",
"self",
",",
"logfile",
",",
"key",
"=",
"JobDetails",
".",
"topkey",
",",
"status",
"=",
"JobStatus",
".",
"unknown",
")",
":",
"self",
".",
"_register_self",
"(",
"logfile",
",",
"key",
",",
"status",
")",
"if",
"self",
".",
"_job_archive",
"is",
"None",
":",
"return",
"self",
".",
"_job_archive",
".",
"register_jobs",
"(",
"self",
".",
"get_jobs",
"(",
")",
")"
] |
Shows collections with ACL . | def access_storage_list ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'access:storage:list' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , } ) | 6,421 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1816-L1823 | [
"def",
"stop_experiment",
"(",
"args",
")",
":",
"experiment_id_list",
"=",
"parse_ids",
"(",
"args",
")",
"if",
"experiment_id_list",
":",
"experiment_config",
"=",
"Experiments",
"(",
")",
"experiment_dict",
"=",
"experiment_config",
".",
"get_all_experiments",
"(",
")",
"for",
"experiment_id",
"in",
"experiment_id_list",
":",
"print_normal",
"(",
"'Stoping experiment %s'",
"%",
"experiment_id",
")",
"nni_config",
"=",
"Config",
"(",
"experiment_dict",
"[",
"experiment_id",
"]",
"[",
"'fileName'",
"]",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"rest_pid",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPid'",
")",
"if",
"rest_pid",
":",
"kill_command",
"(",
"rest_pid",
")",
"tensorboard_pid_list",
"=",
"nni_config",
".",
"get_config",
"(",
"'tensorboardPidList'",
")",
"if",
"tensorboard_pid_list",
":",
"for",
"tensorboard_pid",
"in",
"tensorboard_pid_list",
":",
"try",
":",
"kill_command",
"(",
"tensorboard_pid",
")",
"except",
"Exception",
"as",
"exception",
":",
"print_error",
"(",
"exception",
")",
"nni_config",
".",
"set_config",
"(",
"'tensorboardPidList'",
",",
"[",
"]",
")",
"print_normal",
"(",
"'Stop experiment success!'",
")",
"experiment_config",
".",
"update_experiment",
"(",
"experiment_id",
",",
"'status'",
",",
"'STOPPED'",
")",
"time_now",
"=",
"time",
".",
"strftime",
"(",
"'%Y-%m-%d %H:%M:%S'",
",",
"time",
".",
"localtime",
"(",
"time",
".",
"time",
"(",
")",
")",
")",
"experiment_config",
".",
"update_experiment",
"(",
"experiment_id",
",",
"'endTime'",
",",
"str",
"(",
"time_now",
")",
")"
] |
Shows ACL for the specified collection . | def access_storage_view ( name , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'access:storage:view' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , } ) | 6,422 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1829-L1837 | [
"def",
"reset",
"(",
"self",
",",
"ms",
"=",
"0",
",",
"halt",
"=",
"True",
")",
":",
"self",
".",
"_dll",
".",
"JLINKARM_SetResetDelay",
"(",
"ms",
")",
"res",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_Reset",
"(",
")",
"if",
"res",
"<",
"0",
":",
"raise",
"errors",
".",
"JLinkException",
"(",
"res",
")",
"elif",
"not",
"halt",
":",
"self",
".",
"_dll",
".",
"JLINKARM_Go",
"(",
")",
"return",
"res"
] |
Creates new ACL for the specified collection . | def access_storage_create ( name , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'access:storage:create' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , } ) | 6,423 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1843-L1853 | [
"def",
"_get_all_data",
"(",
"self",
",",
"start_date",
",",
"end_date",
")",
":",
"return",
"[",
"self",
".",
"_get_input_data",
"(",
"var",
",",
"start_date",
",",
"end_date",
")",
"for",
"var",
"in",
"_replace_pressure",
"(",
"self",
".",
"variables",
",",
"self",
".",
"dtype_in_vert",
")",
"]"
] |
Edits ACL for the specified collection . | def access_storage_edit ( name , cid , uid , perm , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'access:storage:edit' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , 'cids' : cid , 'uids' : uid , 'perm' : perm , } ) | 6,424 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1863-L1876 | [
"def",
"reset",
"(",
"self",
",",
"ms",
"=",
"0",
",",
"halt",
"=",
"True",
")",
":",
"self",
".",
"_dll",
".",
"JLINKARM_SetResetDelay",
"(",
"ms",
")",
"res",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_Reset",
"(",
")",
"if",
"res",
"<",
"0",
":",
"raise",
"errors",
".",
"JLinkException",
"(",
"res",
")",
"elif",
"not",
"halt",
":",
"self",
".",
"_dll",
".",
"JLINKARM_Go",
"(",
")",
"return",
"res"
] |
Remove ACL for the specified collection . | def access_storage_rm ( name , yes , * * kwargs ) : if name is None : if not yes : click . confirm ( 'Are you sure you want to remove all ACL?' , abort = True ) ctx = Context ( * * kwargs ) ctx . execute_action ( 'access:storage:rm' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , 'name' : name , } ) | 6,425 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1883-L1897 | [
"def",
"reset",
"(",
"self",
",",
"ms",
"=",
"0",
",",
"halt",
"=",
"True",
")",
":",
"self",
".",
"_dll",
".",
"JLINKARM_SetResetDelay",
"(",
"ms",
")",
"res",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_Reset",
"(",
")",
"if",
"res",
"<",
"0",
":",
"raise",
"errors",
".",
"JLinkException",
"(",
"res",
")",
"elif",
"not",
"halt",
":",
"self",
".",
"_dll",
".",
"JLINKARM_Go",
"(",
")",
"return",
"res"
] |
Shows services for which there are ACL specified . | def access_list ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'access:list' , * * { 'unicorn' : ctx . repo . create_secure_service ( 'unicorn' ) , } ) | 6,426 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1902-L1909 | [
"def",
"_read_body_by_chunk",
"(",
"self",
",",
"response",
",",
"file",
",",
"raw",
"=",
"False",
")",
":",
"reader",
"=",
"ChunkedTransferReader",
"(",
"self",
".",
"_connection",
")",
"file_is_async",
"=",
"hasattr",
"(",
"file",
",",
"'drain'",
")",
"while",
"True",
":",
"chunk_size",
",",
"data",
"=",
"yield",
"from",
"reader",
".",
"read_chunk_header",
"(",
")",
"self",
".",
"_data_event_dispatcher",
".",
"notify_read",
"(",
"data",
")",
"if",
"raw",
":",
"file",
".",
"write",
"(",
"data",
")",
"if",
"not",
"chunk_size",
":",
"break",
"while",
"True",
":",
"content",
",",
"data",
"=",
"yield",
"from",
"reader",
".",
"read_chunk_body",
"(",
")",
"self",
".",
"_data_event_dispatcher",
".",
"notify_read",
"(",
"data",
")",
"if",
"not",
"content",
":",
"if",
"raw",
":",
"file",
".",
"write",
"(",
"data",
")",
"break",
"content",
"=",
"self",
".",
"_decompress_data",
"(",
"content",
")",
"if",
"file",
":",
"file",
".",
"write",
"(",
"content",
")",
"if",
"file_is_async",
":",
"yield",
"from",
"file",
".",
"drain",
"(",
")",
"content",
"=",
"self",
".",
"_flush_decompressor",
"(",
")",
"if",
"file",
":",
"file",
".",
"write",
"(",
"content",
")",
"if",
"file_is_async",
":",
"yield",
"from",
"file",
".",
"drain",
"(",
")",
"trailer_data",
"=",
"yield",
"from",
"reader",
".",
"read_trailer",
"(",
")",
"self",
".",
"_data_event_dispatcher",
".",
"notify_read",
"(",
"trailer_data",
")",
"if",
"file",
"and",
"raw",
":",
"file",
".",
"write",
"(",
"trailer_data",
")",
"if",
"file_is_async",
":",
"yield",
"from",
"file",
".",
"drain",
"(",
")",
"response",
".",
"fields",
".",
"parse",
"(",
"trailer_data",
")"
] |
Shows ACL for the specified service . | def access_view ( name , * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'access:view' , * * { 'unicorn' : ctx . repo . create_secure_service ( 'unicorn' ) , 'service' : name , } ) | 6,427 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1915-L1923 | [
"def",
"create_or_update",
"(",
"cls",
",",
"bucket",
",",
"key",
",",
"value",
")",
":",
"obj",
"=",
"cls",
".",
"get",
"(",
"bucket",
",",
"key",
")",
"if",
"obj",
":",
"obj",
".",
"value",
"=",
"value",
"db",
".",
"session",
".",
"merge",
"(",
"obj",
")",
"else",
":",
"obj",
"=",
"cls",
".",
"create",
"(",
"bucket",
",",
"key",
",",
"value",
")",
"return",
"obj"
] |
View saved public keys . | def keyring_view ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'keyring:view' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , } ) | 6,428 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1966-L1973 | [
"def",
"command_max_delay",
"(",
"self",
",",
"event",
"=",
"None",
")",
":",
"try",
":",
"max_delay",
"=",
"self",
".",
"max_delay_var",
".",
"get",
"(",
")",
"except",
"ValueError",
":",
"max_delay",
"=",
"self",
".",
"runtime_cfg",
".",
"max_delay",
"if",
"max_delay",
"<",
"0",
":",
"max_delay",
"=",
"self",
".",
"runtime_cfg",
".",
"max_delay",
"if",
"max_delay",
">",
"0.1",
":",
"max_delay",
"=",
"self",
".",
"runtime_cfg",
".",
"max_delay",
"self",
".",
"runtime_cfg",
".",
"max_delay",
"=",
"max_delay",
"self",
".",
"max_delay_var",
".",
"set",
"(",
"self",
".",
"runtime_cfg",
".",
"max_delay",
")"
] |
Removes a public key from the keyring . | def keyring_remove ( key , yes , * * kwargs ) : if key is None : if not yes : click . confirm ( 'Are you sure you want to remove all keys?' , abort = True ) ctx = Context ( * * kwargs ) ctx . execute_action ( 'keyring:remove' , * * { 'key' : key , 'storage' : ctx . repo . create_secure_service ( 'storage' ) , } ) | 6,429 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L1998-L2013 | [
"def",
"mmGetPlotUnionSDRActivity",
"(",
"self",
",",
"title",
"=",
"\"Union SDR Activity Raster\"",
",",
"showReset",
"=",
"False",
",",
"resetShading",
"=",
"0.25",
")",
":",
"unionSDRTrace",
"=",
"self",
".",
"mmGetTraceUnionSDR",
"(",
")",
".",
"data",
"columnCount",
"=",
"self",
".",
"getNumColumns",
"(",
")",
"activityType",
"=",
"\"Union SDR Activity\"",
"return",
"self",
".",
"mmGetCellTracePlot",
"(",
"unionSDRTrace",
",",
"columnCount",
",",
"activityType",
",",
"title",
"=",
"title",
",",
"showReset",
"=",
"showReset",
",",
"resetShading",
"=",
"resetShading",
")"
] |
Edits interactively the keyring . | def keyring_edit ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . timeout = None ctx . execute_action ( 'keyring:edit' , * * { 'storage' : ctx . repo . create_secure_service ( 'storage' ) , } ) | 6,430 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L2018-L2026 | [
"def",
"process_orders",
"(",
"self",
",",
"orderbook",
")",
":",
"for",
"stock",
",",
"alloc",
"in",
"orderbook",
".",
"iteritems",
"(",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"'{}: Ordered {} {} stocks'",
".",
"format",
"(",
"self",
".",
"datetime",
",",
"stock",
",",
"alloc",
")",
")",
"if",
"isinstance",
"(",
"alloc",
",",
"int",
")",
":",
"self",
".",
"order",
"(",
"stock",
",",
"alloc",
")",
"elif",
"isinstance",
"(",
"alloc",
",",
"float",
")",
"and",
"alloc",
">=",
"-",
"1",
"and",
"alloc",
"<=",
"1",
":",
"self",
".",
"order_percent",
"(",
"stock",
",",
"alloc",
")",
"else",
":",
"self",
".",
"logger",
".",
"warning",
"(",
"'{}: invalid order for {}: {})'",
".",
"format",
"(",
"self",
".",
"datetime",
",",
"stock",
",",
"alloc",
")",
")"
] |
Refresh the keyring in the cocaine - runtime . | def keyring_refresh ( * * kwargs ) : ctx = Context ( * * kwargs ) ctx . execute_action ( 'keyring:refresh' , * * { 'tvm' : ctx . repo . create_secure_service ( 'tvm' ) , } ) | 6,431 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/dispatch.py#L2031-L2038 | [
"def",
"queryset",
"(",
"self",
",",
"request",
")",
":",
"qs",
"=",
"super",
"(",
"CommentAdmin",
",",
"self",
")",
".",
"queryset",
"(",
"request",
")",
"qs",
"=",
"qs",
".",
"filter",
"(",
"Q",
"(",
"user__is_staff",
"=",
"False",
")",
"|",
"Q",
"(",
"user__isnull",
"=",
"True",
")",
",",
"is_removed",
"=",
"False",
")",
"cls",
"=",
"getattr",
"(",
"self",
",",
"'cls'",
",",
"None",
")",
"if",
"cls",
":",
"qs",
"=",
"qs",
".",
"filter",
"(",
"classifiedcomment__cls",
"=",
"self",
".",
"cls",
")",
"return",
"qs",
".",
"select_related",
"(",
"'user'",
",",
"'content_type'",
")"
] |
This takes the parameter sets of the model instance and evaluates any formulas using the parameter values to create a fixed full set of parameters for each parameter set in the model | def evaluate_parameter_sets ( self ) : #parameter_interpreter = ParameterInterpreter(self.modelInstance) #parameter_interpreter.evaluate_parameter_sets() self . parameter_interpreter = LcoptParameterSet ( self . modelInstance ) self . modelInstance . evaluated_parameter_sets = self . parameter_interpreter . evaluated_parameter_sets self . modelInstance . bw2_export_params = self . parameter_interpreter . bw2_export_params | 6,432 | https://github.com/pjamesjoyce/lcopt/blob/3f1caca31fece4a3068a384900707e6d21d04597/lcopt/bw2_export.py#L18-L28 | [
"def",
"cudaMemcpy_dtoh",
"(",
"dst",
",",
"src",
",",
"count",
")",
":",
"status",
"=",
"_libcudart",
".",
"cudaMemcpy",
"(",
"dst",
",",
"src",
",",
"ctypes",
".",
"c_size_t",
"(",
"count",
")",
",",
"cudaMemcpyDeviceToHost",
")",
"cudaCheckStatus",
"(",
"status",
")"
] |
Creates a parameter map which takes a tuple of the exchange from and exchange to codes and returns the parameter name for that exchange | def create_parameter_map ( self ) : names = self . modelInstance . names db = self . modelInstance . database [ 'items' ] parameter_map = { } def get_names_index ( my_thing ) : return [ i for i , x in enumerate ( names ) if x == my_thing ] [ 0 ] for k , this_item in db . items ( ) : if this_item [ 'type' ] == 'process' : production_id = [ x [ 'input' ] for x in this_item [ 'exchanges' ] if x [ 'type' ] == 'production' ] [ 0 ] input_ids = [ x [ 'input' ] for x in this_item [ 'exchanges' ] if x [ 'type' ] == 'technosphere' ] production_index = get_names_index ( db [ production_id ] [ 'name' ] ) input_indexes = [ get_names_index ( db [ x ] [ 'name' ] ) for x in input_ids ] parameter_ids = [ 'n_p_{}_{}' . format ( x , production_index ) for x in input_indexes ] parameter_map_items = { ( input_ids [ n ] , k ) : parameter_ids [ n ] for n , x in enumerate ( input_ids ) } #check = [self.modelInstance.params[x]['description'] for x in parameter_ids] #print(check) #print(parameter_map_items) parameter_map . update ( parameter_map_items ) self . parameter_map = parameter_map | 6,433 | https://github.com/pjamesjoyce/lcopt/blob/3f1caca31fece4a3068a384900707e6d21d04597/lcopt/bw2_export.py#L30-L55 | [
"def",
"update_status",
"(",
"self",
",",
"new_status",
")",
":",
"timestamp",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"status_history",
"[",
"-",
"1",
"]",
"[",
"\"end\"",
"]",
"=",
"timestamp",
"self",
".",
"status_history",
".",
"append",
"(",
"{",
"\"start\"",
":",
"timestamp",
",",
"\"end\"",
":",
"None",
",",
"\"status\"",
":",
"new_status",
"}",
")"
] |
Get config file | def get_config ( override = None ) : # Set location config_path = os . path . expanduser ( '~' ) + '/.dbschema.yml' if override : config_path = override # Check if the config file exists check_exists ( config_path ) # Load config with open ( config_path ) as f : # use safe_load instead load config = yaml . safe_load ( f ) return config | 6,434 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L15-L31 | [
"def",
"cmd_oreoled",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"4",
":",
"print",
"(",
"\"Usage: oreoled LEDNUM RED GREEN BLUE <RATE>\"",
")",
"return",
"lednum",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"pattern",
"=",
"[",
"0",
"]",
"*",
"24",
"pattern",
"[",
"0",
"]",
"=",
"ord",
"(",
"'R'",
")",
"pattern",
"[",
"1",
"]",
"=",
"ord",
"(",
"'G'",
")",
"pattern",
"[",
"2",
"]",
"=",
"ord",
"(",
"'B'",
")",
"pattern",
"[",
"3",
"]",
"=",
"ord",
"(",
"'0'",
")",
"pattern",
"[",
"4",
"]",
"=",
"0",
"pattern",
"[",
"5",
"]",
"=",
"int",
"(",
"args",
"[",
"1",
"]",
")",
"pattern",
"[",
"6",
"]",
"=",
"int",
"(",
"args",
"[",
"2",
"]",
")",
"pattern",
"[",
"7",
"]",
"=",
"int",
"(",
"args",
"[",
"3",
"]",
")",
"self",
".",
"master",
".",
"mav",
".",
"led_control_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"self",
".",
"settings",
".",
"target_component",
",",
"lednum",
",",
"255",
",",
"8",
",",
"pattern",
")"
] |
Check if a file or a folder exists | def check_exists ( path , type = 'file' ) : if type == 'file' : if not os . path . isfile ( path ) : raise RuntimeError ( 'The file `%s` does not exist.' % path ) else : if not os . path . isdir ( path ) : raise RuntimeError ( 'The folder `%s` does not exist.' % path ) return True | 6,435 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L34-L44 | [
"def",
"_update_job",
"(",
"job_id",
",",
"job_dict",
")",
":",
"# Avoid SQLAlchemy \"Unicode type received non-unicode bind param value\"",
"# warnings.",
"if",
"job_id",
":",
"job_id",
"=",
"unicode",
"(",
"job_id",
")",
"if",
"\"error\"",
"in",
"job_dict",
":",
"job_dict",
"[",
"\"error\"",
"]",
"=",
"_validate_error",
"(",
"job_dict",
"[",
"\"error\"",
"]",
")",
"job_dict",
"[",
"\"error\"",
"]",
"=",
"json",
".",
"dumps",
"(",
"job_dict",
"[",
"\"error\"",
"]",
")",
"# Avoid SQLAlchemy \"Unicode type received non-unicode bind param value\"",
"# warnings.",
"job_dict",
"[",
"\"error\"",
"]",
"=",
"unicode",
"(",
"job_dict",
"[",
"\"error\"",
"]",
")",
"# Avoid SQLAlchemy \"Unicode type received non-unicode bind param value\"",
"# warnings.",
"if",
"\"data\"",
"in",
"job_dict",
":",
"job_dict",
"[",
"\"data\"",
"]",
"=",
"unicode",
"(",
"job_dict",
"[",
"\"data\"",
"]",
")",
"ENGINE",
".",
"execute",
"(",
"JOBS_TABLE",
".",
"update",
"(",
")",
".",
"where",
"(",
"JOBS_TABLE",
".",
"c",
".",
"job_id",
"==",
"job_id",
")",
".",
"values",
"(",
"*",
"*",
"job_dict",
")",
")"
] |
Returns a PostgreSQL or MySQL connection | def get_connection ( engine , host , user , port , password , database , ssl = { } ) : if engine == 'mysql' : # Connection return get_mysql_connection ( host , user , port , password , database , ssl ) elif engine == 'postgresql' : # Connection return get_pg_connection ( host , user , port , password , database , ssl ) else : raise RuntimeError ( '`%s` is not a valid engine.' % engine ) | 6,436 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L81-L91 | [
"def",
"_prepare_audio",
"(",
"self",
",",
"basename",
",",
"replace_already_indexed",
"=",
"False",
")",
":",
"if",
"basename",
"is",
"not",
"None",
":",
"if",
"basename",
"in",
"self",
".",
"get_timestamps",
"(",
")",
":",
"if",
"self",
".",
"get_verbosity",
"(",
")",
":",
"print",
"(",
"\"File specified was already indexed. Reindexing...\"",
")",
"del",
"self",
".",
"__timestamps",
"[",
"basename",
"]",
"self",
".",
"_filtering_step",
"(",
"basename",
")",
"self",
".",
"_staging_step",
"(",
"basename",
")",
"else",
":",
"for",
"audio_basename",
"in",
"self",
".",
"_list_audio_files",
"(",
")",
":",
"if",
"audio_basename",
"in",
"self",
".",
"__timestamps",
":",
"if",
"replace_already_indexed",
":",
"if",
"self",
".",
"get_verbosity",
"(",
")",
":",
"print",
"(",
"\"Already indexed {}. Reindexing...\"",
".",
"format",
"(",
"audio_basename",
")",
")",
"del",
"self",
".",
"__timestamps",
"[",
"audio_basename",
"]",
"else",
":",
"if",
"self",
".",
"get_verbosity",
"(",
")",
":",
"print",
"(",
"\"Already indexed {}. Skipping...\"",
".",
"format",
"(",
"audio_basename",
")",
")",
"continue",
"self",
".",
"_filtering_step",
"(",
"audio_basename",
")",
"self",
".",
"_staging_step",
"(",
"audio_basename",
")"
] |
Parse input and return a list of SQL statements | def parse_statements ( queries_input , engine ) : queries = [ ] query = '' sql_delimiter = ';' # Possible delimiters used in PostgreSQL functions postgres_func_delimiters = [ '$$' , '##' ] # Split input by lines lines = queries_input . strip ( ) . split ( '\n' ) for k , line in enumerate ( lines ) : # Strip line line = line . strip ( ) # Skip empty lines and comments if not line or line . startswith ( '--' ) : continue # Detect new SQL delimiter if engine == 'mysql' and line . upper ( ) . startswith ( 'DELIMITER ' ) : sql_delimiter = line . split ( ) [ 1 ] continue elif engine == 'postgresql' and [ delimiter for delimiter in postgres_func_delimiters if 'AS ' + delimiter in line . upper ( ) ] : sql_delimiter = line . split ( ) [ - 1 ] # Ensure that we leave 'AS [DELIMITER]' query += line + '\n' continue # Statement is not finished if sql_delimiter not in line and k != len ( lines ) - 1 : # Append line query += line + '\n' else : # Statement is finished # Replace non default delimiter if sql_delimiter != ';' and engine == 'mysql' and line . endswith ( sql_delimiter ) : line = line . replace ( sql_delimiter , ';' ) queries . append ( query + line ) query = '' return queries | 6,437 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L124-L169 | [
"def",
"_compute_ogg_page_crc",
"(",
"page",
")",
":",
"page_zero_crc",
"=",
"page",
"[",
":",
"OGG_FIRST_PAGE_HEADER_CRC_OFFSET",
"]",
"+",
"b\"\\00\"",
"*",
"OGG_FIRST_PAGE_HEADER_CRC",
".",
"size",
"+",
"page",
"[",
"OGG_FIRST_PAGE_HEADER_CRC_OFFSET",
"+",
"OGG_FIRST_PAGE_HEADER_CRC",
".",
"size",
":",
"]",
"return",
"ogg_page_crc",
"(",
"page_zero_crc",
")"
] |
Apply a migration to the SQL server | def run_migration ( connection , queries , engine ) : # Execute query with connection . cursor ( ) as cursorMig : # Parse statements queries = parse_statements ( queries , engine ) for query in queries : cursorMig . execute ( query ) connection . commit ( ) return True | 6,438 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L172-L184 | [
"def",
"getOverlayImageData",
"(",
"self",
",",
"ulOverlayHandle",
",",
"pvBuffer",
",",
"unBufferSize",
")",
":",
"fn",
"=",
"self",
".",
"function_table",
".",
"getOverlayImageData",
"punWidth",
"=",
"c_uint32",
"(",
")",
"punHeight",
"=",
"c_uint32",
"(",
")",
"result",
"=",
"fn",
"(",
"ulOverlayHandle",
",",
"pvBuffer",
",",
"unBufferSize",
",",
"byref",
"(",
"punWidth",
")",
",",
"byref",
"(",
"punHeight",
")",
")",
"return",
"result",
",",
"punWidth",
".",
"value",
",",
"punHeight",
".",
"value"
] |
Save a migration in migrations_applied table | def save_migration ( connection , basename ) : # Prepare query sql = "INSERT INTO migrations_applied (name, date) VALUES (%s, NOW())" # Run with connection . cursor ( ) as cursor : cursor . execute ( sql , ( basename , ) ) connection . commit ( ) return True | 6,439 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L187-L198 | [
"def",
"secret_file",
"(",
"filename",
")",
":",
"filestat",
"=",
"os",
".",
"stat",
"(",
"abspath",
"(",
"filename",
")",
")",
"if",
"stat",
".",
"S_ISREG",
"(",
"filestat",
".",
"st_mode",
")",
"==",
"0",
"and",
"stat",
".",
"S_ISLNK",
"(",
"filestat",
".",
"st_mode",
")",
"==",
"0",
":",
"e_msg",
"=",
"\"Secret file %s must be a real file or symlink\"",
"%",
"filename",
"raise",
"aomi",
".",
"exceptions",
".",
"AomiFile",
"(",
"e_msg",
")",
"if",
"platform",
".",
"system",
"(",
")",
"!=",
"\"Windows\"",
":",
"if",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IROTH",
"or",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IWOTH",
"or",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IWGRP",
":",
"e_msg",
"=",
"\"Secret file %s has too loose permissions\"",
"%",
"filename",
"raise",
"aomi",
".",
"exceptions",
".",
"AomiFile",
"(",
"e_msg",
")"
] |
Delete a migration in migrations_applied table | def delete_migration ( connection , basename ) : # Prepare query sql = "DELETE FROM migrations_applied WHERE name = %s" # Run with connection . cursor ( ) as cursor : cursor . execute ( sql , ( basename , ) ) connection . commit ( ) return True | 6,440 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L201-L212 | [
"def",
"secret_file",
"(",
"filename",
")",
":",
"filestat",
"=",
"os",
".",
"stat",
"(",
"abspath",
"(",
"filename",
")",
")",
"if",
"stat",
".",
"S_ISREG",
"(",
"filestat",
".",
"st_mode",
")",
"==",
"0",
"and",
"stat",
".",
"S_ISLNK",
"(",
"filestat",
".",
"st_mode",
")",
"==",
"0",
":",
"e_msg",
"=",
"\"Secret file %s must be a real file or symlink\"",
"%",
"filename",
"raise",
"aomi",
".",
"exceptions",
".",
"AomiFile",
"(",
"e_msg",
")",
"if",
"platform",
".",
"system",
"(",
")",
"!=",
"\"Windows\"",
":",
"if",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IROTH",
"or",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IWOTH",
"or",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IWGRP",
":",
"e_msg",
"=",
"\"Secret file %s has too loose permissions\"",
"%",
"filename",
"raise",
"aomi",
".",
"exceptions",
".",
"AomiFile",
"(",
"e_msg",
")"
] |
Get list of migrations already applied | def get_migrations_applied ( engine , connection ) : try : # Get cursor based on engine if engine == 'postgresql' : cursor = connection . cursor ( cursor_factory = psycopg2 . extras . RealDictCursor ) else : cursor = connection . cursor ( ) sql = "SELECT id, name, date FROM migrations_applied" cursor . execute ( sql ) rows = cursor . fetchall ( ) # print (rows); return rows except psycopg2 . ProgrammingError : raise RuntimeError ( 'The table `migrations_applied` is missing. Please refer to the project documentation at https://github.com/gabfl/dbschema.' ) except pymysql . err . ProgrammingError : raise RuntimeError ( 'The table `migrations_applied` is missing. Please refer to the project documentation at https://github.com/gabfl/dbschema.' ) | 6,441 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L221-L242 | [
"def",
"strace_data_access_event",
"(",
"self",
",",
"operation",
",",
"address",
",",
"data",
",",
"data_mask",
"=",
"None",
",",
"access_width",
"=",
"4",
",",
"address_range",
"=",
"0",
")",
":",
"cmd",
"=",
"enums",
".",
"JLinkStraceCommand",
".",
"TRACE_EVENT_SET",
"event_info",
"=",
"structs",
".",
"JLinkStraceEventInfo",
"(",
")",
"event_info",
".",
"Type",
"=",
"enums",
".",
"JLinkStraceEvent",
".",
"DATA_ACCESS",
"event_info",
".",
"Op",
"=",
"operation",
"event_info",
".",
"AccessSize",
"=",
"int",
"(",
"access_width",
")",
"event_info",
".",
"Addr",
"=",
"int",
"(",
"address",
")",
"event_info",
".",
"Data",
"=",
"int",
"(",
"data",
")",
"event_info",
".",
"DataMask",
"=",
"int",
"(",
"data_mask",
"or",
"0",
")",
"event_info",
".",
"AddrRangeSize",
"=",
"int",
"(",
"address_range",
")",
"handle",
"=",
"self",
".",
"_dll",
".",
"JLINK_STRACE_Control",
"(",
"cmd",
",",
"ctypes",
".",
"byref",
"(",
"event_info",
")",
")",
"if",
"handle",
"<",
"0",
":",
"raise",
"errors",
".",
"JLinkException",
"(",
"handle",
")",
"return",
"handle"
] |
Apply all migrations in a chronological order | def apply_migrations ( engine , connection , path ) : # Get migrations applied migrations_applied = get_migrations_applied ( engine , connection ) # print(migrationsApplied) # Get migrations folder for file in get_migrations_files ( path ) : # Set vars basename = os . path . basename ( os . path . dirname ( file ) ) # Skip migrations if they are already applied if is_applied ( migrations_applied , basename ) : continue # Get migration source source = get_migration_source ( file ) # print (source); # Run migration run_migration ( connection , source , engine ) # Save migration save_migration ( connection , basename ) # Log print ( ' -> Migration `%s` applied' % ( basename ) ) # Log print ( ' * Migrations applied' ) return True | 6,442 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L245-L277 | [
"def",
"genpass",
"(",
"pattern",
"=",
"r'[\\w]{32}'",
")",
":",
"try",
":",
"return",
"rstr",
".",
"xeger",
"(",
"pattern",
")",
"except",
"re",
".",
"error",
"as",
"e",
":",
"raise",
"ValueError",
"(",
"str",
"(",
"e",
")",
")"
] |
Rollback a migration | def rollback_migration ( engine , connection , path , migration_to_rollback ) : # Get migrations applied migrations_applied = get_migrations_applied ( engine , connection ) # Ensure that the migration was previously applied if not is_applied ( migrations_applied , migration_to_rollback ) : raise RuntimeError ( '`%s` is not in the list of previously applied migrations.' % ( migration_to_rollback ) ) # Rollback file file = path + migration_to_rollback + '/down.sql' # Ensure that the file exists check_exists ( file ) # Set vars basename = os . path . basename ( os . path . dirname ( file ) ) # Get migration source source = get_migration_source ( file ) # print (source); # Run migration rollback run_migration ( connection , source , engine ) # Delete migration delete_migration ( connection , basename ) # Log print ( ' -> Migration `%s` has been rolled back' % ( basename ) ) return True | 6,443 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L280-L313 | [
"def",
"getOverlayKey",
"(",
"self",
",",
"ulOverlayHandle",
",",
"pchValue",
",",
"unBufferSize",
")",
":",
"fn",
"=",
"self",
".",
"function_table",
".",
"getOverlayKey",
"pError",
"=",
"EVROverlayError",
"(",
")",
"result",
"=",
"fn",
"(",
"ulOverlayHandle",
",",
"pchValue",
",",
"unBufferSize",
",",
"byref",
"(",
"pError",
")",
")",
"return",
"result",
",",
"pError"
] |
Returns SSL options for the selected engine | def get_ssl ( database ) : # Set available keys per engine if database [ 'engine' ] == 'postgresql' : keys = [ 'sslmode' , 'sslcert' , 'sslkey' , 'sslrootcert' , 'sslcrl' , 'sslcompression' ] else : keys = [ 'ssl_ca' , 'ssl_capath' , 'ssl_cert' , 'ssl_key' , 'ssl_cipher' , 'ssl_check_hostname' ] # Loop thru keys ssl = { } for key in keys : value = database . get ( key , None ) if value is not None : ssl [ key ] = value return ssl | 6,444 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L316-L334 | [
"def",
"channel_portion",
"(",
"image",
",",
"channel",
")",
":",
"# Separate color channels",
"rgb",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"3",
")",
":",
"rgb",
".",
"append",
"(",
"image",
"[",
":",
",",
":",
",",
"i",
"]",
".",
"astype",
"(",
"int",
")",
")",
"ch",
"=",
"rgb",
".",
"pop",
"(",
"channel",
")",
"relative_values",
"=",
"ch",
"-",
"np",
".",
"sum",
"(",
"rgb",
",",
"axis",
"=",
"0",
")",
"/",
"2",
"relative_values",
"=",
"np",
".",
"maximum",
"(",
"np",
".",
"zeros",
"(",
"ch",
".",
"shape",
")",
",",
"relative_values",
")",
"return",
"float",
"(",
"np",
".",
"average",
"(",
"relative_values",
")",
"/",
"255",
")"
] |
Look thru migrations and apply them | def apply ( config_override = None , tag_override = None , rollback = None , skip_missing = None ) : # Load config config = get_config ( config_override ) databases = config [ 'databases' ] # If we are rolling back, ensure that we have a database tag if rollback and not tag_override : raise RuntimeError ( 'To rollback a migration you need to specify the database tag with `--tag`' ) for tag in sorted ( databases ) : # If a tag is specified, skip other tags if tag_override and tag_override != tag : continue # Set vars engine = databases [ tag ] . get ( 'engine' , 'mysql' ) host = databases [ tag ] . get ( 'host' , 'localhost' ) port = databases [ tag ] . get ( 'port' , 3306 ) user = databases [ tag ] [ 'user' ] password = databases [ tag ] [ 'password' ] db = databases [ tag ] [ 'db' ] path = add_slash ( databases [ tag ] [ 'path' ] ) pre_migration = databases [ tag ] . get ( 'pre_migration' , None ) post_migration = databases [ tag ] . get ( 'post_migration' , None ) # Check if the migration path exists if skip_missing : try : check_exists ( path , 'dir' ) except RuntimeError : continue else : check_exists ( path , 'dir' ) # Get database connection connection = get_connection ( engine , host , user , port , password , db , get_ssl ( databases [ tag ] ) ) # Run pre migration queries if pre_migration : run_migration ( connection , pre_migration , engine ) if rollback : print ( ' * Rolling back %s (`%s` on %s)' % ( tag , db , engine ) ) rollback_migration ( engine , connection , path , rollback ) else : print ( ' * Applying migrations for %s (`%s` on %s)' % ( tag , db , engine ) ) apply_migrations ( engine , connection , path ) # Run post migration queries if post_migration : run_migration ( connection , post_migration , engine ) return True | 6,445 | https://github.com/gabfl/dbschema/blob/37722e6654e9f0374fac5518ebdca22f4c39f92f/src/schema_change.py#L337-L396 | [
"def",
"secret_file",
"(",
"filename",
")",
":",
"filestat",
"=",
"os",
".",
"stat",
"(",
"abspath",
"(",
"filename",
")",
")",
"if",
"stat",
".",
"S_ISREG",
"(",
"filestat",
".",
"st_mode",
")",
"==",
"0",
"and",
"stat",
".",
"S_ISLNK",
"(",
"filestat",
".",
"st_mode",
")",
"==",
"0",
":",
"e_msg",
"=",
"\"Secret file %s must be a real file or symlink\"",
"%",
"filename",
"raise",
"aomi",
".",
"exceptions",
".",
"AomiFile",
"(",
"e_msg",
")",
"if",
"platform",
".",
"system",
"(",
")",
"!=",
"\"Windows\"",
":",
"if",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IROTH",
"or",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IWOTH",
"or",
"filestat",
".",
"st_mode",
"&",
"stat",
".",
"S_IWGRP",
":",
"e_msg",
"=",
"\"Secret file %s has too loose permissions\"",
"%",
"filename",
"raise",
"aomi",
".",
"exceptions",
".",
"AomiFile",
"(",
"e_msg",
")"
] |
Determine the user associated with a request using HTTP Basic Authentication . | def resolve ( self , authorization : http . Header ) : if authorization is None : return None scheme , token = authorization . split ( ) if scheme . lower ( ) != 'basic' : return None username , password = base64 . b64decode ( token ) . decode ( 'utf-8' ) . split ( ':' ) user = authenticate ( username = username , password = password ) return user | 6,446 | https://github.com/lucianoratamero/django_apistar/blob/615024680b8033aa346acd188cd542db3341064f/django_apistar/authentication/components.py#L9-L23 | [
"def",
"batchseeds",
"(",
"args",
")",
":",
"from",
"jcvi",
".",
"formats",
".",
"pdf",
"import",
"cat",
"xargs",
"=",
"args",
"[",
"1",
":",
"]",
"p",
"=",
"OptionParser",
"(",
"batchseeds",
".",
"__doc__",
")",
"opts",
",",
"args",
",",
"iopts",
"=",
"add_seeds_options",
"(",
"p",
",",
"args",
")",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
":",
"sys",
".",
"exit",
"(",
"not",
"p",
".",
"print_help",
"(",
")",
")",
"folder",
",",
"=",
"args",
"folder",
"=",
"folder",
".",
"rstrip",
"(",
"'/'",
")",
"outdir",
"=",
"folder",
"+",
"\"-debug\"",
"outfile",
"=",
"folder",
"+",
"\"-output.tsv\"",
"assert",
"op",
".",
"isdir",
"(",
"folder",
")",
"images",
"=",
"[",
"]",
"jsonfile",
"=",
"opts",
".",
"calibrate",
"or",
"op",
".",
"join",
"(",
"folder",
",",
"\"calibrate.json\"",
")",
"if",
"not",
"op",
".",
"exists",
"(",
"jsonfile",
")",
":",
"jsonfile",
"=",
"None",
"for",
"im",
"in",
"iglob",
"(",
"folder",
",",
"\"*.jpg,*.JPG,*.png\"",
")",
":",
"if",
"im",
".",
"endswith",
"(",
"(",
"\".resize.jpg\"",
",",
"\".main.jpg\"",
",",
"\".label.jpg\"",
")",
")",
":",
"continue",
"if",
"op",
".",
"basename",
"(",
"im",
")",
".",
"startswith",
"(",
"\"calibrate\"",
")",
":",
"continue",
"images",
".",
"append",
"(",
"im",
")",
"fw",
"=",
"must_open",
"(",
"outfile",
",",
"'w'",
")",
"print",
"(",
"Seed",
".",
"header",
"(",
"calibrate",
"=",
"jsonfile",
")",
",",
"file",
"=",
"fw",
")",
"nseeds",
"=",
"0",
"for",
"im",
"in",
"images",
":",
"imargs",
"=",
"[",
"im",
",",
"\"--noheader\"",
",",
"\"--outdir={0}\"",
".",
"format",
"(",
"outdir",
")",
"]",
"+",
"xargs",
"if",
"jsonfile",
":",
"imargs",
"+=",
"[",
"\"--calibrate={0}\"",
".",
"format",
"(",
"jsonfile",
")",
"]",
"objects",
"=",
"seeds",
"(",
"imargs",
")",
"for",
"o",
"in",
"objects",
":",
"print",
"(",
"o",
",",
"file",
"=",
"fw",
")",
"nseeds",
"+=",
"len",
"(",
"objects",
")",
"fw",
".",
"close",
"(",
")",
"logging",
".",
"debug",
"(",
"\"Processed {0} images.\"",
".",
"format",
"(",
"len",
"(",
"images",
")",
")",
")",
"logging",
".",
"debug",
"(",
"\"A total of {0} objects written to `{1}`.\"",
".",
"format",
"(",
"nseeds",
",",
"outfile",
")",
")",
"pdfs",
"=",
"iglob",
"(",
"outdir",
",",
"\"*.pdf\"",
")",
"outpdf",
"=",
"folder",
"+",
"\"-output.pdf\"",
"cat",
"(",
"pdfs",
"+",
"[",
"\"--outfile={0}\"",
".",
"format",
"(",
"outpdf",
")",
"]",
")",
"logging",
".",
"debug",
"(",
"\"Debugging information written to `{0}`.\"",
".",
"format",
"(",
"outpdf",
")",
")",
"return",
"outfile"
] |
Determine the user associated with a request using Token Authentication . | def resolve ( self , authorization : http . Header ) : from django_apistar . authentication . models import Token if authorization is None : return None scheme , token = authorization . split ( ) if scheme . lower ( ) != 'bearer' : return None try : user = Token . objects . get ( key = token ) . user except Token . DoesNotExist : return None return user | 6,447 | https://github.com/lucianoratamero/django_apistar/blob/615024680b8033aa346acd188cd542db3341064f/django_apistar/authentication/components.py#L27-L45 | [
"def",
"Prod",
"(",
"a",
",",
"axis",
",",
"keep_dims",
")",
":",
"return",
"np",
".",
"prod",
"(",
"a",
",",
"axis",
"=",
"axis",
"if",
"not",
"isinstance",
"(",
"axis",
",",
"np",
".",
"ndarray",
")",
"else",
"tuple",
"(",
"axis",
")",
",",
"keepdims",
"=",
"keep_dims",
")",
","
] |
Lazy event loop initialization | def loop ( self ) : if not self . _loop : self . _loop = IOLoop . current ( ) return self . _loop return self . _loop | 6,448 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/cli.py#L245-L250 | [
"def",
"unpack_rawr_zip_payload",
"(",
"table_sources",
",",
"payload",
")",
":",
"# the io we get from S3 is streaming, so we can't seek on it, but zipfile",
"# seems to require that. so we buffer it all in memory. RAWR tiles are",
"# generally up to around 100MB in size, which should be safe to store in",
"# RAM.",
"from",
"tilequeue",
".",
"query",
".",
"common",
"import",
"Table",
"from",
"io",
"import",
"BytesIO",
"zfh",
"=",
"zipfile",
".",
"ZipFile",
"(",
"BytesIO",
"(",
"payload",
")",
",",
"'r'",
")",
"def",
"get_table",
"(",
"table_name",
")",
":",
"# need to extract the whole compressed file from zip reader, as it",
"# doesn't support .tell() on the filelike, which gzip requires.",
"data",
"=",
"zfh",
".",
"open",
"(",
"table_name",
",",
"'r'",
")",
".",
"read",
"(",
")",
"unpacker",
"=",
"Unpacker",
"(",
"file_like",
"=",
"BytesIO",
"(",
"data",
")",
")",
"source",
"=",
"table_sources",
"[",
"table_name",
"]",
"return",
"Table",
"(",
"source",
",",
"unpacker",
")",
"return",
"get_table"
] |
Execute action with specified options . | def execute_action ( self , action_name , * * options ) : assert action_name in NG_ACTIONS , 'wrong action - {0}' . format ( action_name ) action = NG_ACTIONS [ action_name ] self . loop . run_sync ( lambda : action . execute ( * * options ) , timeout = self . timeout ) | 6,449 | https://github.com/cocaine/cocaine-tools/blob/d8834f8e04ca42817d5f4e368d471484d4b3419f/cocaine/tools/cli.py#L252-L263 | [
"def",
"_push_tail",
"(",
"self",
",",
"level",
",",
"parent",
",",
"tail_node",
")",
":",
"ret",
"=",
"list",
"(",
"parent",
")",
"if",
"level",
"==",
"SHIFT",
":",
"ret",
".",
"append",
"(",
"tail_node",
")",
"return",
"ret",
"sub_index",
"=",
"(",
"(",
"self",
".",
"_count",
"-",
"1",
")",
">>",
"level",
")",
"&",
"BIT_MASK",
"# >>>",
"if",
"len",
"(",
"parent",
")",
">",
"sub_index",
":",
"ret",
"[",
"sub_index",
"]",
"=",
"self",
".",
"_push_tail",
"(",
"level",
"-",
"SHIFT",
",",
"parent",
"[",
"sub_index",
"]",
",",
"tail_node",
")",
"return",
"ret",
"ret",
".",
"append",
"(",
"self",
".",
"_new_path",
"(",
"level",
"-",
"SHIFT",
",",
"tail_node",
")",
")",
"return",
"ret"
] |
max_page_size is 65000 because we output old excel . xls format | def json2excel ( items , keys , filename , page_size = 60000 ) : wb = xlwt . Workbook ( ) rowindex = 0 sheetindex = 0 for item in items : if rowindex % page_size == 0 : sheetname = "%02d" % sheetindex ws = wb . add_sheet ( sheetname ) rowindex = 0 sheetindex += 1 colindex = 0 for key in keys : ws . write ( rowindex , colindex , key ) colindex += 1 rowindex += 1 colindex = 0 for key in keys : v = item . get ( key , "" ) if type ( v ) == list : v = ',' . join ( v ) if type ( v ) == set : v = ',' . join ( v ) ws . write ( rowindex , colindex , v ) colindex += 1 rowindex += 1 logging . debug ( filename ) wb . save ( filename ) | 6,450 | https://github.com/cnschema/cdata/blob/893e2e1e27b61c8551c8b5f5f9bf05ec61490e23/cdata/table.py#L22-L53 | [
"def",
"get_fptr",
"(",
"self",
")",
":",
"cmpfunc",
"=",
"ctypes",
".",
"CFUNCTYPE",
"(",
"ctypes",
".",
"c_int",
",",
"WPARAM",
",",
"LPARAM",
",",
"ctypes",
".",
"POINTER",
"(",
"KBDLLHookStruct",
")",
")",
"return",
"cmpfunc",
"(",
"self",
".",
"handle_input",
")"
] |
old versions of models won t have produciton parameters leading to ZeroDivision errors and breaking things | def check_production_parameters_exist ( self ) : for k , v in self . modelInstance . parameter_sets . items ( ) : for p_id in self . modelInstance . production_params . keys ( ) : if v . get ( p_id ) : #print('{} already exists'.format(p_id)) pass else : #print('No production parameter called {} - setting it to 1'.format(p_id)) v [ p_id ] = 1.0 for p_id in self . modelInstance . allocation_params . keys ( ) : if v . get ( p_id ) : #print('{} already exists'.format(p_id)) pass else : #print('No production parameter called {} - setting it to 1'.format(p_id)) v [ p_id ] = 1.0 | 6,451 | https://github.com/pjamesjoyce/lcopt/blob/3f1caca31fece4a3068a384900707e6d21d04597/lcopt/parameters.py#L100-L117 | [
"def",
"merge_entities",
"(",
"self",
",",
"from_entity_ids",
",",
"to_entity_id",
",",
"force",
"=",
"False",
",",
"mount_point",
"=",
"DEFAULT_MOUNT_POINT",
")",
":",
"params",
"=",
"{",
"'from_entity_ids'",
":",
"from_entity_ids",
",",
"'to_entity_id'",
":",
"to_entity_id",
",",
"'force'",
":",
"force",
",",
"}",
"api_path",
"=",
"'/v1/{mount_point}/entity/merge'",
".",
"format",
"(",
"mount_point",
"=",
"mount_point",
")",
"return",
"self",
".",
"_adapter",
".",
"post",
"(",
"url",
"=",
"api_path",
",",
"json",
"=",
"params",
",",
")"
] |
Creates the JSON representation of a symbol | def _create_symbol ( self , id , symbolobj ) : result = { 'id' : symbolobj . name , 'isPoint' : False , 'isStroke' : False , 'isFill' : False } matcher = Mapfile . _SYMBOL_NAME_REGEXP . match ( symbolobj . name ) if matcher : result [ 'name' ] = matcher . group ( 2 ) for c in matcher . group ( 1 ) : field = Mapfile . _STYLE_CHAR2NAME [ c ] result [ field ] = True else : result [ 'name' ] = symbolobj . name result [ 'isPoint' ] = result [ 'isStroke' ] = result [ 'isFill' ] = True return result | 6,452 | https://github.com/camptocamp/Studio/blob/43cb7298434fb606b15136801b79b03571a2f27e/studio/lib/mapserializer.py#L90-L102 | [
"def",
"cdx_clamp",
"(",
"cdx_iter",
",",
"from_ts",
",",
"to_ts",
")",
":",
"if",
"from_ts",
"and",
"len",
"(",
"from_ts",
")",
"<",
"14",
":",
"from_ts",
"=",
"pad_timestamp",
"(",
"from_ts",
",",
"PAD_14_DOWN",
")",
"if",
"to_ts",
"and",
"len",
"(",
"to_ts",
")",
"<",
"14",
":",
"to_ts",
"=",
"pad_timestamp",
"(",
"to_ts",
",",
"PAD_14_UP",
")",
"for",
"cdx",
"in",
"cdx_iter",
":",
"if",
"from_ts",
"and",
"cdx",
"[",
"TIMESTAMP",
"]",
"<",
"from_ts",
":",
"continue",
"if",
"to_ts",
"and",
"cdx",
"[",
"TIMESTAMP",
"]",
">",
"to_ts",
":",
"continue",
"yield",
"cdx"
] |
Convert a unicode string with Hanyang - PUA codes to a Syllable - Initial - Peak - Final encoded unicode string . | def translate ( pua , composed = True ) : from . encoder import PUAComposedEncoder from . encoder import PUADecomposedEncoder if composed : JamoEncoder = PUAComposedEncoder else : JamoEncoder = PUADecomposedEncoder encoder = JamoEncoder ( ) return encoder . encode ( pua , final = True ) | 6,453 | https://github.com/mete0r/hypua2jamo/blob/caceb33a26c27645703d659a82bb1152deef1469/src/hypua2jamo/__init__.py#L32-L49 | [
"def",
"wait_for_compactions",
"(",
"self",
",",
"timeout",
"=",
"600",
")",
":",
"for",
"node",
"in",
"list",
"(",
"self",
".",
"nodes",
".",
"values",
"(",
")",
")",
":",
"if",
"node",
".",
"is_running",
"(",
")",
":",
"node",
".",
"wait_for_compactions",
"(",
"timeout",
")",
"return",
"self"
] |
Convert Hanyang - PUA code iterable to Syllable - Initial - Peak - Final encoded unicode string . | def codes2unicode ( codes , composed = True ) : pua = u'' . join ( unichr ( code ) for code in codes ) return translate ( pua , composed = composed ) | 6,454 | https://github.com/mete0r/hypua2jamo/blob/caceb33a26c27645703d659a82bb1152deef1469/src/hypua2jamo/__init__.py#L52-L63 | [
"def",
"make_vbox_dirs",
"(",
"max_vbox_id",
",",
"output_dir",
",",
"topology_name",
")",
":",
"if",
"max_vbox_id",
"is",
"not",
"None",
":",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"max_vbox_id",
"+",
"1",
")",
":",
"vbox_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"output_dir",
",",
"topology_name",
"+",
"'-files'",
",",
"'vbox'",
",",
"'vm-%s'",
"%",
"i",
")",
"os",
".",
"makedirs",
"(",
"vbox_dir",
")"
] |
read up to len bytes and return them or empty string on EOF | def read ( self , len = 1024 ) : return self . _with_retry ( functools . partial ( self . _read_attempt , len ) , self . gettimeout ( ) ) | 6,455 | https://github.com/teepark/greenhouse/blob/8fd1be4f5443ba090346b5ec82fdbeb0a060d956/greenhouse/io/ssl.py#L114-L118 | [
"def",
"from_dict",
"(",
"self",
",",
"document",
")",
":",
"# Get object properties from Json document",
"identifier",
"=",
"str",
"(",
"document",
"[",
"'_id'",
"]",
")",
"active",
"=",
"document",
"[",
"'active'",
"]",
"timestamp",
"=",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"document",
"[",
"'timestamp'",
"]",
",",
"'%Y-%m-%dT%H:%M:%S.%f'",
")",
"properties",
"=",
"document",
"[",
"'properties'",
"]",
"# The directory is not materilaized in database to allow moving the",
"# base directory without having to update the database.",
"directory",
"=",
"self",
".",
"get_directory",
"(",
"identifier",
")",
"# Cretae image handle",
"return",
"ImageHandle",
"(",
"identifier",
",",
"properties",
",",
"directory",
",",
"timestamp",
"=",
"timestamp",
",",
"is_active",
"=",
"active",
")"
] |
connects to the address and wraps the connection in an SSL context | def connect ( self , address ) : tout = _timeout ( self . gettimeout ( ) ) while 1 : self . _wait_event ( tout . now , write = True ) err = self . _connect ( address , tout . now ) if err in ( errno . EINPROGRESS , errno . EALREADY , errno . EWOULDBLOCK ) : continue if err : raise socket . error ( err , errno . errorcode [ err ] ) return 0 | 6,456 | https://github.com/teepark/greenhouse/blob/8fd1be4f5443ba090346b5ec82fdbeb0a060d956/greenhouse/io/ssl.py#L287-L297 | [
"def",
"delete_column",
"(",
"self",
",",
"column",
"=",
"None",
",",
"table",
"=",
"None",
",",
"verbose",
"=",
"None",
")",
":",
"PARAMS",
"=",
"set_param",
"(",
"[",
"'column'",
",",
"'table'",
"]",
",",
"[",
"column",
",",
"table",
"]",
")",
"response",
"=",
"api",
"(",
"url",
"=",
"self",
".",
"__url",
"+",
"\"/delete column\"",
",",
"PARAMS",
"=",
"PARAMS",
",",
"method",
"=",
"\"POST\"",
",",
"verbose",
"=",
"verbose",
")",
"return",
"response"
] |
accept a connection attempt from a remote client | def accept ( self ) : while 1 : try : sock , addr = self . _sock . accept ( ) return ( type ( self ) ( sock , keyfile = self . keyfile , certfile = self . certfile , server_side = True , cert_reqs = self . cert_reqs , ssl_version = self . ssl_version , ca_certs = self . ca_certs , do_handshake_on_connect = self . do_handshake_on_connect , suppress_ragged_eofs = self . suppress_ragged_eofs , ciphers = self . ciphers ) , addr ) except socket . error , exc : if exc . args [ 0 ] not in ( errno . EAGAIN , errno . EWOULDBLOCK ) : raise sys . exc_clear ( ) self . _wait_event ( self . gettimeout ( ) ) | 6,457 | https://github.com/teepark/greenhouse/blob/8fd1be4f5443ba090346b5ec82fdbeb0a060d956/greenhouse/io/ssl.py#L299-L322 | [
"def",
"_ion_equals",
"(",
"a",
",",
"b",
",",
"timestamp_comparison_func",
",",
"recursive_comparison_func",
")",
":",
"for",
"a",
",",
"b",
"in",
"(",
"(",
"a",
",",
"b",
")",
",",
"(",
"b",
",",
"a",
")",
")",
":",
"# Ensures that operand order does not matter.",
"if",
"isinstance",
"(",
"a",
",",
"_IonNature",
")",
":",
"if",
"isinstance",
"(",
"b",
",",
"_IonNature",
")",
":",
"# Both operands have _IonNature. Their IonTypes and annotations must be equivalent.",
"eq",
"=",
"a",
".",
"ion_type",
"is",
"b",
".",
"ion_type",
"and",
"_annotations_eq",
"(",
"a",
",",
"b",
")",
"else",
":",
"# Only one operand has _IonNature. It cannot be equivalent to the other operand if it has annotations.",
"eq",
"=",
"not",
"a",
".",
"ion_annotations",
"if",
"eq",
":",
"if",
"isinstance",
"(",
"a",
",",
"IonPyList",
")",
":",
"return",
"_sequences_eq",
"(",
"a",
",",
"b",
",",
"recursive_comparison_func",
")",
"elif",
"isinstance",
"(",
"a",
",",
"IonPyDict",
")",
":",
"return",
"_structs_eq",
"(",
"a",
",",
"b",
",",
"recursive_comparison_func",
")",
"elif",
"isinstance",
"(",
"a",
",",
"IonPyTimestamp",
")",
":",
"return",
"timestamp_comparison_func",
"(",
"a",
",",
"b",
")",
"elif",
"isinstance",
"(",
"a",
",",
"IonPyNull",
")",
":",
"return",
"isinstance",
"(",
"b",
",",
"IonPyNull",
")",
"or",
"(",
"b",
"is",
"None",
"and",
"a",
".",
"ion_type",
"is",
"IonType",
".",
"NULL",
")",
"elif",
"isinstance",
"(",
"a",
",",
"IonPySymbol",
")",
"or",
"(",
"isinstance",
"(",
"a",
",",
"IonPyText",
")",
"and",
"a",
".",
"ion_type",
"is",
"IonType",
".",
"SYMBOL",
")",
":",
"return",
"_symbols_eq",
"(",
"a",
",",
"b",
")",
"elif",
"isinstance",
"(",
"a",
",",
"IonPyDecimal",
")",
":",
"return",
"_decimals_eq",
"(",
"a",
",",
"b",
")",
"elif",
"isinstance",
"(",
"a",
",",
"IonPyFloat",
")",
":",
"return",
"_floats_eq",
"(",
"a",
",",
"b",
")",
"else",
":",
"return",
"a",
"==",
"b",
"return",
"False",
"# Reaching this point means that neither operand has _IonNature.",
"for",
"a",
",",
"b",
"in",
"(",
"(",
"a",
",",
"b",
")",
",",
"(",
"b",
",",
"a",
")",
")",
":",
"# Ensures that operand order does not matter.",
"if",
"isinstance",
"(",
"a",
",",
"list",
")",
":",
"return",
"_sequences_eq",
"(",
"a",
",",
"b",
",",
"recursive_comparison_func",
")",
"elif",
"isinstance",
"(",
"a",
",",
"dict",
")",
":",
"return",
"_structs_eq",
"(",
"a",
",",
"b",
",",
"recursive_comparison_func",
")",
"elif",
"isinstance",
"(",
"a",
",",
"datetime",
")",
":",
"return",
"timestamp_comparison_func",
"(",
"a",
",",
"b",
")",
"elif",
"isinstance",
"(",
"a",
",",
"SymbolToken",
")",
":",
"return",
"_symbols_eq",
"(",
"a",
",",
"b",
")",
"elif",
"isinstance",
"(",
"a",
",",
"Decimal",
")",
":",
"return",
"_decimals_eq",
"(",
"a",
",",
"b",
")",
"elif",
"isinstance",
"(",
"a",
",",
"float",
")",
":",
"return",
"_floats_eq",
"(",
"a",
",",
"b",
")",
"return",
"a",
"==",
"b"
] |
return a file - like object that operates on the ssl connection | def makefile ( self , mode = 'r' , bufsize = - 1 ) : sockfile = gsock . SocketFile . __new__ ( gsock . SocketFile ) gfiles . FileBase . __init__ ( sockfile ) sockfile . _sock = self sockfile . mode = mode if bufsize > 0 : sockfile . CHUNKSIZE = bufsize return sockfile | 6,458 | https://github.com/teepark/greenhouse/blob/8fd1be4f5443ba090346b5ec82fdbeb0a060d956/greenhouse/io/ssl.py#L324-L332 | [
"def",
"search_results_total",
"(",
"html",
",",
"xpath",
",",
"check",
",",
"delimiter",
")",
":",
"for",
"container",
"in",
"html",
".",
"findall",
"(",
"xpath",
")",
":",
"if",
"check",
"in",
"container",
".",
"findtext",
"(",
"'.'",
")",
":",
"text",
"=",
"container",
".",
"findtext",
"(",
"'.'",
")",
".",
"split",
"(",
"delimiter",
")",
"total",
"=",
"int",
"(",
"text",
"[",
"-",
"1",
"]",
".",
"strip",
"(",
")",
")",
"return",
"total"
] |
Set up language runtimes and pass control to python project script . | def run ( cont , util , shell , argv = None ) : cont . fetch_and_import ( "setup/python/setup.py" ) . run ( cont , util , shell , argv ) cmake_cont = cont . fetch_and_import ( "setup/cmake/setup.py" ) . run ( cont , util , shell , argv ) # Now that the cmake container is set up, use its execute method # to find out where cmake scripts are actually installed. # # The answer might be obvious from just using "which" on OS X and # Linux, but on Windows, the binaries are symlinked into another # directory - we need the true install location. with cont . in_temp_cache_dir ( ) : with open ( "cmroot.cmake" , "w" ) as root_script : root_script . write ( "message (${CMAKE_ROOT})" ) install_path = bytearray ( ) def steal_output ( process , outputs ) : """Steal output from container executor.""" install_path . extend ( outputs [ 1 ] . read ( ) . strip ( ) ) return process . wait ( ) cmake_cont . execute ( cont , steal_output , "cmake" , "-P" , root_script . name ) # If we're on linux, then the returned path is going to be # relative to the container, so make that explicit, since we're # not running the tests inside the container. if platform . system ( ) == "Linux" : root_fs_path_bytes = cmake_cont . root_fs_path ( ) install_path = os . path . join ( root_fs_path_bytes . decode ( "utf-8" ) , install_path . decode ( "utf-8" ) [ 1 : ] ) install_path = os . path . normpath ( install_path ) else : install_path = install_path . decode ( "utf-8" ) util . overwrite_environment_variable ( shell , "CMAKE_INSTALL_PATH" , install_path ) | 6,459 | https://github.com/polysquare/cmake-ast/blob/431a32d595d76f1f8f993eb6ddcc79effbadff9d/container-setup.py#L17-L64 | [
"def",
"stack",
"(",
"S",
")",
":",
"S",
",",
"nreps",
"=",
"zip",
"(",
"*",
"S",
")",
"S",
"=",
"np",
".",
"array",
"(",
"[",
"list",
"(",
"x",
")",
"for",
"x",
"in",
"S",
"]",
")",
"rows",
",",
"cols",
"=",
"S",
".",
"shape",
"counts",
"=",
"[",
"]",
"for",
"c",
"in",
"xrange",
"(",
"cols",
")",
":",
"freq",
"=",
"[",
"0",
"]",
"*",
"NBASES",
"for",
"b",
",",
"nrep",
"in",
"zip",
"(",
"S",
"[",
":",
",",
"c",
"]",
",",
"nreps",
")",
":",
"freq",
"[",
"BASES",
".",
"index",
"(",
"b",
")",
"]",
"+=",
"nrep",
"counts",
".",
"append",
"(",
"freq",
")",
"return",
"counts"
] |
Finds the content tag from a pattern in the provided string | def get_content ( pattern , string , tag = 'content' ) : output = [ ] for match in re . finditer ( pattern , string ) : output . append ( match . group ( tag ) ) return output | 6,460 | https://github.com/nickpandolfi/Cyther/blob/9fb0bd77af594008aa6ee8af460aa8c953abf5bc/cyther/extractor.py#L13-L20 | [
"def",
"_init_rabit",
"(",
")",
":",
"if",
"_LIB",
"is",
"not",
"None",
":",
"_LIB",
".",
"RabitGetRank",
".",
"restype",
"=",
"ctypes",
".",
"c_int",
"_LIB",
".",
"RabitGetWorldSize",
".",
"restype",
"=",
"ctypes",
".",
"c_int",
"_LIB",
".",
"RabitIsDistributed",
".",
"restype",
"=",
"ctypes",
".",
"c_int",
"_LIB",
".",
"RabitVersionNumber",
".",
"restype",
"=",
"ctypes",
".",
"c_int"
] |
Used to extract a given regex pattern from a string given several options | def extract ( pattern , string , * , assert_equal = False , one = False , condense = False , default = None , default_if_multiple = True , default_if_none = True ) : if isinstance ( pattern , str ) : output = get_content ( pattern , string ) else : # Must be a linear container output = [ ] for p in pattern : output += get_content ( p , string ) output = process_output ( output , one = one , condense = condense , default = default , default_if_multiple = default_if_multiple , default_if_none = default_if_none ) if assert_equal : assert_output ( output , assert_equal ) else : return output | 6,461 | https://github.com/nickpandolfi/Cyther/blob/9fb0bd77af594008aa6ee8af460aa8c953abf5bc/cyther/extractor.py#L23-L46 | [
"def",
"cublasGetVersion",
"(",
"handle",
")",
":",
"version",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"status",
"=",
"_libcublas",
".",
"cublasGetVersion_v2",
"(",
"handle",
",",
"ctypes",
".",
"byref",
"(",
"version",
")",
")",
"cublasCheckStatus",
"(",
"status",
")",
"return",
"version",
".",
"value"
] |
Used to find the correct static lib name to pass to gcc | def extractRuntime ( runtime_dirs ) : names = [ str ( item ) for name in runtime_dirs for item in os . listdir ( name ) ] string = '\n' . join ( names ) result = extract ( RUNTIME_PATTERN , string , condense = True ) return result | 6,462 | https://github.com/nickpandolfi/Cyther/blob/9fb0bd77af594008aa6ee8af460aa8c953abf5bc/cyther/extractor.py#L52-L59 | [
"def",
"records",
"(",
"account_id",
")",
":",
"s",
"=",
"boto3",
".",
"Session",
"(",
")",
"table",
"=",
"s",
".",
"resource",
"(",
"'dynamodb'",
")",
".",
"Table",
"(",
"'Sphere11.Dev.ResourceLocks'",
")",
"results",
"=",
"table",
".",
"scan",
"(",
")",
"for",
"r",
"in",
"results",
"[",
"'Items'",
"]",
":",
"if",
"'LockDate'",
"in",
"r",
":",
"r",
"[",
"'LockDate'",
"]",
"=",
"datetime",
".",
"fromtimestamp",
"(",
"r",
"[",
"'LockDate'",
"]",
")",
"if",
"'RevisionDate'",
"in",
"r",
":",
"r",
"[",
"'RevisionDate'",
"]",
"=",
"datetime",
".",
"fromtimestamp",
"(",
"r",
"[",
"'RevisionDate'",
"]",
")",
"print",
"(",
"tabulate",
".",
"tabulate",
"(",
"results",
"[",
"'Items'",
"]",
",",
"headers",
"=",
"\"keys\"",
",",
"tablefmt",
"=",
"'fancy_grid'",
")",
")"
] |
Extracts a three digit standard format version number | def extractVersion ( string , default = '?' ) : return extract ( VERSION_PATTERN , string , condense = True , default = default , one = True ) | 6,463 | https://github.com/nickpandolfi/Cyther/blob/9fb0bd77af594008aa6ee8af460aa8c953abf5bc/cyther/extractor.py#L87-L92 | [
"def",
"_parse_path",
"(",
"self",
",",
"path",
")",
":",
"handle",
",",
"path",
"=",
"self",
".",
"_split_path",
"(",
"path",
")",
"if",
"self",
".",
"_machine",
"is",
"not",
"None",
":",
"handle",
"=",
"self",
".",
"_connect_hive",
"(",
"handle",
")",
"return",
"handle",
",",
"path"
] |
combine a jinja template with a secret . ini file | def render_secrets ( config_path , secret_path , ) : with open ( secret_path , 'r' ) as s_fh : secret_ini = anyconfig . load ( s_fh , ac_parser = 'ini' ) with open ( config_path , 'r' ) as c_fh : raw_cfg = c_fh . read ( ) rendered_cfg = anytemplate . renders ( raw_cfg , secret_ini , at_engine = 'jinja2' ) p_config = ProsperConfig ( config_path ) local_config = configparser . ConfigParser ( ) local_config . optionxform = str local_config . read_string ( rendered_cfg ) p_config . local_config = local_config return p_config | 6,464 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_config.py#L17-L46 | [
"def",
"cudnnSetTensor4dDescriptor",
"(",
"tensorDesc",
",",
"format",
",",
"dataType",
",",
"n",
",",
"c",
",",
"h",
",",
"w",
")",
":",
"status",
"=",
"_libcudnn",
".",
"cudnnSetTensor4dDescriptor",
"(",
"tensorDesc",
",",
"format",
",",
"dataType",
",",
"n",
",",
"c",
",",
"h",
",",
"w",
")",
"cudnnCheckStatus",
"(",
"status",
")"
] |
try to figure out if value is valid or jinja2 template value | def check_value ( config , section , option , jinja_pattern = JINJA_PATTERN , ) : value = config [ section ] [ option ] if re . match ( jinja_pattern , value ) : return None return value | 6,465 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_config.py#L48-L75 | [
"def",
"get_mentions",
"(",
"self",
",",
"docs",
"=",
"None",
",",
"sort",
"=",
"False",
")",
":",
"result",
"=",
"[",
"]",
"if",
"docs",
":",
"docs",
"=",
"docs",
"if",
"isinstance",
"(",
"docs",
",",
"(",
"list",
",",
"tuple",
")",
")",
"else",
"[",
"docs",
"]",
"# Get cands from all splits",
"for",
"mention_class",
"in",
"self",
".",
"mention_classes",
":",
"mentions",
"=",
"(",
"self",
".",
"session",
".",
"query",
"(",
"mention_class",
")",
".",
"filter",
"(",
"mention_class",
".",
"document_id",
".",
"in_",
"(",
"[",
"doc",
".",
"id",
"for",
"doc",
"in",
"docs",
"]",
")",
")",
".",
"order_by",
"(",
"mention_class",
".",
"id",
")",
".",
"all",
"(",
")",
")",
"if",
"sort",
":",
"mentions",
"=",
"sorted",
"(",
"mentions",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
"[",
"0",
"]",
".",
"get_stable_id",
"(",
")",
")",
"result",
".",
"append",
"(",
"mentions",
")",
"else",
":",
"for",
"mention_class",
"in",
"self",
".",
"mention_classes",
":",
"mentions",
"=",
"(",
"self",
".",
"session",
".",
"query",
"(",
"mention_class",
")",
".",
"order_by",
"(",
"mention_class",
".",
"id",
")",
".",
"all",
"(",
")",
")",
"if",
"sort",
":",
"mentions",
"=",
"sorted",
"(",
"mentions",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
"[",
"0",
"]",
".",
"get_stable_id",
"(",
")",
")",
"result",
".",
"append",
"(",
"mentions",
")",
"return",
"result"
] |
fetch and parse config file | def read_config ( config_filepath , logger = logging . getLogger ( 'ProsperCommon' ) , ) : config_parser = configparser . ConfigParser ( interpolation = ExtendedInterpolation ( ) , allow_no_value = True , delimiters = ( '=' ) , inline_comment_prefixes = ( '#' ) ) logger . debug ( 'config_filepath=%s' , config_filepath ) with open ( config_filepath , 'r' ) as filehandle : config_parser . read_file ( filehandle ) return config_parser | 6,466 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_config.py#L265-L287 | [
"def",
"Nu_vertical_cylinder",
"(",
"Pr",
",",
"Gr",
",",
"L",
"=",
"None",
",",
"D",
"=",
"None",
",",
"Method",
"=",
"None",
",",
"AvailableMethods",
"=",
"False",
")",
":",
"def",
"list_methods",
"(",
")",
":",
"methods",
"=",
"[",
"]",
"for",
"key",
",",
"values",
"in",
"vertical_cylinder_correlations",
".",
"items",
"(",
")",
":",
"if",
"values",
"[",
"4",
"]",
"or",
"all",
"(",
"(",
"L",
",",
"D",
")",
")",
":",
"methods",
".",
"append",
"(",
"key",
")",
"if",
"'Popiel & Churchill'",
"in",
"methods",
":",
"methods",
".",
"remove",
"(",
"'Popiel & Churchill'",
")",
"methods",
".",
"insert",
"(",
"0",
",",
"'Popiel & Churchill'",
")",
"elif",
"'McAdams, Weiss & Saunders'",
"in",
"methods",
":",
"methods",
".",
"remove",
"(",
"'McAdams, Weiss & Saunders'",
")",
"methods",
".",
"insert",
"(",
"0",
",",
"'McAdams, Weiss & Saunders'",
")",
"return",
"methods",
"if",
"AvailableMethods",
":",
"return",
"list_methods",
"(",
")",
"if",
"not",
"Method",
":",
"Method",
"=",
"list_methods",
"(",
")",
"[",
"0",
"]",
"if",
"Method",
"in",
"vertical_cylinder_correlations",
":",
"if",
"vertical_cylinder_correlations",
"[",
"Method",
"]",
"[",
"4",
"]",
":",
"return",
"vertical_cylinder_correlations",
"[",
"Method",
"]",
"[",
"0",
"]",
"(",
"Pr",
"=",
"Pr",
",",
"Gr",
"=",
"Gr",
")",
"else",
":",
"return",
"vertical_cylinder_correlations",
"[",
"Method",
"]",
"[",
"0",
"]",
"(",
"Pr",
"=",
"Pr",
",",
"Gr",
"=",
"Gr",
",",
"L",
"=",
"L",
",",
"D",
"=",
"D",
")",
"else",
":",
"raise",
"Exception",
"(",
"\"Correlation name not recognized; see the \"",
"\"documentation for the available options.\"",
")"
] |
helper for finding local filepath for config | def get_local_config_filepath ( config_filepath , force_local = False , ) : local_config_name = path . basename ( config_filepath ) . split ( '.' ) [ 0 ] + '_local.cfg' local_config_filepath = path . join ( path . split ( config_filepath ) [ 0 ] , local_config_name ) real_config_filepath = '' if path . isfile ( local_config_filepath ) or force_local : #if _local.cfg version exists, use it instead real_config_filepath = local_config_filepath else : #else use tracked default real_config_filepath = config_filepath return real_config_filepath | 6,467 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_config.py#L289-L314 | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"return",
"Event",
".",
"objects",
".",
"filter",
"(",
"Q",
"(",
"startTime__gte",
"=",
"timezone",
".",
"now",
"(",
")",
"-",
"timedelta",
"(",
"days",
"=",
"90",
")",
")",
"&",
"(",
"Q",
"(",
"series__isnull",
"=",
"False",
")",
"|",
"Q",
"(",
"publicevent__isnull",
"=",
"False",
")",
")",
")",
".",
"annotate",
"(",
"count",
"=",
"Count",
"(",
"'eventregistration'",
")",
")",
".",
"annotate",
"(",
"*",
"*",
"self",
".",
"get_annotations",
"(",
")",
")",
".",
"exclude",
"(",
"Q",
"(",
"count",
"=",
"0",
")",
"&",
"Q",
"(",
"status__in",
"=",
"[",
"Event",
".",
"RegStatus",
".",
"hidden",
",",
"Event",
".",
"RegStatus",
".",
"regHidden",
",",
"Event",
".",
"RegStatus",
".",
"disabled",
"]",
")",
")"
] |
evaluates the requested option and returns the correct value | def get_option ( self , section_name , key_name , args_option = None , args_default = None , ) : if args_option != args_default and args_option is not None : self . logger . debug ( '-- using function args' ) return args_option section_info = section_name + '.' + key_name option = None try : option = check_value ( self . local_config , section_name , key_name ) self . logger . debug ( '-- using local config' ) if option : return option except ( KeyError , configparser . NoOptionError , configparser . NoSectionError ) : self . logger . debug ( '`%s` not found in local config' , section_info ) try : option = check_value ( self . global_config , section_name , key_name ) self . logger . debug ( '-- using global config' ) if option : return option except ( KeyError , configparser . NoOptionError , configparser . NoSectionError ) : self . logger . warning ( '`%s` not found in global config' , section_info ) env_option = get_value_from_environment ( section_name , key_name , logger = self . logger ) if env_option : self . logger . debug ( '-- using environment value' ) return env_option self . logger . debug ( '-- using default argument' ) return args_default | 6,468 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_config.py#L150-L207 | [
"def",
"acquire_writer",
"(",
"self",
")",
":",
"with",
"self",
".",
"mutex",
":",
"while",
"self",
".",
"rwlock",
"!=",
"0",
":",
"self",
".",
"_writer_wait",
"(",
")",
"self",
".",
"rwlock",
"=",
"-",
"1"
] |
Establish API username and password associated with APIv2 commands . | def SetCredentials ( api_username , api_passwd ) : global V2_API_USERNAME global V2_API_PASSWD global _V2_ENABLED _V2_ENABLED = True V2_API_USERNAME = api_username V2_API_PASSWD = api_passwd | 6,469 | https://github.com/CenturyLinkCloud/clc-python-sdk/blob/f4dba40c627cb08dd4b7d0d277e8d67578010b05/src/clc/APIv2/__init__.py#L46-L53 | [
"def",
"setOverlayTexelAspect",
"(",
"self",
",",
"ulOverlayHandle",
",",
"fTexelAspect",
")",
":",
"fn",
"=",
"self",
".",
"function_table",
".",
"setOverlayTexelAspect",
"result",
"=",
"fn",
"(",
"ulOverlayHandle",
",",
"fTexelAspect",
")",
"return",
"result"
] |
Start a session with the given parameters | def get_session ( username , password , default_endpoints = clc . defaults , cert = None ) : if cert is None : cert = API . _ResourcePath ( 'clc/cacert.pem' ) session = requests . Session ( ) request = session . request ( "POST" , "{}/v2/authentication/login" . format ( default_endpoints . ENDPOINT_URL_V2 ) , data = { "username" : username , "password" : password } , verify = cert ) data = request . json ( ) if request . status_code == 200 : token = data [ 'bearerToken' ] alias = data [ 'accountAlias' ] location = data [ 'locationAlias' ] elif request . status_code == 400 : raise Exception ( "Invalid V2 API login. {}" . format ( data [ 'message' ] ) ) else : raise Exception ( "Error logging into V2 API. Response code {}. message {}" . format ( request . status_code , data [ 'message' ] ) ) return { 'username' : username , 'password' : password , 'http_session' : session , 'token' : token , 'alias' : alias , 'location' : location } | 6,470 | https://github.com/CenturyLinkCloud/clc-python-sdk/blob/f4dba40c627cb08dd4b7d0d277e8d67578010b05/src/clc/APIv2/__init__.py#L56-L91 | [
"def",
"getOverlayTransformAbsolute",
"(",
"self",
",",
"ulOverlayHandle",
")",
":",
"fn",
"=",
"self",
".",
"function_table",
".",
"getOverlayTransformAbsolute",
"peTrackingOrigin",
"=",
"ETrackingUniverseOrigin",
"(",
")",
"pmatTrackingOriginToOverlayTransform",
"=",
"HmdMatrix34_t",
"(",
")",
"result",
"=",
"fn",
"(",
"ulOverlayHandle",
",",
"byref",
"(",
"peTrackingOrigin",
")",
",",
"byref",
"(",
"pmatTrackingOriginToOverlayTransform",
")",
")",
"return",
"result",
",",
"peTrackingOrigin",
",",
"pmatTrackingOriginToOverlayTransform"
] |
Set the property identifier | def set_id ( self , pid ) : if self . type == 'KAF' : return self . node . set ( 'pid' , pid ) elif self . type == 'NAF' : return self . node . set ( 'id' , pid ) | 6,471 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/features_data.py#L47-L56 | [
"def",
"_get_container_dirs",
"(",
"source_dir",
",",
"manifest_dir",
")",
":",
"base",
"=",
"\"/tmp/samcli\"",
"result",
"=",
"{",
"\"source_dir\"",
":",
"\"{}/source\"",
".",
"format",
"(",
"base",
")",
",",
"\"artifacts_dir\"",
":",
"\"{}/artifacts\"",
".",
"format",
"(",
"base",
")",
",",
"\"scratch_dir\"",
":",
"\"{}/scratch\"",
".",
"format",
"(",
"base",
")",
",",
"\"manifest_dir\"",
":",
"\"{}/manifest\"",
".",
"format",
"(",
"base",
")",
"}",
"if",
"pathlib",
".",
"PurePath",
"(",
"source_dir",
")",
"==",
"pathlib",
".",
"PurePath",
"(",
"manifest_dir",
")",
":",
"# It is possible that the manifest resides within the source. In that case, we won't mount the manifest",
"# directory separately.",
"result",
"[",
"\"manifest_dir\"",
"]",
"=",
"result",
"[",
"\"source_dir\"",
"]",
"return",
"result"
] |
Converts the element to NAF | def to_kaf ( self ) : if self . type == 'NAF' : ##convert all the properties for node in self . node . findall ( 'properties/property' ) : node . set ( 'pid' , node . get ( 'id' ) ) del node . attrib [ 'id' ] | 6,472 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/features_data.py#L187-L195 | [
"def",
"_get_license_description",
"(",
"license_code",
")",
":",
"req",
"=",
"requests",
".",
"get",
"(",
"\"{base_url}/licenses/{license_code}\"",
".",
"format",
"(",
"base_url",
"=",
"BASE_URL",
",",
"license_code",
"=",
"license_code",
")",
",",
"headers",
"=",
"_HEADERS",
")",
"if",
"req",
".",
"status_code",
"==",
"requests",
".",
"codes",
".",
"ok",
":",
"s",
"=",
"req",
".",
"json",
"(",
")",
"[",
"\"body\"",
"]",
"search_curly",
"=",
"re",
".",
"search",
"(",
"r'\\{(.*)\\}'",
",",
"s",
")",
"search_square",
"=",
"re",
".",
"search",
"(",
"r'\\[(.*)\\]'",
",",
"s",
")",
"license",
"=",
"\"\"",
"replace_string",
"=",
"'{year} {name}'",
".",
"format",
"(",
"year",
"=",
"date",
".",
"today",
"(",
")",
".",
"year",
",",
"name",
"=",
"_get_config_name",
"(",
")",
")",
"if",
"search_curly",
":",
"license",
"=",
"re",
".",
"sub",
"(",
"r'\\{(.+)\\}'",
",",
"replace_string",
",",
"s",
")",
"elif",
"search_square",
":",
"license",
"=",
"re",
".",
"sub",
"(",
"r'\\[(.+)\\]'",
",",
"replace_string",
",",
"s",
")",
"else",
":",
"license",
"=",
"s",
"return",
"license",
"else",
":",
"print",
"(",
"Fore",
".",
"RED",
"+",
"'No such license. Please check again.'",
")",
",",
"print",
"(",
"Style",
".",
"RESET_ALL",
")",
",",
"sys",
".",
"exit",
"(",
")"
] |
Converts the element to KAF | def to_naf ( self ) : if self . type == 'KAF' : ##convert all the properties for node in self . node . findall ( 'properties/property' ) : node . set ( 'id' , node . get ( 'pid' ) ) del node . attrib [ 'pid' ] | 6,473 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/features_data.py#L197-L205 | [
"def",
"sync_blockchain",
"(",
"working_dir",
",",
"bt_opts",
",",
"last_block",
",",
"server_state",
",",
"expected_snapshots",
"=",
"{",
"}",
",",
"*",
"*",
"virtualchain_args",
")",
":",
"subdomain_index",
"=",
"server_state",
"[",
"'subdomains'",
"]",
"atlas_state",
"=",
"server_state",
"[",
"'atlas'",
"]",
"# make this usable even if we haven't explicitly configured virtualchain ",
"impl",
"=",
"sys",
".",
"modules",
"[",
"__name__",
"]",
"log",
".",
"info",
"(",
"\"Synchronizing database {} up to block {}\"",
".",
"format",
"(",
"working_dir",
",",
"last_block",
")",
")",
"# NOTE: this is the only place where a read-write handle should be created,",
"# since this is the only place where the db should be modified.",
"new_db",
"=",
"BlockstackDB",
".",
"borrow_readwrite_instance",
"(",
"working_dir",
",",
"last_block",
",",
"expected_snapshots",
"=",
"expected_snapshots",
")",
"# propagate runtime state to virtualchain callbacks",
"new_db",
".",
"subdomain_index",
"=",
"subdomain_index",
"new_db",
".",
"atlas_state",
"=",
"atlas_state",
"rc",
"=",
"virtualchain",
".",
"sync_virtualchain",
"(",
"bt_opts",
",",
"last_block",
",",
"new_db",
",",
"expected_snapshots",
"=",
"expected_snapshots",
",",
"*",
"*",
"virtualchain_args",
")",
"BlockstackDB",
".",
"release_readwrite_instance",
"(",
"new_db",
",",
"last_block",
")",
"return",
"rc"
] |
Iterator that returns all the properties of the layuer | def get_properties ( self ) : node_prop = self . node . find ( 'properties' ) if node_prop is not None : obj_properties = Cproperties ( node_prop , self . type ) for prop in obj_properties : yield prop | 6,474 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/features_data.py#L227-L237 | [
"def",
"_adapt_WSDateTime",
"(",
"dt",
")",
":",
"try",
":",
"ts",
"=",
"int",
"(",
"(",
"dt",
".",
"replace",
"(",
"tzinfo",
"=",
"pytz",
".",
"utc",
")",
"-",
"datetime",
"(",
"1970",
",",
"1",
",",
"1",
",",
"tzinfo",
"=",
"pytz",
".",
"utc",
")",
")",
".",
"total_seconds",
"(",
")",
")",
"except",
"(",
"OverflowError",
",",
"OSError",
")",
":",
"if",
"dt",
"<",
"datetime",
".",
"now",
"(",
")",
":",
"ts",
"=",
"0",
"else",
":",
"ts",
"=",
"2",
"**",
"63",
"-",
"1",
"return",
"ts"
] |
Removes the property layer if exists | def remove_properties ( self ) : node_prop = self . node . find ( 'properties' ) if node_prop is not None : self . node . remove ( node_prop ) | 6,475 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/features_data.py#L240-L246 | [
"def",
"_read_config",
"(",
"config_location",
")",
":",
"global",
"LOGGING_CONFIG",
"with",
"open",
"(",
"config_location",
",",
"\"r\"",
")",
"as",
"config_loc",
":",
"cfg_file",
"=",
"json",
".",
"load",
"(",
"config_loc",
")",
"if",
"\"logging\"",
"in",
"cfg_file",
":",
"log_dict",
"=",
"cfg_file",
".",
"get",
"(",
"\"logging\"",
")",
"with",
"open",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"join",
"(",
"__file__",
",",
"os",
".",
"path",
".",
"pardir",
",",
"'logging_schema.json'",
")",
")",
")",
"as",
"schema_file",
":",
"logging_schema",
"=",
"json",
".",
"load",
"(",
"schema_file",
")",
"jsonschema",
".",
"validate",
"(",
"log_dict",
",",
"logging_schema",
")",
"merged",
"=",
"jsonmerge",
".",
"merge",
"(",
"LOGGING_CONFIG",
",",
"log_dict",
")",
"LOGGING_CONFIG",
"=",
"merged"
] |
Returns the term identifier | def get_id ( self ) : if self . type == 'NAF' : return self . node . get ( 'id' ) elif self . type == 'KAF' : return self . node . get ( 'mid' ) | 6,476 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/markable_data.py#L39-L48 | [
"def",
"create_experiment",
"(",
"args",
")",
":",
"config_file_name",
"=",
"''",
".",
"join",
"(",
"random",
".",
"sample",
"(",
"string",
".",
"ascii_letters",
"+",
"string",
".",
"digits",
",",
"8",
")",
")",
"nni_config",
"=",
"Config",
"(",
"config_file_name",
")",
"config_path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"args",
".",
"config",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"config_path",
")",
":",
"print_error",
"(",
"'Please set correct config path!'",
")",
"exit",
"(",
"1",
")",
"experiment_config",
"=",
"get_yml_content",
"(",
"config_path",
")",
"validate_all_content",
"(",
"experiment_config",
",",
"config_path",
")",
"nni_config",
".",
"set_config",
"(",
"'experimentConfig'",
",",
"experiment_config",
")",
"launch_experiment",
"(",
"args",
",",
"experiment_config",
",",
"'new'",
",",
"config_file_name",
")",
"nni_config",
".",
"set_config",
"(",
"'restServerPort'",
",",
"args",
".",
"port",
")"
] |
Sets the identifier for the term | def set_id ( self , i ) : if self . type == 'NAF' : self . node . set ( 'id' , i ) elif self . type == 'KAF' : self . node . set ( 'mid' , i ) | 6,477 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/markable_data.py#L50-L59 | [
"def",
"_recv",
"(",
"self",
")",
":",
"recvd",
"=",
"[",
"]",
"self",
".",
"_lock",
".",
"acquire",
"(",
")",
"if",
"not",
"self",
".",
"_can_send_recv",
"(",
")",
":",
"log",
".",
"warning",
"(",
"'%s cannot recv: socket not connected'",
",",
"self",
")",
"self",
".",
"_lock",
".",
"release",
"(",
")",
"return",
"(",
")",
"while",
"len",
"(",
"recvd",
")",
"<",
"self",
".",
"config",
"[",
"'sock_chunk_buffer_count'",
"]",
":",
"try",
":",
"data",
"=",
"self",
".",
"_sock",
".",
"recv",
"(",
"self",
".",
"config",
"[",
"'sock_chunk_bytes'",
"]",
")",
"# We expect socket.recv to raise an exception if there are no",
"# bytes available to read from the socket in non-blocking mode.",
"# but if the socket is disconnected, we will get empty data",
"# without an exception raised",
"if",
"not",
"data",
":",
"log",
".",
"error",
"(",
"'%s: socket disconnected'",
",",
"self",
")",
"self",
".",
"_lock",
".",
"release",
"(",
")",
"self",
".",
"close",
"(",
"error",
"=",
"Errors",
".",
"KafkaConnectionError",
"(",
"'socket disconnected'",
")",
")",
"return",
"[",
"]",
"else",
":",
"recvd",
".",
"append",
"(",
"data",
")",
"except",
"SSLWantReadError",
":",
"break",
"except",
"ConnectionError",
"as",
"e",
":",
"if",
"six",
".",
"PY2",
"and",
"e",
".",
"errno",
"==",
"errno",
".",
"EWOULDBLOCK",
":",
"break",
"log",
".",
"exception",
"(",
"'%s: Error receiving network data'",
"' closing socket'",
",",
"self",
")",
"self",
".",
"_lock",
".",
"release",
"(",
")",
"self",
".",
"close",
"(",
"error",
"=",
"Errors",
".",
"KafkaConnectionError",
"(",
"e",
")",
")",
"return",
"[",
"]",
"except",
"BlockingIOError",
":",
"if",
"six",
".",
"PY3",
":",
"break",
"self",
".",
"_lock",
".",
"release",
"(",
")",
"raise",
"recvd_data",
"=",
"b''",
".",
"join",
"(",
"recvd",
")",
"if",
"self",
".",
"_sensors",
":",
"self",
".",
"_sensors",
".",
"bytes_received",
".",
"record",
"(",
"len",
"(",
"recvd_data",
")",
")",
"try",
":",
"responses",
"=",
"self",
".",
"_protocol",
".",
"receive_bytes",
"(",
"recvd_data",
")",
"except",
"Errors",
".",
"KafkaProtocolError",
"as",
"e",
":",
"self",
".",
"_lock",
".",
"release",
"(",
")",
"self",
".",
"close",
"(",
"e",
")",
"return",
"[",
"]",
"else",
":",
"self",
".",
"_lock",
".",
"release",
"(",
")",
"return",
"responses"
] |
Adds an external reference object to the markable | def add_external_reference ( self , ext_ref ) : ext_refs_node = self . node . find ( 'externalReferences' ) if ext_refs_node is None : ext_refs_obj = CexternalReferences ( ) self . node . append ( ext_refs_obj . get_node ( ) ) else : ext_refs_obj = CexternalReferences ( ext_refs_node ) ext_refs_obj . add_external_reference ( ext_ref ) | 6,478 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/markable_data.py#L116-L129 | [
"def",
"subvolume_sync",
"(",
"path",
",",
"subvolids",
"=",
"None",
",",
"sleep",
"=",
"None",
")",
":",
"if",
"subvolids",
"and",
"type",
"(",
"subvolids",
")",
"is",
"not",
"list",
":",
"raise",
"CommandExecutionError",
"(",
"'Subvolids parameter must be a list'",
")",
"cmd",
"=",
"[",
"'btrfs'",
",",
"'subvolume'",
",",
"'sync'",
"]",
"if",
"sleep",
":",
"cmd",
".",
"extend",
"(",
"[",
"'-s'",
",",
"sleep",
"]",
")",
"cmd",
".",
"append",
"(",
"path",
")",
"if",
"subvolids",
":",
"cmd",
".",
"extend",
"(",
"subvolids",
")",
"res",
"=",
"__salt__",
"[",
"'cmd.run_all'",
"]",
"(",
"cmd",
")",
"salt",
".",
"utils",
".",
"fsutils",
".",
"_verify_run",
"(",
"res",
")",
"return",
"True"
] |
Iterator that returns all the external references of the markable | def get_external_references ( self ) : for ext_ref_node in self . node . findall ( 'externalReferences' ) : ext_refs_obj = CexternalReferences ( ext_ref_node ) for ref in ext_refs_obj : yield ref | 6,479 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/markable_data.py#L132-L141 | [
"def",
"config_diff",
"(",
"args",
")",
":",
"config_1",
"=",
"config_get",
"(",
"args",
")",
".",
"splitlines",
"(",
")",
"args",
".",
"project",
"=",
"args",
".",
"Project",
"args",
".",
"workspace",
"=",
"args",
".",
"Workspace",
"cfg_1_name",
"=",
"args",
".",
"config",
"if",
"args",
".",
"Config",
"is",
"not",
"None",
":",
"args",
".",
"config",
"=",
"args",
".",
"Config",
"if",
"args",
".",
"Namespace",
"is",
"not",
"None",
":",
"args",
".",
"namespace",
"=",
"args",
".",
"Namespace",
"config_2",
"=",
"config_get",
"(",
"args",
")",
".",
"splitlines",
"(",
")",
"if",
"not",
"args",
".",
"verbose",
":",
"config_1",
"=",
"skip_cfg_ver",
"(",
"config_1",
")",
"config_2",
"=",
"skip_cfg_ver",
"(",
"config_2",
")",
"return",
"list",
"(",
"unified_diff",
"(",
"config_1",
",",
"config_2",
",",
"cfg_1_name",
",",
"args",
".",
"config",
",",
"lineterm",
"=",
"''",
")",
")"
] |
Adds an external reference for the given markable | def add_external_reference ( self , markable_id , external_ref ) : if markable_id in self . idx : markable_obj = Cterm ( self . idx [ markable_id ] , self . type ) markable_obj . add_external_reference ( external_ref ) else : print ( '{markable_id} not in self.idx' . format ( * * locals ( ) ) ) | 6,480 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/markable_data.py#L247-L259 | [
"def",
"config_diff",
"(",
"args",
")",
":",
"config_1",
"=",
"config_get",
"(",
"args",
")",
".",
"splitlines",
"(",
")",
"args",
".",
"project",
"=",
"args",
".",
"Project",
"args",
".",
"workspace",
"=",
"args",
".",
"Workspace",
"cfg_1_name",
"=",
"args",
".",
"config",
"if",
"args",
".",
"Config",
"is",
"not",
"None",
":",
"args",
".",
"config",
"=",
"args",
".",
"Config",
"if",
"args",
".",
"Namespace",
"is",
"not",
"None",
":",
"args",
".",
"namespace",
"=",
"args",
".",
"Namespace",
"config_2",
"=",
"config_get",
"(",
"args",
")",
".",
"splitlines",
"(",
")",
"if",
"not",
"args",
".",
"verbose",
":",
"config_1",
"=",
"skip_cfg_ver",
"(",
"config_1",
")",
"config_2",
"=",
"skip_cfg_ver",
"(",
"config_2",
")",
"return",
"list",
"(",
"unified_diff",
"(",
"config_1",
",",
"config_2",
",",
"cfg_1_name",
",",
"args",
".",
"config",
",",
"lineterm",
"=",
"''",
")",
")"
] |
Removes a list of markables from the layer | def remove_markables ( self , list_mark_ids ) : nodes_to_remove = set ( ) for markable in self : if markable . get_id ( ) in list_mark_ids : nodes_to_remove . add ( markable . get_node ( ) ) #For removing the previous comment prv = markable . get_node ( ) . getprevious ( ) if prv is not None : nodes_to_remove . add ( prv ) for node in nodes_to_remove : self . node . remove ( node ) | 6,481 | https://github.com/cltl/KafNafParserPy/blob/9bc32e803c176404b255ba317479b8780ed5f569/KafNafParserPy/markable_data.py#L261-L277 | [
"def",
"ValidateEndConfig",
"(",
"self",
",",
"config_obj",
",",
"errors_fatal",
"=",
"True",
")",
":",
"errors",
"=",
"super",
"(",
"WindowsClientRepacker",
",",
"self",
")",
".",
"ValidateEndConfig",
"(",
"config_obj",
",",
"errors_fatal",
"=",
"errors_fatal",
")",
"install_dir",
"=",
"config_obj",
"[",
"\"Client.install_path\"",
"]",
"for",
"path",
"in",
"config_obj",
"[",
"\"Client.tempdir_roots\"",
"]",
":",
"if",
"path",
".",
"startswith",
"(",
"\"/\"",
")",
":",
"errors",
".",
"append",
"(",
"\"Client.tempdir_root %s starts with /, probably has Unix path.\"",
"%",
"path",
")",
"if",
"not",
"path",
".",
"startswith",
"(",
"install_dir",
")",
":",
"errors",
".",
"append",
"(",
"\"Client.tempdir_root %s is not inside the install_dir %s, this is \"",
"\"a security risk\"",
"%",
"(",
"(",
"path",
",",
"install_dir",
")",
")",
")",
"if",
"config_obj",
".",
"Get",
"(",
"\"Logging.path\"",
")",
".",
"startswith",
"(",
"\"/\"",
")",
":",
"errors",
".",
"append",
"(",
"\"Logging.path starts with /, probably has Unix path. %s\"",
"%",
"config_obj",
"[",
"\"Logging.path\"",
"]",
")",
"if",
"\"Windows\\\\\"",
"in",
"config_obj",
".",
"GetRaw",
"(",
"\"Logging.path\"",
")",
":",
"errors",
".",
"append",
"(",
"\"Windows in Logging.path, you probably want \"",
"\"%(WINDIR|env) instead\"",
")",
"if",
"not",
"config_obj",
"[",
"\"Client.binary_name\"",
"]",
".",
"endswith",
"(",
"\".exe\"",
")",
":",
"errors",
".",
"append",
"(",
"\"Missing .exe extension on binary_name %s\"",
"%",
"config_obj",
"[",
"\"Client.binary_name\"",
"]",
")",
"if",
"not",
"config_obj",
"[",
"\"Nanny.binary\"",
"]",
".",
"endswith",
"(",
"\".exe\"",
")",
":",
"errors",
".",
"append",
"(",
"\"Missing .exe extension on nanny_binary\"",
")",
"if",
"errors_fatal",
"and",
"errors",
":",
"for",
"error",
"in",
"errors",
":",
"logging",
".",
"error",
"(",
"\"Build Config Error: %s\"",
",",
"error",
")",
"raise",
"RuntimeError",
"(",
"\"Bad configuration generated. Terminating.\"",
")",
"else",
":",
"return",
"errors"
] |
Make an exponential back off getInfo call on an Earth Engine object | def getinfo ( ee_obj , n = 4 ) : output = None for i in range ( 1 , n ) : try : output = ee_obj . getInfo ( ) except ee . ee_exception . EEException as e : if 'Earth Engine memory capacity exceeded' in str ( e ) : logging . info ( ' Resending query ({}/10)' . format ( i ) ) logging . debug ( ' {}' . format ( e ) ) sleep ( i ** 2 ) else : raise e if output : break # output = ee_obj.getInfo() return output | 6,482 | https://github.com/Open-ET/openet-core-beta/blob/f2b81ccf87bf7e7fe1b9f3dd1d4081d0ec7852db/openet/core/utils.py#L9-L27 | [
"def",
"compare_values",
"(",
"values0",
",",
"values1",
")",
":",
"values0",
"=",
"{",
"v",
"[",
"0",
"]",
":",
"v",
"[",
"1",
":",
"]",
"for",
"v",
"in",
"values0",
"}",
"values1",
"=",
"{",
"v",
"[",
"0",
"]",
":",
"v",
"[",
"1",
":",
"]",
"for",
"v",
"in",
"values1",
"}",
"created",
"=",
"[",
"(",
"k",
",",
"v",
"[",
"0",
"]",
",",
"v",
"[",
"1",
"]",
")",
"for",
"k",
",",
"v",
"in",
"values1",
".",
"items",
"(",
")",
"if",
"k",
"not",
"in",
"values0",
"]",
"deleted",
"=",
"[",
"(",
"k",
",",
"v",
"[",
"0",
"]",
",",
"v",
"[",
"1",
"]",
")",
"for",
"k",
",",
"v",
"in",
"values0",
".",
"items",
"(",
")",
"if",
"k",
"not",
"in",
"values1",
"]",
"modified",
"=",
"[",
"(",
"k",
",",
"v",
"[",
"0",
"]",
",",
"v",
"[",
"1",
"]",
")",
"for",
"k",
",",
"v",
"in",
"values0",
".",
"items",
"(",
")",
"if",
"v",
"!=",
"values1",
".",
"get",
"(",
"k",
",",
"None",
")",
"]",
"return",
"created",
",",
"deleted",
",",
"modified"
] |
Extract the output value from a calculation done with constant images | def constant_image_value ( image , crs = 'EPSG:32613' , scale = 1 ) : return getinfo ( ee . Image ( image ) . reduceRegion ( reducer = ee . Reducer . first ( ) , scale = scale , geometry = ee . Geometry . Rectangle ( [ 0 , 0 , 10 , 10 ] , crs , False ) ) ) | 6,483 | https://github.com/Open-ET/openet-core-beta/blob/f2b81ccf87bf7e7fe1b9f3dd1d4081d0ec7852db/openet/core/utils.py#L33-L37 | [
"def",
"get_index",
"(",
"self",
",",
"index",
",",
"type",
",",
"alias",
"=",
"None",
",",
"typed",
"=",
"None",
",",
"read_only",
"=",
"True",
",",
"kwargs",
"=",
"None",
")",
":",
"if",
"kwargs",
".",
"tjson",
"!=",
"None",
":",
"Log",
".",
"error",
"(",
"\"used `typed` parameter, not `tjson`\"",
")",
"if",
"read_only",
":",
"# GET EXACT MATCH, OR ALIAS",
"aliases",
"=",
"wrap",
"(",
"self",
".",
"get_aliases",
"(",
")",
")",
"if",
"index",
"in",
"aliases",
".",
"index",
":",
"pass",
"elif",
"index",
"in",
"aliases",
".",
"alias",
":",
"match",
"=",
"[",
"a",
"for",
"a",
"in",
"aliases",
"if",
"a",
".",
"alias",
"==",
"index",
"]",
"[",
"0",
"]",
"kwargs",
".",
"alias",
"=",
"match",
".",
"alias",
"kwargs",
".",
"index",
"=",
"match",
".",
"index",
"else",
":",
"Log",
".",
"error",
"(",
"\"Can not find index {{index_name}}\"",
",",
"index_name",
"=",
"kwargs",
".",
"index",
")",
"return",
"Index",
"(",
"kwargs",
"=",
"kwargs",
",",
"cluster",
"=",
"self",
")",
"else",
":",
"# GET BEST MATCH, INCLUDING PROTOTYPE",
"best",
"=",
"self",
".",
"get_best_matching_index",
"(",
"index",
",",
"alias",
")",
"if",
"not",
"best",
":",
"Log",
".",
"error",
"(",
"\"Can not find index {{index_name}}\"",
",",
"index_name",
"=",
"kwargs",
".",
"index",
")",
"if",
"best",
".",
"alias",
"!=",
"None",
":",
"kwargs",
".",
"alias",
"=",
"best",
".",
"alias",
"kwargs",
".",
"index",
"=",
"best",
".",
"index",
"elif",
"kwargs",
".",
"alias",
"==",
"None",
":",
"kwargs",
".",
"alias",
"=",
"kwargs",
".",
"index",
"kwargs",
".",
"index",
"=",
"best",
".",
"index",
"return",
"Index",
"(",
"kwargs",
"=",
"kwargs",
",",
"cluster",
"=",
"self",
")"
] |
Get the 0 UTC date for a date | def date_0utc ( date ) : return ee . Date . fromYMD ( date . get ( 'year' ) , date . get ( 'month' ) , date . get ( 'day' ) ) | 6,484 | https://github.com/Open-ET/openet-core-beta/blob/f2b81ccf87bf7e7fe1b9f3dd1d4081d0ec7852db/openet/core/utils.py#L82-L95 | [
"def",
"_unregister_bundle_factories",
"(",
"self",
",",
"bundle",
")",
":",
"# type: (Bundle) -> None",
"with",
"self",
".",
"__factories_lock",
":",
"# Find out which factories must be removed",
"to_remove",
"=",
"[",
"factory_name",
"for",
"factory_name",
"in",
"self",
".",
"__factories",
"if",
"self",
".",
"get_factory_bundle",
"(",
"factory_name",
")",
"is",
"bundle",
"]",
"# Remove all of them",
"for",
"factory_name",
"in",
"to_remove",
":",
"try",
":",
"self",
".",
"unregister_factory",
"(",
"factory_name",
")",
"except",
"ValueError",
"as",
"ex",
":",
"_logger",
".",
"warning",
"(",
"\"Error unregistering factory '%s': %s\"",
",",
"factory_name",
",",
"ex",
")"
] |
tries to resolve version number | def get_version ( here_path , default_version = DEFAULT_VERSION , ) : if 'site-packages' in here_path : # Running as dependency return _version_from_file ( here_path ) if os . environ . get ( 'TRAVIS_TAG' ) : # Running on Travis-CI: trumps all if not TEST_MODE : # pragma: no cover return os . environ . get ( 'TRAVIS_TAG' ) . replace ( 'v' , '' ) else : warnings . warn ( 'Travis detected, but TEST_MODE enabled' , exceptions . ProsperVersionTestModeWarning ) try : current_tag = _read_git_tags ( default_version = default_version ) except Exception : # pragma: no cover return _version_from_file ( here_path ) # TODO: if #steps from tag root, increment minor # TODO: check if off main branch and add name to prerelease with open ( os . path . join ( here_path , 'version.txt' ) , 'w' ) as v_fh : # save version info somewhere static v_fh . write ( current_tag ) return current_tag | 6,485 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_version.py#L18-L57 | [
"def",
"min_or",
"(",
"a",
",",
"b",
",",
"c",
",",
"d",
",",
"w",
")",
":",
"m",
"=",
"(",
"1",
"<<",
"(",
"w",
"-",
"1",
")",
")",
"while",
"m",
"!=",
"0",
":",
"if",
"(",
"(",
"~",
"a",
")",
"&",
"c",
"&",
"m",
")",
"!=",
"0",
":",
"temp",
"=",
"(",
"a",
"|",
"m",
")",
"&",
"-",
"m",
"if",
"temp",
"<=",
"b",
":",
"a",
"=",
"temp",
"break",
"elif",
"(",
"a",
"&",
"(",
"~",
"c",
")",
"&",
"m",
")",
"!=",
"0",
":",
"temp",
"=",
"(",
"c",
"|",
"m",
")",
"&",
"-",
"m",
"if",
"temp",
"<=",
"d",
":",
"c",
"=",
"temp",
"break",
"m",
">>=",
"1",
"return",
"a",
"|",
"c"
] |
tries to find current git tag | def _read_git_tags ( default_version = DEFAULT_VERSION , git_command = ( 'git' , 'tag' ) , ) : try : current_tags = check_output ( git_command ) . splitlines ( ) except Exception : # pragma: no cover raise if not current_tags [ 0 ] : warnings . warn ( 'Unable to resolve current version' , exceptions . ProsperDefaultVersionWarning ) return default_version latest_version = semantic_version . Version ( default_version ) for tag in current_tags : tag_str = decode ( tag , 'utf-8' ) . replace ( 'v' , '' ) try : tag_ver = semantic_version . Version ( tag_str ) except Exception : # pragma: no cover continue # invalid tags ok, but no release if tag_ver > latest_version : latest_version = tag_ver return str ( latest_version ) | 6,486 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_version.py#L59-L101 | [
"def",
"register",
"(",
"cls",
",",
"encryptor",
":",
"Encryptor",
")",
":",
"# save the current encryptor statically",
"cls",
".",
"__encryptor__",
"=",
"encryptor",
"# NB: we cannot use the before_insert listener in conjunction with a foreign key relationship",
"# for encrypted data; SQLAlchemy will warn about using 'related attribute set' operation so",
"# late in its insert/flush process.",
"listeners",
"=",
"dict",
"(",
"init",
"=",
"on_init",
",",
"load",
"=",
"on_load",
",",
")",
"for",
"name",
",",
"func",
"in",
"listeners",
".",
"items",
"(",
")",
":",
"# If we initialize the graph multiple times (as in many unit testing scenarios),",
"# we will accumulate listener functions -- with unpredictable results. As protection,",
"# we need to remove existing listeners before adding new ones; this solution only",
"# works if the id (e.g. memory address) of the listener does not change, which means",
"# they cannot be closures around the `encryptor` reference.",
"#",
"# Hence the `__encryptor__` hack above...",
"if",
"contains",
"(",
"cls",
",",
"name",
",",
"func",
")",
":",
"remove",
"(",
"cls",
",",
"name",
",",
"func",
")",
"listen",
"(",
"cls",
",",
"name",
",",
"func",
")"
] |
for PyPI installed versions just get data from file | def _version_from_file ( path_to_version , default_version = DEFAULT_VERSION , ) : version_filepath = os . path . join ( path_to_version , 'version.txt' ) if not os . path . isfile ( version_filepath ) : warnings . warn ( 'Unable to resolve current version' , exceptions . ProsperDefaultVersionWarning ) return default_version with open ( version_filepath , 'r' ) as v_fh : data = v_fh . read ( ) return data | 6,487 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_version.py#L103-L127 | [
"def",
"user_deleted_from_site_event",
"(",
"event",
")",
":",
"userid",
"=",
"event",
".",
"principal",
"catalog",
"=",
"api",
".",
"portal",
".",
"get_tool",
"(",
"'portal_catalog'",
")",
"query",
"=",
"{",
"'object_provides'",
":",
"WORKSPACE_INTERFACE",
"}",
"query",
"[",
"'workspace_members'",
"]",
"=",
"userid",
"workspaces",
"=",
"[",
"IWorkspace",
"(",
"b",
".",
"_unrestrictedGetObject",
"(",
")",
")",
"for",
"b",
"in",
"catalog",
".",
"unrestrictedSearchResults",
"(",
"query",
")",
"]",
"for",
"workspace",
"in",
"workspaces",
":",
"workspace",
".",
"remove_from_team",
"(",
"userid",
")"
] |
commom configuration code | def _configure_common ( self , prefix , fallback_level , fallback_format , handler_name , handler , custom_args = '' ) : ## Retrieve settings from config ## log_level = self . config . get_option ( 'LOGGING' , prefix + 'log_level' , None , fallback_level ) log_format_name = self . config . get_option ( 'LOGGING' , prefix + 'log_format' , None , None ) log_format = ReportingFormats [ log_format_name ] . value if log_format_name else fallback_format log_format = log_format . format ( custom_args = custom_args ) # should work even if no {custom_args} ## Attach handlers/formatter ## formatter = logging . Formatter ( log_format ) handler . setFormatter ( formatter ) handler . setLevel ( log_level ) self . logger . addHandler ( handler ) if not self . logger . isEnabledFor ( logging . getLevelName ( log_level ) ) : # make sure logger level is not lower than handler level self . logger . setLevel ( log_level ) ## Save info about handler created ## self . log_info . append ( handler_name + ' @ ' + str ( log_level ) ) self . log_handlers . append ( handler ) | 6,488 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L126-L168 | [
"def",
"move_vobject",
"(",
"self",
",",
"uid",
",",
"from_file",
",",
"to_file",
")",
":",
"if",
"from_file",
"not",
"in",
"self",
".",
"_reminders",
"or",
"to_file",
"not",
"in",
"self",
".",
"_reminders",
":",
"return",
"uid",
"=",
"uid",
".",
"split",
"(",
"'@'",
")",
"[",
"0",
"]",
"with",
"self",
".",
"_lock",
":",
"rem",
"=",
"open",
"(",
"from_file",
")",
".",
"readlines",
"(",
")",
"for",
"(",
"index",
",",
"line",
")",
"in",
"enumerate",
"(",
"rem",
")",
":",
"if",
"uid",
"==",
"md5",
"(",
"line",
"[",
":",
"-",
"1",
"]",
".",
"encode",
"(",
"'utf-8'",
")",
")",
".",
"hexdigest",
"(",
")",
":",
"del",
"rem",
"[",
"index",
"]",
"open",
"(",
"from_file",
",",
"'w'",
")",
".",
"writelines",
"(",
"rem",
")",
"open",
"(",
"to_file",
",",
"'a'",
")",
".",
"write",
"(",
"line",
")",
"break"
] |
default logger that every Prosper script should use!! | def configure_default_logger ( self , log_freq = 'midnight' , log_total = 30 , log_level = 'INFO' , log_format = ReportingFormats . DEFAULT . value , custom_args = '' ) : ## Override defaults if required ## log_freq = self . config . get_option ( 'LOGGING' , 'log_freq' , None , log_freq ) log_total = self . config . get_option ( 'LOGGING' , 'log_total' , None , log_total ) ## Set up log file handles/name ## log_filename = self . log_name + '.log' log_abspath = path . join ( self . log_path , log_filename ) general_handler = TimedRotatingFileHandler ( log_abspath , when = log_freq , interval = 1 , backupCount = int ( log_total ) ) self . _configure_common ( '' , log_level , log_format , 'default' , general_handler , custom_args = custom_args ) | 6,489 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L170-L215 | [
"def",
"fetched_records",
"(",
"self",
",",
"max_records",
"=",
"None",
")",
":",
"if",
"max_records",
"is",
"None",
":",
"max_records",
"=",
"self",
".",
"config",
"[",
"'max_poll_records'",
"]",
"assert",
"max_records",
">",
"0",
"drained",
"=",
"collections",
".",
"defaultdict",
"(",
"list",
")",
"records_remaining",
"=",
"max_records",
"while",
"records_remaining",
">",
"0",
":",
"if",
"not",
"self",
".",
"_next_partition_records",
":",
"if",
"not",
"self",
".",
"_completed_fetches",
":",
"break",
"completion",
"=",
"self",
".",
"_completed_fetches",
".",
"popleft",
"(",
")",
"self",
".",
"_next_partition_records",
"=",
"self",
".",
"_parse_fetched_data",
"(",
"completion",
")",
"else",
":",
"records_remaining",
"-=",
"self",
".",
"_append",
"(",
"drained",
",",
"self",
".",
"_next_partition_records",
",",
"records_remaining",
")",
"return",
"dict",
"(",
"drained",
")",
",",
"bool",
"(",
"self",
".",
"_completed_fetches",
")"
] |
logger for sending messages to Discord . Easy way to alert humans of issues | def configure_discord_logger ( self , discord_webhook = None , discord_recipient = None , log_level = 'ERROR' , log_format = ReportingFormats . PRETTY_PRINT . value , custom_args = '' ) : # Override defaults if required # discord_webhook = self . config . get_option ( 'LOGGING' , 'discord_webhook' , None , discord_webhook ) discord_recipient = self . config . get_option ( 'LOGGING' , 'discord_recipient' , None , discord_recipient ) log_level = self . config . get_option ( 'LOGGING' , 'discord_level' , None , log_level ) # Actually build discord logging handler # discord_obj = DiscordWebhook ( ) discord_obj . webhook ( discord_webhook ) # vv TODO vv: Test review # if discord_obj . can_query : discord_handler = HackyDiscordHandler ( discord_obj , discord_recipient ) self . _configure_common ( 'discord_' , log_level , log_format , 'Discord' , discord_handler , custom_args = custom_args ) else : warnings . warn ( 'Unable to execute webhook' , exceptions . WebhookCreateFailed ) | 6,490 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L243-L302 | [
"def",
"generate_citation_counter",
"(",
"self",
")",
":",
"cite_counter",
"=",
"dict",
"(",
")",
"filename",
"=",
"'%s.aux'",
"%",
"self",
".",
"project_name",
"with",
"open",
"(",
"filename",
")",
"as",
"fobj",
":",
"main_aux",
"=",
"fobj",
".",
"read",
"(",
")",
"cite_counter",
"[",
"filename",
"]",
"=",
"_count_citations",
"(",
"filename",
")",
"for",
"match",
"in",
"re",
".",
"finditer",
"(",
"r'\\\\@input\\{(.*.aux)\\}'",
",",
"main_aux",
")",
":",
"filename",
"=",
"match",
".",
"groups",
"(",
")",
"[",
"0",
"]",
"try",
":",
"counter",
"=",
"_count_citations",
"(",
"filename",
")",
"except",
"IOError",
":",
"pass",
"else",
":",
"cite_counter",
"[",
"filename",
"]",
"=",
"counter",
"return",
"cite_counter"
] |
logger for sending messages to Slack . Easy way to alert humans of issues | def configure_slack_logger ( self , slack_webhook = None , log_level = 'ERROR' , log_format = ReportingFormats . SLACK_PRINT . value , custom_args = '' ) : # Override defaults if required # slack_webhook = self . config . get_option ( 'LOGGING' , 'slack_webhook' , None , slack_webhook ) log_level = self . config . get_option ( 'LOGGING' , 'slack_level' , None , log_level ) # Actually build slack logging handler # # vv TODO vv: Test review # slack_handler = HackySlackHandler ( slack_webhook ) self . _configure_common ( 'slack_' , log_level , log_format , 'Slack' , slack_handler , custom_args = custom_args ) | 6,491 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L305-L347 | [
"def",
"generate_citation_counter",
"(",
"self",
")",
":",
"cite_counter",
"=",
"dict",
"(",
")",
"filename",
"=",
"'%s.aux'",
"%",
"self",
".",
"project_name",
"with",
"open",
"(",
"filename",
")",
"as",
"fobj",
":",
"main_aux",
"=",
"fobj",
".",
"read",
"(",
")",
"cite_counter",
"[",
"filename",
"]",
"=",
"_count_citations",
"(",
"filename",
")",
"for",
"match",
"in",
"re",
".",
"finditer",
"(",
"r'\\\\@input\\{(.*.aux)\\}'",
",",
"main_aux",
")",
":",
"filename",
"=",
"match",
".",
"groups",
"(",
")",
"[",
"0",
"]",
"try",
":",
"counter",
"=",
"_count_citations",
"(",
"filename",
")",
"except",
"IOError",
":",
"pass",
"else",
":",
"cite_counter",
"[",
"filename",
"]",
"=",
"counter",
"return",
"cite_counter"
] |
logger for sending messages to HipChat . Easy way to alert humans of issues | def configure_hipchat_logger ( self , hipchat_webhook = None , log_level = 'ERROR' , log_format = ReportingFormats . PRETTY_PRINT . value , custom_args = '' ) : # Override defaults if required # hipchat_webhook = self . config . get_option ( 'LOGGING' , 'hipchat_webhook' , None , hipchat_webhook ) log_level = self . config . get_option ( 'LOGGING' , 'hipchat_level' , None , log_level ) # Actually build HipChat logging handler # # vv TODO vv: Test review # try : hipchat_handler = HackyHipChatHandler ( hipchat_webhook ) self . _configure_common ( 'hipchat_' , log_level , log_format , 'HipChat' , hipchat_handler , custom_args = custom_args ) except Exception as error_msg : raise error_msg | 6,492 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L350-L395 | [
"def",
"update",
"(",
"self",
",",
"other",
")",
":",
"self",
".",
"update_ttl",
"(",
"other",
".",
"ttl",
")",
"super",
"(",
"Rdataset",
",",
"self",
")",
".",
"update",
"(",
"other",
")"
] |
Load object with webhook_url | def webhook ( self , webhook_url ) : if not webhook_url : raise Exception ( 'Url can not be None' ) matcher = re . match ( self . __webhook_url_format , webhook_url ) if not matcher : raise Exception ( 'Invalid url format, looking for: ' + self . __webhook_url_format ) self . api_keys ( int ( matcher . group ( 1 ) ) , matcher . group ( 2 ) ) | 6,493 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L472-L486 | [
"def",
"calc_stats",
"(",
"prices",
")",
":",
"if",
"isinstance",
"(",
"prices",
",",
"pd",
".",
"Series",
")",
":",
"return",
"PerformanceStats",
"(",
"prices",
")",
"elif",
"isinstance",
"(",
"prices",
",",
"pd",
".",
"DataFrame",
")",
":",
"return",
"GroupStats",
"(",
"*",
"[",
"prices",
"[",
"x",
"]",
"for",
"x",
"in",
"prices",
".",
"columns",
"]",
")",
"else",
":",
"raise",
"NotImplementedError",
"(",
"'Unsupported type'",
")"
] |
required classmethod for logging to execute logging message | def emit ( self , record ) : # pragma: no cover if record . exc_text : record . exc_text = '```python\n{0}\n```' . format ( record . exc_text ) # recast to code block log_msg = self . format ( record ) if len ( log_msg ) + self . alert_length > DISCORD_MESSAGE_LIMIT : log_msg = log_msg [ : ( DISCORD_MESSAGE_LIMIT - DISCORD_PAD_SIZE ) ] if self . alert_recipient and record . levelno == logging . CRITICAL : log_msg = log_msg + '\n' + str ( self . alert_recipient ) self . send_msg_to_webhook ( log_msg ) | 6,494 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L546-L557 | [
"def",
"as_cross",
"(",
"self",
",",
"delimiter",
"=",
"''",
")",
":",
"if",
"self",
".",
"order",
">",
"usd_order",
":",
"return",
"'USD%s%s'",
"%",
"(",
"delimiter",
",",
"self",
".",
"code",
")",
"else",
":",
"return",
"'%s%sUSD'",
"%",
"(",
"self",
".",
"code",
",",
"delimiter",
")"
] |
separated Requests logic for easier testing | def send_msg_to_webhook ( self , message ) : payload = { 'content' : message } header = { 'Content-Type' : 'application/json' } try : request = requests . post ( self . api_url , headers = header , json = payload ) request . raise_for_status ( ) except Exception as error_msg : #pragma: no cover warning_msg = ( 'EXCEPTION: UNABLE TO COMMIT LOG MESSAGE' + '\n\texception={0}' . format ( repr ( error_msg ) ) + '\n\tmessage={0}' . format ( message ) ) warnings . warn ( warning_msg , exceptions . WebhookFailedEmitWarning ) | 6,495 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L559-L592 | [
"def",
"getOverlayImageData",
"(",
"self",
",",
"ulOverlayHandle",
",",
"pvBuffer",
",",
"unBufferSize",
")",
":",
"fn",
"=",
"self",
".",
"function_table",
".",
"getOverlayImageData",
"punWidth",
"=",
"c_uint32",
"(",
")",
"punHeight",
"=",
"c_uint32",
"(",
")",
"result",
"=",
"fn",
"(",
"ulOverlayHandle",
",",
"pvBuffer",
",",
"unBufferSize",
",",
"byref",
"(",
"punWidth",
")",
",",
"byref",
"(",
"punHeight",
")",
")",
"return",
"result",
",",
"punWidth",
".",
"value",
",",
"punHeight",
".",
"value"
] |
add slack - specific flourishes to responses | def decorate ( self , record ) : attachments = { } ## Set color if record . levelno >= logging . ERROR : attachments [ 'color' ] = 'warning' #builtin if record . levelno >= logging . CRITICAL : attachments [ 'color' ] = 'danger' #builtin ## Log text attach_text = '{levelname}: {name} {module}.{funcName}:{lineno}' . format ( levelname = record . levelname , name = record . name , module = record . module , funcName = record . funcName , lineno = record . lineno ) attachments [ 'text' ] = attach_text attachments [ 'fallback' ] = attach_text return attachments | 6,496 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L616-L645 | [
"def",
"_GetImportTimestamps",
"(",
"self",
",",
"pefile_object",
")",
":",
"import_timestamps",
"=",
"[",
"]",
"if",
"not",
"hasattr",
"(",
"pefile_object",
",",
"'DIRECTORY_ENTRY_IMPORT'",
")",
":",
"return",
"import_timestamps",
"for",
"importdata",
"in",
"pefile_object",
".",
"DIRECTORY_ENTRY_IMPORT",
":",
"dll_name",
"=",
"getattr",
"(",
"importdata",
",",
"'dll'",
",",
"''",
")",
"try",
":",
"dll_name",
"=",
"dll_name",
".",
"decode",
"(",
"'ascii'",
")",
"except",
"UnicodeDecodeError",
":",
"dll_name",
"=",
"dll_name",
".",
"decode",
"(",
"'ascii'",
",",
"errors",
"=",
"'replace'",
")",
"if",
"not",
"dll_name",
":",
"dll_name",
"=",
"'<NO DLL NAME>'",
"timestamp",
"=",
"getattr",
"(",
"importdata",
".",
"struct",
",",
"'TimeDateStamp'",
",",
"0",
")",
"if",
"timestamp",
":",
"import_timestamps",
".",
"append",
"(",
"[",
"dll_name",
",",
"timestamp",
"]",
")",
"return",
"import_timestamps"
] |
push message out to webhook | def send_msg_to_webhook ( self , json_payload , log_msg ) : if SILENCE_OVERRIDE : # pragma: no cover return payload = { 'text' : log_msg , 'attachments' : [ json_payload ] } header = { 'Content-Type' : 'application/json' } try : request = requests . post ( self . webhook_url , headers = header , json = payload ) request . raise_for_status ( ) except Exception as error_msg : #pragma: no cover warning_msg = ( 'EXCEPTION: UNABLE TO COMMIT LOG MESSAGE' + '\n\texception={0}' . format ( repr ( error_msg ) ) + '\n\tmessage={0}' . format ( log_msg ) ) warnings . warn ( warning_msg , exceptions . WebhookFailedEmitWarning ) | 6,497 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L647-L682 | [
"def",
"fromtif",
"(",
"path",
",",
"ext",
"=",
"'tif'",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
",",
"recursive",
"=",
"False",
",",
"nplanes",
"=",
"None",
",",
"npartitions",
"=",
"None",
",",
"labels",
"=",
"None",
",",
"engine",
"=",
"None",
",",
"credentials",
"=",
"None",
",",
"discard_extra",
"=",
"False",
")",
":",
"from",
"tifffile",
"import",
"TiffFile",
"if",
"nplanes",
"is",
"not",
"None",
"and",
"nplanes",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"'nplanes must be positive if passed, got %d'",
"%",
"nplanes",
")",
"def",
"getarray",
"(",
"idx_buffer_filename",
")",
":",
"idx",
",",
"buf",
",",
"fname",
"=",
"idx_buffer_filename",
"fbuf",
"=",
"BytesIO",
"(",
"buf",
")",
"tfh",
"=",
"TiffFile",
"(",
"fbuf",
")",
"ary",
"=",
"tfh",
".",
"asarray",
"(",
")",
"pageCount",
"=",
"ary",
".",
"shape",
"[",
"0",
"]",
"if",
"nplanes",
"is",
"not",
"None",
":",
"extra",
"=",
"pageCount",
"%",
"nplanes",
"if",
"extra",
":",
"if",
"discard_extra",
":",
"pageCount",
"=",
"pageCount",
"-",
"extra",
"logging",
".",
"getLogger",
"(",
"'thunder'",
")",
".",
"warn",
"(",
"'Ignored %d pages in file %s'",
"%",
"(",
"extra",
",",
"fname",
")",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"nplanes '%d' does not evenly divide '%d in file %s'\"",
"%",
"(",
"nplanes",
",",
"pageCount",
",",
"fname",
")",
")",
"values",
"=",
"[",
"ary",
"[",
"i",
":",
"(",
"i",
"+",
"nplanes",
")",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"pageCount",
",",
"nplanes",
")",
"]",
"else",
":",
"values",
"=",
"[",
"ary",
"]",
"tfh",
".",
"close",
"(",
")",
"if",
"ary",
".",
"ndim",
"==",
"3",
":",
"values",
"=",
"[",
"val",
".",
"squeeze",
"(",
")",
"for",
"val",
"in",
"values",
"]",
"nvals",
"=",
"len",
"(",
"values",
")",
"keys",
"=",
"[",
"(",
"idx",
"*",
"nvals",
"+",
"timepoint",
",",
")",
"for",
"timepoint",
"in",
"range",
"(",
"nvals",
")",
"]",
"return",
"zip",
"(",
"keys",
",",
"values",
")",
"recount",
"=",
"False",
"if",
"nplanes",
"is",
"None",
"else",
"True",
"data",
"=",
"frompath",
"(",
"path",
",",
"accessor",
"=",
"getarray",
",",
"ext",
"=",
"ext",
",",
"start",
"=",
"start",
",",
"stop",
"=",
"stop",
",",
"recursive",
"=",
"recursive",
",",
"npartitions",
"=",
"npartitions",
",",
"recount",
"=",
"recount",
",",
"labels",
"=",
"labels",
",",
"engine",
"=",
"engine",
",",
"credentials",
"=",
"credentials",
")",
"if",
"engine",
"is",
"not",
"None",
"and",
"npartitions",
"is",
"not",
"None",
"and",
"data",
".",
"npartitions",
"(",
")",
"<",
"npartitions",
":",
"data",
"=",
"data",
".",
"repartition",
"(",
"npartitions",
")",
"return",
"data"
] |
Build up HipChat specific values for log record | def decorate ( self , record ) : color = 'gray' if record . levelno == logging . WARNING : color = 'yellow' if record . levelno == logging . INFO : color = 'green' if record . levelno == logging . DEBUG : color = 'gray' if record . levelno >= logging . ERROR : color = 'red' notify = False if record . levelno >= logging . ERROR : nofiy = True payload = { 'color' : color , 'notify' : notify , 'message_format' : 'text' } return payload | 6,498 | https://github.com/EVEprosper/ProsperCommon/blob/bcada3b25420099e1f204db8d55eb268e7b4dc27/prosper/common/prosper_logging.py#L691-L721 | [
"def",
"do_watch",
"(",
"self",
",",
"*",
"args",
")",
":",
"tables",
"=",
"[",
"]",
"if",
"not",
"self",
".",
"engine",
".",
"cached_descriptions",
":",
"self",
".",
"engine",
".",
"describe_all",
"(",
")",
"all_tables",
"=",
"list",
"(",
"self",
".",
"engine",
".",
"cached_descriptions",
")",
"for",
"arg",
"in",
"args",
":",
"candidates",
"=",
"set",
"(",
"(",
"t",
"for",
"t",
"in",
"all_tables",
"if",
"fnmatch",
"(",
"t",
",",
"arg",
")",
")",
")",
"for",
"t",
"in",
"sorted",
"(",
"candidates",
")",
":",
"if",
"t",
"not",
"in",
"tables",
":",
"tables",
".",
"append",
"(",
"t",
")",
"mon",
"=",
"Monitor",
"(",
"self",
".",
"engine",
",",
"tables",
")",
"mon",
".",
"start",
"(",
")"
] |
Gets the list of Networks mapped to the account in the specified datacenter . | def GetNetworks ( alias = None , location = None ) : if alias is None : alias = clc . v1 . Account . GetAlias ( ) if location is None : location = clc . v1 . Account . GetLocation ( ) r = clc . v1 . API . Call ( 'post' , 'Network/GetAccountNetworks' , { 'AccountAlias' : alias , 'Location' : location } ) if int ( r [ 'StatusCode' ] ) == 0 : return ( r [ 'Networks' ] ) | 6,499 | https://github.com/CenturyLinkCloud/clc-python-sdk/blob/f4dba40c627cb08dd4b7d0d277e8d67578010b05/src/clc/APIv1/network.py#L15-L26 | [
"def",
"generate",
"(",
"self",
")",
":",
"try",
":",
"model",
"=",
"self",
".",
"schema",
"(",
")",
".",
"model",
"(",
")",
"except",
"AttributeError",
":",
"return",
"os",
".",
"urandom",
"(",
"self",
".",
"__bits",
")",
".",
"encode",
"(",
"'hex'",
")",
"else",
":",
"while",
"True",
":",
"token",
"=",
"os",
".",
"urandom",
"(",
"self",
".",
"__bits",
")",
".",
"encode",
"(",
"'hex'",
")",
"if",
"model",
".",
"select",
"(",
"where",
"=",
"orb",
".",
"Query",
"(",
"self",
")",
"==",
"token",
")",
".",
"count",
"(",
")",
"==",
"0",
":",
"return",
"token"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.