repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
holtjma/msbwt | MUS/MultiStringBWT.py | mergeNewSeqs | def mergeNewSeqs(seqArray, mergedDir, numProcs, areUniform, logger):
'''
This function takes a series of sequences and creates a big BWT by merging the smaller ones
Mostly a test function, no real purpose to the tool as of now
@param seqArray - a list of '$'-terminated strings to be placed into the arr... | python | def mergeNewSeqs(seqArray, mergedDir, numProcs, areUniform, logger):
'''
This function takes a series of sequences and creates a big BWT by merging the smaller ones
Mostly a test function, no real purpose to the tool as of now
@param seqArray - a list of '$'-terminated strings to be placed into the arr... | [
"def",
"mergeNewSeqs",
"(",
"seqArray",
",",
"mergedDir",
",",
"numProcs",
",",
"areUniform",
",",
"logger",
")",
":",
"#first wipe away any traces of old information for the case of overwriting a BWT at mergedFN",
"MSBWTGen",
".",
"clearAuxiliaryData",
"(",
"mergedDir",
")",... | This function takes a series of sequences and creates a big BWT by merging the smaller ones
Mostly a test function, no real purpose to the tool as of now
@param seqArray - a list of '$'-terminated strings to be placed into the array
@param mergedFN - the final destination filename for the merged BWT
@p... | [
"This",
"function",
"takes",
"a",
"series",
"of",
"sequences",
"and",
"creates",
"a",
"big",
"BWT",
"by",
"merging",
"the",
"smaller",
"ones",
"Mostly",
"a",
"test",
"function",
"no",
"real",
"purpose",
"to",
"the",
"tool",
"as",
"of",
"now"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L1088-L1126 | train | 61,400 |
holtjma/msbwt | MUS/MultiStringBWT.py | compareKmerProfiles | def compareKmerProfiles(profileFN1, profileFN2):
'''
This function takes two kmer profiles and compare them for similarity.
@param profileFN1 - the first kmer-profile to compare to
@param profileFN2 - the second kmer-profile to compare to
@return - a tuple of the form (1-norm, 2-norm, sum of differe... | python | def compareKmerProfiles(profileFN1, profileFN2):
'''
This function takes two kmer profiles and compare them for similarity.
@param profileFN1 - the first kmer-profile to compare to
@param profileFN2 - the second kmer-profile to compare to
@return - a tuple of the form (1-norm, 2-norm, sum of differe... | [
"def",
"compareKmerProfiles",
"(",
"profileFN1",
",",
"profileFN2",
")",
":",
"fp1",
"=",
"open",
"(",
"profileFN1",
",",
"'r'",
")",
"fp2",
"=",
"open",
"(",
"profileFN2",
",",
"'r'",
")",
"oneNorm",
"=",
"0",
"twoNorm",
"=",
"0",
"sumDeltas",
"=",
"0... | This function takes two kmer profiles and compare them for similarity.
@param profileFN1 - the first kmer-profile to compare to
@param profileFN2 - the second kmer-profile to compare to
@return - a tuple of the form (1-norm, 2-norm, sum of differences, normalized Dot product) | [
"This",
"function",
"takes",
"two",
"kmer",
"profiles",
"and",
"compare",
"them",
"for",
"similarity",
"."
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L1128-L1175 | train | 61,401 |
holtjma/msbwt | MUS/MultiStringBWT.py | parseProfileLine | def parseProfileLine(fp):
'''
Helper function for profile parsing
@param fp - the file pointer to get the next line from
@return - (kmer, kmerCount) as (string, int)
'''
nextLine = fp.readline()
if nextLine == None or nextLine == '':
return (None, None)
else:
pieces = nex... | python | def parseProfileLine(fp):
'''
Helper function for profile parsing
@param fp - the file pointer to get the next line from
@return - (kmer, kmerCount) as (string, int)
'''
nextLine = fp.readline()
if nextLine == None or nextLine == '':
return (None, None)
else:
pieces = nex... | [
"def",
"parseProfileLine",
"(",
"fp",
")",
":",
"nextLine",
"=",
"fp",
".",
"readline",
"(",
")",
"if",
"nextLine",
"==",
"None",
"or",
"nextLine",
"==",
"''",
":",
"return",
"(",
"None",
",",
"None",
")",
"else",
":",
"pieces",
"=",
"nextLine",
".",... | Helper function for profile parsing
@param fp - the file pointer to get the next line from
@return - (kmer, kmerCount) as (string, int) | [
"Helper",
"function",
"for",
"profile",
"parsing"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L1177-L1188 | train | 61,402 |
holtjma/msbwt | MUS/MultiStringBWT.py | reverseComplement | def reverseComplement(seq):
'''
Helper function for generating reverse-complements
'''
revComp = ''
complement = {'A':'T', 'C':'G', 'G':'C', 'T':'A', 'N':'N', '$':'$'}
for c in reversed(seq):
revComp += complement[c]
return revComp | python | def reverseComplement(seq):
'''
Helper function for generating reverse-complements
'''
revComp = ''
complement = {'A':'T', 'C':'G', 'G':'C', 'T':'A', 'N':'N', '$':'$'}
for c in reversed(seq):
revComp += complement[c]
return revComp | [
"def",
"reverseComplement",
"(",
"seq",
")",
":",
"revComp",
"=",
"''",
"complement",
"=",
"{",
"'A'",
":",
"'T'",
",",
"'C'",
":",
"'G'",
",",
"'G'",
":",
"'C'",
",",
"'T'",
":",
"'A'",
",",
"'N'",
":",
"'N'",
",",
"'$'",
":",
"'$'",
"}",
"for... | Helper function for generating reverse-complements | [
"Helper",
"function",
"for",
"generating",
"reverse",
"-",
"complements"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L1408-L1416 | train | 61,403 |
holtjma/msbwt | MUS/MultiStringBWT.py | BasicBWT.countOccurrencesOfSeq | def countOccurrencesOfSeq(self, seq, givenRange=None):
'''
This function counts the number of occurrences of the given sequence
@param seq - the sequence to search for
@param givenRange - the range to start from (if a partial search has already been run), default=whole range
@ret... | python | def countOccurrencesOfSeq(self, seq, givenRange=None):
'''
This function counts the number of occurrences of the given sequence
@param seq - the sequence to search for
@param givenRange - the range to start from (if a partial search has already been run), default=whole range
@ret... | [
"def",
"countOccurrencesOfSeq",
"(",
"self",
",",
"seq",
",",
"givenRange",
"=",
"None",
")",
":",
"#init the current range",
"if",
"givenRange",
"==",
"None",
":",
"if",
"not",
"self",
".",
"searchCache",
".",
"has_key",
"(",
"seq",
"[",
"-",
"self",
".",... | This function counts the number of occurrences of the given sequence
@param seq - the sequence to search for
@param givenRange - the range to start from (if a partial search has already been run), default=whole range
@return - an integer count of the number of times seq occurred in this BWT | [
"This",
"function",
"counts",
"the",
"number",
"of",
"occurrences",
"of",
"the",
"given",
"sequence"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L79-L112 | train | 61,404 |
holtjma/msbwt | MUS/MultiStringBWT.py | BasicBWT.recoverString | def recoverString(self, strIndex, withIndex=False):
'''
This will return the string that starts at the given index
@param strIndex - the index of the string we want to recover
@return - string that we found starting at the specified '$' index
'''
retNums = []
indi... | python | def recoverString(self, strIndex, withIndex=False):
'''
This will return the string that starts at the given index
@param strIndex - the index of the string we want to recover
@return - string that we found starting at the specified '$' index
'''
retNums = []
indi... | [
"def",
"recoverString",
"(",
"self",
",",
"strIndex",
",",
"withIndex",
"=",
"False",
")",
":",
"retNums",
"=",
"[",
"]",
"indices",
"=",
"[",
"]",
"#figure out the first hop backwards",
"currIndex",
"=",
"strIndex",
"prevChar",
"=",
"self",
".",
"getCharAtInd... | This will return the string that starts at the given index
@param strIndex - the index of the string we want to recover
@return - string that we found starting at the specified '$' index | [
"This",
"will",
"return",
"the",
"string",
"that",
"starts",
"at",
"the",
"given",
"index"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L169-L209 | train | 61,405 |
holtjma/msbwt | MUS/MultiStringBWT.py | MultiStringBWT.getOccurrenceOfCharAtIndex | def getOccurrenceOfCharAtIndex(self, sym, index):
'''
This functions gets the FM-index value of a character at the specified position
@param sym - the character to find the occurrence level
@param index - the index we want to find the occurrence level at
@return - the number of o... | python | def getOccurrenceOfCharAtIndex(self, sym, index):
'''
This functions gets the FM-index value of a character at the specified position
@param sym - the character to find the occurrence level
@param index - the index we want to find the occurrence level at
@return - the number of o... | [
"def",
"getOccurrenceOfCharAtIndex",
"(",
"self",
",",
"sym",
",",
"index",
")",
":",
"#sampling method",
"#get the bin we occupy",
"binID",
"=",
"index",
">>",
"self",
".",
"bitPower",
"#these two methods seem to have the same approximate run time",
"if",
"(",
"binID",
... | This functions gets the FM-index value of a character at the specified position
@param sym - the character to find the occurrence level
@param index - the index we want to find the occurrence level at
@return - the number of occurrences of char before the specified index | [
"This",
"functions",
"gets",
"the",
"FM",
"-",
"index",
"value",
"of",
"a",
"character",
"at",
"the",
"specified",
"position"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L319-L335 | train | 61,406 |
holtjma/msbwt | MUS/MultiStringBWT.py | CompressedMSBWT.loadMsbwt | def loadMsbwt(self, dirName, logger):
'''
This functions loads a BWT file and constructs total counts, indexes start positions, and constructs an FM index in memory
@param dirName - the directory to load, inside should be '<DIR>/comp_msbwt.npy' or it will fail
'''
#open the file ... | python | def loadMsbwt(self, dirName, logger):
'''
This functions loads a BWT file and constructs total counts, indexes start positions, and constructs an FM index in memory
@param dirName - the directory to load, inside should be '<DIR>/comp_msbwt.npy' or it will fail
'''
#open the file ... | [
"def",
"loadMsbwt",
"(",
"self",
",",
"dirName",
",",
"logger",
")",
":",
"#open the file with our BWT in it",
"self",
".",
"dirName",
"=",
"dirName",
"self",
".",
"bwt",
"=",
"np",
".",
"load",
"(",
"self",
".",
"dirName",
"+",
"'/comp_msbwt.npy'",
",",
"... | This functions loads a BWT file and constructs total counts, indexes start positions, and constructs an FM index in memory
@param dirName - the directory to load, inside should be '<DIR>/comp_msbwt.npy' or it will fail | [
"This",
"functions",
"loads",
"a",
"BWT",
"file",
"and",
"constructs",
"total",
"counts",
"indexes",
"start",
"positions",
"and",
"constructs",
"an",
"FM",
"index",
"in",
"memory"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L396-L408 | train | 61,407 |
holtjma/msbwt | MUS/MultiStringBWT.py | CompressedMSBWT.getCharAtIndex | def getCharAtIndex(self, index):
'''
Used for searching, this function masks the complexity behind retrieving a specific character at a specific index
in our compressed BWT.
@param index - the index to retrieve the character from
@param return - return the character in our BWT th... | python | def getCharAtIndex(self, index):
'''
Used for searching, this function masks the complexity behind retrieving a specific character at a specific index
in our compressed BWT.
@param index - the index to retrieve the character from
@param return - return the character in our BWT th... | [
"def",
"getCharAtIndex",
"(",
"self",
",",
"index",
")",
":",
"#get the bin we should start from",
"binID",
"=",
"index",
">>",
"self",
".",
"bitPower",
"bwtIndex",
"=",
"self",
".",
"refFM",
"[",
"binID",
"]",
"#these are the values that indicate how far in we really... | Used for searching, this function masks the complexity behind retrieving a specific character at a specific index
in our compressed BWT.
@param index - the index to retrieve the character from
@param return - return the character in our BWT that's at a particular index (integer format) | [
"Used",
"for",
"searching",
"this",
"function",
"masks",
"the",
"complexity",
"behind",
"retrieving",
"a",
"specific",
"character",
"at",
"a",
"specific",
"index",
"in",
"our",
"compressed",
"BWT",
"."
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L555-L593 | train | 61,408 |
holtjma/msbwt | MUS/MultiStringBWT.py | CompressedMSBWT.getBWTRange | def getBWTRange(self, start, end):
'''
This function masks the complexity of retrieving a chunk of the BWT from the compressed format
@param start - the beginning of the range to retrieve
@param end - the end of the range in normal python notation (bwt[end] is not part of the return)
... | python | def getBWTRange(self, start, end):
'''
This function masks the complexity of retrieving a chunk of the BWT from the compressed format
@param start - the beginning of the range to retrieve
@param end - the end of the range in normal python notation (bwt[end] is not part of the return)
... | [
"def",
"getBWTRange",
"(",
"self",
",",
"start",
",",
"end",
")",
":",
"#set aside an array block to fill",
"startBlockIndex",
"=",
"start",
">>",
"self",
".",
"bitPower",
"endBlockIndex",
"=",
"int",
"(",
"math",
".",
"floor",
"(",
"float",
"(",
"end",
")",... | This function masks the complexity of retrieving a chunk of the BWT from the compressed format
@param start - the beginning of the range to retrieve
@param end - the end of the range in normal python notation (bwt[end] is not part of the return)
@return - a range of integers representing the cha... | [
"This",
"function",
"masks",
"the",
"complexity",
"of",
"retrieving",
"a",
"chunk",
"of",
"the",
"BWT",
"from",
"the",
"compressed",
"format"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L595-L608 | train | 61,409 |
holtjma/msbwt | MUS/MultiStringBWT.py | CompressedMSBWT.decompressBlocks | def decompressBlocks(self, startBlock, endBlock):
'''
This is mostly a helper function to get BWT range, but I wanted it to be a separate thing for use possibly in
decompression
@param startBlock - the index of the start block we will decode
@param endBlock - the index of the fi... | python | def decompressBlocks(self, startBlock, endBlock):
'''
This is mostly a helper function to get BWT range, but I wanted it to be a separate thing for use possibly in
decompression
@param startBlock - the index of the start block we will decode
@param endBlock - the index of the fi... | [
"def",
"decompressBlocks",
"(",
"self",
",",
"startBlock",
",",
"endBlock",
")",
":",
"expectedIndex",
"=",
"startBlock",
"*",
"self",
".",
"binSize",
"trueIndex",
"=",
"np",
".",
"sum",
"(",
"self",
".",
"partialFM",
"[",
"startBlock",
"]",
")",
"-",
"s... | This is mostly a helper function to get BWT range, but I wanted it to be a separate thing for use possibly in
decompression
@param startBlock - the index of the start block we will decode
@param endBlock - the index of the final block we will decode, if they are the same, we decode one block
... | [
"This",
"is",
"mostly",
"a",
"helper",
"function",
"to",
"get",
"BWT",
"range",
"but",
"I",
"wanted",
"it",
"to",
"be",
"a",
"separate",
"thing",
"for",
"use",
"possibly",
"in",
"decompression"
] | 7503346ec072ddb89520db86fef85569a9ba093a | https://github.com/holtjma/msbwt/blob/7503346ec072ddb89520db86fef85569a9ba093a/MUS/MultiStringBWT.py#L610-L666 | train | 61,410 |
bookieio/breadability | breadability/document.py | decode_html | def decode_html(html):
"""
Converts bytes stream containing an HTML page into Unicode.
Tries to guess character encoding from meta tag of by "chardet" library.
"""
if isinstance(html, unicode):
return html
match = CHARSET_META_TAG_PATTERN.search(html)
if match:
declared_enco... | python | def decode_html(html):
"""
Converts bytes stream containing an HTML page into Unicode.
Tries to guess character encoding from meta tag of by "chardet" library.
"""
if isinstance(html, unicode):
return html
match = CHARSET_META_TAG_PATTERN.search(html)
if match:
declared_enco... | [
"def",
"decode_html",
"(",
"html",
")",
":",
"if",
"isinstance",
"(",
"html",
",",
"unicode",
")",
":",
"return",
"html",
"match",
"=",
"CHARSET_META_TAG_PATTERN",
".",
"search",
"(",
"html",
")",
"if",
"match",
":",
"declared_encoding",
"=",
"match",
".",... | Converts bytes stream containing an HTML page into Unicode.
Tries to guess character encoding from meta tag of by "chardet" library. | [
"Converts",
"bytes",
"stream",
"containing",
"an",
"HTML",
"page",
"into",
"Unicode",
".",
"Tries",
"to",
"guess",
"character",
"encoding",
"from",
"meta",
"tag",
"of",
"by",
"chardet",
"library",
"."
] | 95a364c43b00baf6664bea1997a7310827fb1ee9 | https://github.com/bookieio/breadability/blob/95a364c43b00baf6664bea1997a7310827fb1ee9/breadability/document.py#L28-L61 | train | 61,411 |
bookieio/breadability | breadability/document.py | build_document | def build_document(html_content, base_href=None):
"""Requires that the `html_content` not be None"""
assert html_content is not None
if isinstance(html_content, unicode):
html_content = html_content.encode("utf8", "xmlcharrefreplace")
try:
document = document_fromstring(html_content, p... | python | def build_document(html_content, base_href=None):
"""Requires that the `html_content` not be None"""
assert html_content is not None
if isinstance(html_content, unicode):
html_content = html_content.encode("utf8", "xmlcharrefreplace")
try:
document = document_fromstring(html_content, p... | [
"def",
"build_document",
"(",
"html_content",
",",
"base_href",
"=",
"None",
")",
":",
"assert",
"html_content",
"is",
"not",
"None",
"if",
"isinstance",
"(",
"html_content",
",",
"unicode",
")",
":",
"html_content",
"=",
"html_content",
".",
"encode",
"(",
... | Requires that the `html_content` not be None | [
"Requires",
"that",
"the",
"html_content",
"not",
"be",
"None"
] | 95a364c43b00baf6664bea1997a7310827fb1ee9 | https://github.com/bookieio/breadability/blob/95a364c43b00baf6664bea1997a7310827fb1ee9/breadability/document.py#L90-L107 | train | 61,412 |
ngzhian/pycrunchbase | src/pycrunchbase/resource/node.py | Node._parse_properties | def _parse_properties(self):
"""Nodes have properties, which are facts like the
name, description, url etc.
Loop through each of them and set it as attributes on this company so
that we can make calls like
company.name
person.description
"""
props_... | python | def _parse_properties(self):
"""Nodes have properties, which are facts like the
name, description, url etc.
Loop through each of them and set it as attributes on this company so
that we can make calls like
company.name
person.description
"""
props_... | [
"def",
"_parse_properties",
"(",
"self",
")",
":",
"props_dict",
"=",
"self",
".",
"data",
".",
"get",
"(",
"'properties'",
",",
"{",
"}",
")",
"for",
"prop_name",
"in",
"self",
".",
"KNOWN_PROPERTIES",
":",
"if",
"prop_name",
"in",
"props_dict",
":",
"s... | Nodes have properties, which are facts like the
name, description, url etc.
Loop through each of them and set it as attributes on this company so
that we can make calls like
company.name
person.description | [
"Nodes",
"have",
"properties",
"which",
"are",
"facts",
"like",
"the",
"name",
"description",
"url",
"etc",
".",
"Loop",
"through",
"each",
"of",
"them",
"and",
"set",
"it",
"as",
"attributes",
"on",
"this",
"company",
"so",
"that",
"we",
"can",
"make",
... | 8635ee343ff0d02db01e15967e00894ea2a37b7d | https://github.com/ngzhian/pycrunchbase/blob/8635ee343ff0d02db01e15967e00894ea2a37b7d/src/pycrunchbase/resource/node.py#L23-L36 | train | 61,413 |
ngzhian/pycrunchbase | src/pycrunchbase/resource/node.py | Node._parse_relationship | def _parse_relationship(self):
"""Nodes have Relationships, and similarly to properties,
we set it as an attribute on the Organization so we can make calls like
company.current_team
person.degrees
"""
rs_dict = self.data.get('relationships', {})
for rs_nam... | python | def _parse_relationship(self):
"""Nodes have Relationships, and similarly to properties,
we set it as an attribute on the Organization so we can make calls like
company.current_team
person.degrees
"""
rs_dict = self.data.get('relationships', {})
for rs_nam... | [
"def",
"_parse_relationship",
"(",
"self",
")",
":",
"rs_dict",
"=",
"self",
".",
"data",
".",
"get",
"(",
"'relationships'",
",",
"{",
"}",
")",
"for",
"rs_name",
"in",
"self",
".",
"KNOWN_RELATIONSHIPS",
":",
"if",
"rs_name",
"in",
"rs_dict",
":",
"set... | Nodes have Relationships, and similarly to properties,
we set it as an attribute on the Organization so we can make calls like
company.current_team
person.degrees | [
"Nodes",
"have",
"Relationships",
"and",
"similarly",
"to",
"properties",
"we",
"set",
"it",
"as",
"an",
"attribute",
"on",
"the",
"Organization",
"so",
"we",
"can",
"make",
"calls",
"like",
"company",
".",
"current_team",
"person",
".",
"degrees"
] | 8635ee343ff0d02db01e15967e00894ea2a37b7d | https://github.com/ngzhian/pycrunchbase/blob/8635ee343ff0d02db01e15967e00894ea2a37b7d/src/pycrunchbase/resource/node.py#L38-L51 | train | 61,414 |
AmesCornish/buttersink | buttersink/progress.py | DisplayProgress.open | def open(self):
""" Reset time and counts. """
self.startTime = datetime.datetime.now()
self.offset = 0
return self | python | def open(self):
""" Reset time and counts. """
self.startTime = datetime.datetime.now()
self.offset = 0
return self | [
"def",
"open",
"(",
"self",
")",
":",
"self",
".",
"startTime",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"self",
".",
"offset",
"=",
"0",
"return",
"self"
] | Reset time and counts. | [
"Reset",
"time",
"and",
"counts",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/progress.py#L28-L32 | train | 61,415 |
AmesCornish/buttersink | buttersink/progress.py | DisplayProgress.update | def update(self, sent):
""" Update self and parent with intermediate progress. """
self.offset = sent
now = datetime.datetime.now()
elapsed = (now - self.startTime).total_seconds()
if elapsed > 0:
mbps = (sent * 8 / (10 ** 6)) / elapsed
else:
mbp... | python | def update(self, sent):
""" Update self and parent with intermediate progress. """
self.offset = sent
now = datetime.datetime.now()
elapsed = (now - self.startTime).total_seconds()
if elapsed > 0:
mbps = (sent * 8 / (10 ** 6)) / elapsed
else:
mbp... | [
"def",
"update",
"(",
"self",
",",
"sent",
")",
":",
"self",
".",
"offset",
"=",
"sent",
"now",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"elapsed",
"=",
"(",
"now",
"-",
"self",
".",
"startTime",
")",
".",
"total_seconds",
"(",
")",
... | Update self and parent with intermediate progress. | [
"Update",
"self",
"and",
"parent",
"with",
"intermediate",
"progress",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/progress.py#L39-L51 | train | 61,416 |
AmesCornish/buttersink | buttersink/progress.py | DisplayProgress._display | def _display(self, sent, now, chunk, mbps):
""" Display intermediate progress. """
if self.parent is not None:
self.parent._display(self.parent.offset + sent, now, chunk, mbps)
return
elapsed = now - self.startTime
if sent > 0 and self.total is not None and sent... | python | def _display(self, sent, now, chunk, mbps):
""" Display intermediate progress. """
if self.parent is not None:
self.parent._display(self.parent.offset + sent, now, chunk, mbps)
return
elapsed = now - self.startTime
if sent > 0 and self.total is not None and sent... | [
"def",
"_display",
"(",
"self",
",",
"sent",
",",
"now",
",",
"chunk",
",",
"mbps",
")",
":",
"if",
"self",
".",
"parent",
"is",
"not",
"None",
":",
"self",
".",
"parent",
".",
"_display",
"(",
"self",
".",
"parent",
".",
"offset",
"+",
"sent",
"... | Display intermediate progress. | [
"Display",
"intermediate",
"progress",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/progress.py#L53-L80 | train | 61,417 |
AmesCornish/buttersink | buttersink/progress.py | DisplayProgress.close | def close(self):
""" Stop overwriting display, or update parent. """
if self.parent:
self.parent.update(self.parent.offset + self.offset)
return
self.output.write("\n")
self.output.flush() | python | def close(self):
""" Stop overwriting display, or update parent. """
if self.parent:
self.parent.update(self.parent.offset + self.offset)
return
self.output.write("\n")
self.output.flush() | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"parent",
":",
"self",
".",
"parent",
".",
"update",
"(",
"self",
".",
"parent",
".",
"offset",
"+",
"self",
".",
"offset",
")",
"return",
"self",
".",
"output",
".",
"write",
"(",
"\"\\n\""... | Stop overwriting display, or update parent. | [
"Stop",
"overwriting",
"display",
"or",
"update",
"parent",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/progress.py#L82-L88 | train | 61,418 |
AmesCornish/buttersink | buttersink/Store.py | _printUUID | def _printUUID(uuid, detail='word'):
""" Return friendly abbreviated string for uuid. """
if not isinstance(detail, int):
detail = detailNum[detail]
if detail > detailNum['word']:
return uuid
if uuid is None:
return None
return "%s...%s" % (uuid[:4], uuid[-4:]) | python | def _printUUID(uuid, detail='word'):
""" Return friendly abbreviated string for uuid. """
if not isinstance(detail, int):
detail = detailNum[detail]
if detail > detailNum['word']:
return uuid
if uuid is None:
return None
return "%s...%s" % (uuid[:4], uuid[-4:]) | [
"def",
"_printUUID",
"(",
"uuid",
",",
"detail",
"=",
"'word'",
")",
":",
"if",
"not",
"isinstance",
"(",
"detail",
",",
"int",
")",
":",
"detail",
"=",
"detailNum",
"[",
"detail",
"]",
"if",
"detail",
">",
"detailNum",
"[",
"'word'",
"]",
":",
"retu... | Return friendly abbreviated string for uuid. | [
"Return",
"friendly",
"abbreviated",
"string",
"for",
"uuid",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L527-L538 | train | 61,419 |
AmesCornish/buttersink | buttersink/Store.py | skipDryRun | def skipDryRun(logger, dryRun, level=logging.DEBUG):
""" Return logging function.
When logging function called, will return True if action should be skipped.
Log will indicate if skipped because of dry run.
"""
# This is an undocumented "feature" of logging module:
# logging.log() requires a nu... | python | def skipDryRun(logger, dryRun, level=logging.DEBUG):
""" Return logging function.
When logging function called, will return True if action should be skipped.
Log will indicate if skipped because of dry run.
"""
# This is an undocumented "feature" of logging module:
# logging.log() requires a nu... | [
"def",
"skipDryRun",
"(",
"logger",
",",
"dryRun",
",",
"level",
"=",
"logging",
".",
"DEBUG",
")",
":",
"# This is an undocumented \"feature\" of logging module:",
"# logging.log() requires a numeric level",
"# logging.getLevelName() maps names to numbers",
"if",
"not",
"isins... | Return logging function.
When logging function called, will return True if action should be skipped.
Log will indicate if skipped because of dry run. | [
"Return",
"logging",
"function",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L541-L555 | train | 61,420 |
AmesCornish/buttersink | buttersink/Store.py | Store.listVolumes | def listVolumes(self):
""" Return list of all volumes in this Store's selected directory. """
for (vol, paths) in self.paths.items():
for path in paths:
if path.startswith('/'):
continue
if path == '.':
continue
... | python | def listVolumes(self):
""" Return list of all volumes in this Store's selected directory. """
for (vol, paths) in self.paths.items():
for path in paths:
if path.startswith('/'):
continue
if path == '.':
continue
... | [
"def",
"listVolumes",
"(",
"self",
")",
":",
"for",
"(",
"vol",
",",
"paths",
")",
"in",
"self",
".",
"paths",
".",
"items",
"(",
")",
":",
"for",
"path",
"in",
"paths",
":",
"if",
"path",
".",
"startswith",
"(",
"'/'",
")",
":",
"continue",
"if"... | Return list of all volumes in this Store's selected directory. | [
"Return",
"list",
"of",
"all",
"volumes",
"in",
"this",
"Store",
"s",
"selected",
"directory",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L90-L101 | train | 61,421 |
AmesCornish/buttersink | buttersink/Store.py | Store.getSendPath | def getSendPath(self, volume):
""" Get a path appropriate for sending the volume from this Store.
The path may be relative or absolute in this Store.
"""
try:
return self._fullPath(next(iter(self.getPaths(volume))))
except StopIteration:
return None | python | def getSendPath(self, volume):
""" Get a path appropriate for sending the volume from this Store.
The path may be relative or absolute in this Store.
"""
try:
return self._fullPath(next(iter(self.getPaths(volume))))
except StopIteration:
return None | [
"def",
"getSendPath",
"(",
"self",
",",
"volume",
")",
":",
"try",
":",
"return",
"self",
".",
"_fullPath",
"(",
"next",
"(",
"iter",
"(",
"self",
".",
"getPaths",
"(",
"volume",
")",
")",
")",
")",
"except",
"StopIteration",
":",
"return",
"None"
] | Get a path appropriate for sending the volume from this Store.
The path may be relative or absolute in this Store. | [
"Get",
"a",
"path",
"appropriate",
"for",
"sending",
"the",
"volume",
"from",
"this",
"Store",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L107-L116 | train | 61,422 |
AmesCornish/buttersink | buttersink/Store.py | Store.selectReceivePath | def selectReceivePath(self, paths):
""" From a set of source paths, recommend a destination path.
The paths are relative or absolute, in a source Store.
The result will be absolute, suitable for this destination Store.
"""
logger.debug("%s", paths)
if not paths:
... | python | def selectReceivePath(self, paths):
""" From a set of source paths, recommend a destination path.
The paths are relative or absolute, in a source Store.
The result will be absolute, suitable for this destination Store.
"""
logger.debug("%s", paths)
if not paths:
... | [
"def",
"selectReceivePath",
"(",
"self",
",",
"paths",
")",
":",
"logger",
".",
"debug",
"(",
"\"%s\"",
",",
"paths",
")",
"if",
"not",
"paths",
":",
"path",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"self",
".",
"userPath",
")",
"+",
"'/Anon'",
... | From a set of source paths, recommend a destination path.
The paths are relative or absolute, in a source Store.
The result will be absolute, suitable for this destination Store. | [
"From",
"a",
"set",
"of",
"source",
"paths",
"recommend",
"a",
"destination",
"path",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L118-L137 | train | 61,423 |
AmesCornish/buttersink | buttersink/Store.py | Store._relativePath | def _relativePath(self, fullPath):
""" Return fullPath relative to Store directory.
Return fullPath if fullPath is not inside directory.
Return None if fullPath is outside our scope.
"""
if fullPath is None:
return None
assert fullPath.startswith("/"), full... | python | def _relativePath(self, fullPath):
""" Return fullPath relative to Store directory.
Return fullPath if fullPath is not inside directory.
Return None if fullPath is outside our scope.
"""
if fullPath is None:
return None
assert fullPath.startswith("/"), full... | [
"def",
"_relativePath",
"(",
"self",
",",
"fullPath",
")",
":",
"if",
"fullPath",
"is",
"None",
":",
"return",
"None",
"assert",
"fullPath",
".",
"startswith",
"(",
"\"/\"",
")",
",",
"fullPath",
"path",
"=",
"os",
".",
"path",
".",
"relpath",
"(",
"fu... | Return fullPath relative to Store directory.
Return fullPath if fullPath is not inside directory.
Return None if fullPath is outside our scope. | [
"Return",
"fullPath",
"relative",
"to",
"Store",
"directory",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L148-L167 | train | 61,424 |
AmesCornish/buttersink | buttersink/Store.py | Diff.setSize | def setSize(self, size, sizeIsEstimated):
""" Update size. """
self._size = size
self._sizeIsEstimated = sizeIsEstimated
if self.fromVol is not None and size is not None and not sizeIsEstimated:
Diff.theKnownSizes[self.toUUID][self.fromUUID] = size | python | def setSize(self, size, sizeIsEstimated):
""" Update size. """
self._size = size
self._sizeIsEstimated = sizeIsEstimated
if self.fromVol is not None and size is not None and not sizeIsEstimated:
Diff.theKnownSizes[self.toUUID][self.fromUUID] = size | [
"def",
"setSize",
"(",
"self",
",",
"size",
",",
"sizeIsEstimated",
")",
":",
"self",
".",
"_size",
"=",
"size",
"self",
".",
"_sizeIsEstimated",
"=",
"sizeIsEstimated",
"if",
"self",
".",
"fromVol",
"is",
"not",
"None",
"and",
"size",
"is",
"not",
"None... | Update size. | [
"Update",
"size",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L333-L339 | train | 61,425 |
AmesCornish/buttersink | buttersink/Store.py | Diff.sendTo | def sendTo(self, dest, chunkSize):
""" Send this difference to the dest Store. """
vol = self.toVol
paths = self.sink.getPaths(vol)
if self.sink == dest:
logger.info("Keep: %s", self)
self.sink.keep(self)
else:
# Log, but don't skip yet, so we... | python | def sendTo(self, dest, chunkSize):
""" Send this difference to the dest Store. """
vol = self.toVol
paths = self.sink.getPaths(vol)
if self.sink == dest:
logger.info("Keep: %s", self)
self.sink.keep(self)
else:
# Log, but don't skip yet, so we... | [
"def",
"sendTo",
"(",
"self",
",",
"dest",
",",
"chunkSize",
")",
":",
"vol",
"=",
"self",
".",
"toVol",
"paths",
"=",
"self",
".",
"sink",
".",
"getPaths",
"(",
"vol",
")",
"if",
"self",
".",
"sink",
"==",
"dest",
":",
"logger",
".",
"info",
"("... | Send this difference to the dest Store. | [
"Send",
"this",
"difference",
"to",
"the",
"dest",
"Store",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L341-L372 | train | 61,426 |
AmesCornish/buttersink | buttersink/Store.py | Volume.writeInfoLine | def writeInfoLine(self, stream, fromUUID, size):
""" Write one line of diff information. """
if size is None or fromUUID is None:
return
if not isinstance(size, int):
logger.warning("Bad size: %s", size)
return
stream.write(str("%s\t%s\t%d\n" % (
... | python | def writeInfoLine(self, stream, fromUUID, size):
""" Write one line of diff information. """
if size is None or fromUUID is None:
return
if not isinstance(size, int):
logger.warning("Bad size: %s", size)
return
stream.write(str("%s\t%s\t%d\n" % (
... | [
"def",
"writeInfoLine",
"(",
"self",
",",
"stream",
",",
"fromUUID",
",",
"size",
")",
":",
"if",
"size",
"is",
"None",
"or",
"fromUUID",
"is",
"None",
":",
"return",
"if",
"not",
"isinstance",
"(",
"size",
",",
"int",
")",
":",
"logger",
".",
"warni... | Write one line of diff information. | [
"Write",
"one",
"line",
"of",
"diff",
"information",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L425-L436 | train | 61,427 |
AmesCornish/buttersink | buttersink/Store.py | Volume.writeInfo | def writeInfo(self, stream):
""" Write information about diffs into a file stream for use later. """
for (fromUUID, size) in Diff.theKnownSizes[self.uuid].iteritems():
self.writeInfoLine(stream, fromUUID, size) | python | def writeInfo(self, stream):
""" Write information about diffs into a file stream for use later. """
for (fromUUID, size) in Diff.theKnownSizes[self.uuid].iteritems():
self.writeInfoLine(stream, fromUUID, size) | [
"def",
"writeInfo",
"(",
"self",
",",
"stream",
")",
":",
"for",
"(",
"fromUUID",
",",
"size",
")",
"in",
"Diff",
".",
"theKnownSizes",
"[",
"self",
".",
"uuid",
"]",
".",
"iteritems",
"(",
")",
":",
"self",
".",
"writeInfoLine",
"(",
"stream",
",",
... | Write information about diffs into a file stream for use later. | [
"Write",
"information",
"about",
"diffs",
"into",
"a",
"file",
"stream",
"for",
"use",
"later",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L438-L441 | train | 61,428 |
AmesCornish/buttersink | buttersink/Store.py | Volume.hasInfo | def hasInfo(self):
""" Will have information to write. """
count = len([None
for (fromUUID, size)
in Diff.theKnownSizes[self.uuid].iteritems()
if size is not None and fromUUID is not None
])
return count > 0 | python | def hasInfo(self):
""" Will have information to write. """
count = len([None
for (fromUUID, size)
in Diff.theKnownSizes[self.uuid].iteritems()
if size is not None and fromUUID is not None
])
return count > 0 | [
"def",
"hasInfo",
"(",
"self",
")",
":",
"count",
"=",
"len",
"(",
"[",
"None",
"for",
"(",
"fromUUID",
",",
"size",
")",
"in",
"Diff",
".",
"theKnownSizes",
"[",
"self",
".",
"uuid",
"]",
".",
"iteritems",
"(",
")",
"if",
"size",
"is",
"not",
"N... | Will have information to write. | [
"Will",
"have",
"information",
"to",
"write",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L443-L450 | train | 61,429 |
AmesCornish/buttersink | buttersink/Store.py | Volume.readInfo | def readInfo(stream):
""" Read previously-written information about diffs. """
try:
for line in stream:
(toUUID, fromUUID, size) = line.split()
try:
size = int(size)
except Exception:
logger.warning("Bad ... | python | def readInfo(stream):
""" Read previously-written information about diffs. """
try:
for line in stream:
(toUUID, fromUUID, size) = line.split()
try:
size = int(size)
except Exception:
logger.warning("Bad ... | [
"def",
"readInfo",
"(",
"stream",
")",
":",
"try",
":",
"for",
"line",
"in",
"stream",
":",
"(",
"toUUID",
",",
"fromUUID",
",",
"size",
")",
"=",
"line",
".",
"split",
"(",
")",
"try",
":",
"size",
"=",
"int",
"(",
"size",
")",
"except",
"Except... | Read previously-written information about diffs. | [
"Read",
"previously",
"-",
"written",
"information",
"about",
"diffs",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L453-L466 | train | 61,430 |
AmesCornish/buttersink | buttersink/Store.py | Volume.make | def make(cls, vol):
""" Convert uuid to Volume, if necessary. """
if isinstance(vol, cls):
return vol
elif vol is None:
return None
else:
return cls(vol, None) | python | def make(cls, vol):
""" Convert uuid to Volume, if necessary. """
if isinstance(vol, cls):
return vol
elif vol is None:
return None
else:
return cls(vol, None) | [
"def",
"make",
"(",
"cls",
",",
"vol",
")",
":",
"if",
"isinstance",
"(",
"vol",
",",
"cls",
")",
":",
"return",
"vol",
"elif",
"vol",
"is",
"None",
":",
"return",
"None",
"else",
":",
"return",
"cls",
"(",
"vol",
",",
"None",
")"
] | Convert uuid to Volume, if necessary. | [
"Convert",
"uuid",
"to",
"Volume",
"if",
"necessary",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Store.py#L506-L513 | train | 61,431 |
AmesCornish/buttersink | buttersink/S3Store.py | S3Store.hasEdge | def hasEdge(self, diff):
""" Test whether edge is in this sink. """
return diff.toVol in [d.toVol for d in self.diffs[diff.fromVol]] | python | def hasEdge(self, diff):
""" Test whether edge is in this sink. """
return diff.toVol in [d.toVol for d in self.diffs[diff.fromVol]] | [
"def",
"hasEdge",
"(",
"self",
",",
"diff",
")",
":",
"return",
"diff",
".",
"toVol",
"in",
"[",
"d",
".",
"toVol",
"for",
"d",
"in",
"self",
".",
"diffs",
"[",
"diff",
".",
"fromVol",
"]",
"]"
] | Test whether edge is in this sink. | [
"Test",
"whether",
"edge",
"is",
"in",
"this",
"sink",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/S3Store.py#L176-L178 | train | 61,432 |
AmesCornish/buttersink | buttersink/S3Store.py | S3Store._parseKeyName | def _parseKeyName(self, name):
""" Returns dict with fullpath, to, from. """
if name.endswith(Store.theInfoExtension):
return {'type': 'info'}
match = self.keyPattern.match(name)
if not match:
return None
match = match.groupdict()
match.update(ty... | python | def _parseKeyName(self, name):
""" Returns dict with fullpath, to, from. """
if name.endswith(Store.theInfoExtension):
return {'type': 'info'}
match = self.keyPattern.match(name)
if not match:
return None
match = match.groupdict()
match.update(ty... | [
"def",
"_parseKeyName",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
".",
"endswith",
"(",
"Store",
".",
"theInfoExtension",
")",
":",
"return",
"{",
"'type'",
":",
"'info'",
"}",
"match",
"=",
"self",
".",
"keyPattern",
".",
"match",
"(",
"name",... | Returns dict with fullpath, to, from. | [
"Returns",
"dict",
"with",
"fullpath",
"to",
"from",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/S3Store.py#L210-L222 | train | 61,433 |
AmesCornish/buttersink | buttersink/util.py | humanize | def humanize(number):
""" Return a human-readable string for number. """
# units = ('bytes', 'KB', 'MB', 'GB', 'TB')
# base = 1000
units = ('bytes', 'KiB', 'MiB', 'GiB', 'TiB')
base = 1024
if number is None:
return None
pow = int(math.log(number, base)) if number > 0 else 0
pow =... | python | def humanize(number):
""" Return a human-readable string for number. """
# units = ('bytes', 'KB', 'MB', 'GB', 'TB')
# base = 1000
units = ('bytes', 'KiB', 'MiB', 'GiB', 'TiB')
base = 1024
if number is None:
return None
pow = int(math.log(number, base)) if number > 0 else 0
pow =... | [
"def",
"humanize",
"(",
"number",
")",
":",
"# units = ('bytes', 'KB', 'MB', 'GB', 'TB')",
"# base = 1000",
"units",
"=",
"(",
"'bytes'",
",",
"'KiB'",
",",
"'MiB'",
",",
"'GiB'",
",",
"'TiB'",
")",
"base",
"=",
"1024",
"if",
"number",
"is",
"None",
":",
"re... | Return a human-readable string for number. | [
"Return",
"a",
"human",
"-",
"readable",
"string",
"for",
"number",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/util.py#L24-L35 | train | 61,434 |
AmesCornish/buttersink | buttersink/Butter.py | Butter.receive | def receive(self, path, diff, showProgress=True):
""" Return a context manager for stream that will store a diff. """
directory = os.path.dirname(path)
cmd = ["btrfs", "receive", "-e", directory]
if Store.skipDryRun(logger, self.dryrun)("Command: %s", cmd):
return None
... | python | def receive(self, path, diff, showProgress=True):
""" Return a context manager for stream that will store a diff. """
directory = os.path.dirname(path)
cmd = ["btrfs", "receive", "-e", directory]
if Store.skipDryRun(logger, self.dryrun)("Command: %s", cmd):
return None
... | [
"def",
"receive",
"(",
"self",
",",
"path",
",",
"diff",
",",
"showProgress",
"=",
"True",
")",
":",
"directory",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
"cmd",
"=",
"[",
"\"btrfs\"",
",",
"\"receive\"",
",",
"\"-e\"",
",",
"directo... | Return a context manager for stream that will store a diff. | [
"Return",
"a",
"context",
"manager",
"for",
"stream",
"that",
"will",
"store",
"a",
"diff",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/Butter.py#L81-L101 | train | 61,435 |
AmesCornish/buttersink | buttersink/BestDiffs.py | BestDiffs.iterDiffs | def iterDiffs(self):
""" Return all diffs used in optimal network. """
nodes = self.nodes.values()
nodes.sort(key=lambda node: self._height(node))
for node in nodes:
yield node.diff | python | def iterDiffs(self):
""" Return all diffs used in optimal network. """
nodes = self.nodes.values()
nodes.sort(key=lambda node: self._height(node))
for node in nodes:
yield node.diff | [
"def",
"iterDiffs",
"(",
"self",
")",
":",
"nodes",
"=",
"self",
".",
"nodes",
".",
"values",
"(",
")",
"nodes",
".",
"sort",
"(",
"key",
"=",
"lambda",
"node",
":",
"self",
".",
"_height",
"(",
"node",
")",
")",
"for",
"node",
"in",
"nodes",
":"... | Return all diffs used in optimal network. | [
"Return",
"all",
"diffs",
"used",
"in",
"optimal",
"network",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/BestDiffs.py#L301-L306 | train | 61,436 |
AmesCornish/buttersink | buttersink/BestDiffs.py | BestDiffs._prune | def _prune(self):
""" Get rid of all intermediate nodes that aren't needed. """
done = False
while not done:
done = True
for node in [node for node in self.nodes.values() if node.intermediate]:
if not [dep for dep in self.nodes.values() if dep.previous == ... | python | def _prune(self):
""" Get rid of all intermediate nodes that aren't needed. """
done = False
while not done:
done = True
for node in [node for node in self.nodes.values() if node.intermediate]:
if not [dep for dep in self.nodes.values() if dep.previous == ... | [
"def",
"_prune",
"(",
"self",
")",
":",
"done",
"=",
"False",
"while",
"not",
"done",
":",
"done",
"=",
"True",
"for",
"node",
"in",
"[",
"node",
"for",
"node",
"in",
"self",
".",
"nodes",
".",
"values",
"(",
")",
"if",
"node",
".",
"intermediate",... | Get rid of all intermediate nodes that aren't needed. | [
"Get",
"rid",
"of",
"all",
"intermediate",
"nodes",
"that",
"aren",
"t",
"needed",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/BestDiffs.py#L313-L322 | train | 61,437 |
pycontribs/activedirectory | activedirectory/activedirectory.py | ActiveDirectory.__compress_attributes | def __compress_attributes(self, dic):
"""
This will convert all attributes that are list with only one item string into simple string. It seems that LDAP always return lists, even when it doesn
t make sense.
:param dic:
:return:
"""
result = {}
for k, v i... | python | def __compress_attributes(self, dic):
"""
This will convert all attributes that are list with only one item string into simple string. It seems that LDAP always return lists, even when it doesn
t make sense.
:param dic:
:return:
"""
result = {}
for k, v i... | [
"def",
"__compress_attributes",
"(",
"self",
",",
"dic",
")",
":",
"result",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"dic",
".",
"iteritems",
"(",
")",
":",
"if",
"isinstance",
"(",
"v",
",",
"types",
".",
"ListType",
")",
"and",
"len",
"(",
"... | This will convert all attributes that are list with only one item string into simple string. It seems that LDAP always return lists, even when it doesn
t make sense.
:param dic:
:return: | [
"This",
"will",
"convert",
"all",
"attributes",
"that",
"are",
"list",
"with",
"only",
"one",
"item",
"string",
"into",
"simple",
"string",
".",
"It",
"seems",
"that",
"LDAP",
"always",
"return",
"lists",
"even",
"when",
"it",
"doesn",
"t",
"make",
"sense"... | cd491511e2ed667c3b4634a682ea012c6cbedb38 | https://github.com/pycontribs/activedirectory/blob/cd491511e2ed667c3b4634a682ea012c6cbedb38/activedirectory/activedirectory.py#L253-L276 | train | 61,438 |
AmesCornish/buttersink | buttersink/ButterStore.py | ButterStore._keepVol | def _keepVol(self, vol):
""" Mark this volume to be kept in path. """
if vol is None:
return
if vol in self.extraVolumes:
del self.extraVolumes[vol]
return
if vol not in self.paths:
raise Exception("%s not in %s" % (vol, self))
p... | python | def _keepVol(self, vol):
""" Mark this volume to be kept in path. """
if vol is None:
return
if vol in self.extraVolumes:
del self.extraVolumes[vol]
return
if vol not in self.paths:
raise Exception("%s not in %s" % (vol, self))
p... | [
"def",
"_keepVol",
"(",
"self",
",",
"vol",
")",
":",
"if",
"vol",
"is",
"None",
":",
"return",
"if",
"vol",
"in",
"self",
".",
"extraVolumes",
":",
"del",
"self",
".",
"extraVolumes",
"[",
"vol",
"]",
"return",
"if",
"vol",
"not",
"in",
"self",
".... | Mark this volume to be kept in path. | [
"Mark",
"this",
"volume",
"to",
"be",
"kept",
"in",
"path",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ButterStore.py#L308-L326 | train | 61,439 |
AmesCornish/buttersink | buttersink/ioctl.py | Structure.write | def write(self, keyArgs):
""" Write specified key arguments into data structure. """
# bytearray doesn't work with fcntl
args = array.array('B', (0,) * self.size)
self._struct.pack_into(args, 0, *list(self.yieldArgs(keyArgs)))
return args | python | def write(self, keyArgs):
""" Write specified key arguments into data structure. """
# bytearray doesn't work with fcntl
args = array.array('B', (0,) * self.size)
self._struct.pack_into(args, 0, *list(self.yieldArgs(keyArgs)))
return args | [
"def",
"write",
"(",
"self",
",",
"keyArgs",
")",
":",
"# bytearray doesn't work with fcntl",
"args",
"=",
"array",
".",
"array",
"(",
"'B'",
",",
"(",
"0",
",",
")",
"*",
"self",
".",
"size",
")",
"self",
".",
"_struct",
".",
"pack_into",
"(",
"args",... | Write specified key arguments into data structure. | [
"Write",
"specified",
"key",
"arguments",
"into",
"data",
"structure",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ioctl.py#L222-L227 | train | 61,440 |
AmesCornish/buttersink | buttersink/ioctl.py | Structure.popValue | def popValue(self, argList):
""" Take a flat arglist, and pop relevent values and return as a value or tuple. """
# return self._Tuple(*[name for (name, typeObj) in self._types.items()])
return self._Tuple(*[typeObj.popValue(argList) for (name, typeObj) in self._types.items()]) | python | def popValue(self, argList):
""" Take a flat arglist, and pop relevent values and return as a value or tuple. """
# return self._Tuple(*[name for (name, typeObj) in self._types.items()])
return self._Tuple(*[typeObj.popValue(argList) for (name, typeObj) in self._types.items()]) | [
"def",
"popValue",
"(",
"self",
",",
"argList",
")",
":",
"# return self._Tuple(*[name for (name, typeObj) in self._types.items()])",
"return",
"self",
".",
"_Tuple",
"(",
"*",
"[",
"typeObj",
".",
"popValue",
"(",
"argList",
")",
"for",
"(",
"name",
",",
"typeObj... | Take a flat arglist, and pop relevent values and return as a value or tuple. | [
"Take",
"a",
"flat",
"arglist",
"and",
"pop",
"relevent",
"values",
"and",
"return",
"as",
"a",
"value",
"or",
"tuple",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ioctl.py#L229-L232 | train | 61,441 |
AmesCornish/buttersink | buttersink/ioctl.py | Buffer.read | def read(self, structure):
""" Read and advance. """
start = self.offset
self.skip(structure.size)
return structure.read(self.buf, start) | python | def read(self, structure):
""" Read and advance. """
start = self.offset
self.skip(structure.size)
return structure.read(self.buf, start) | [
"def",
"read",
"(",
"self",
",",
"structure",
")",
":",
"start",
"=",
"self",
".",
"offset",
"self",
".",
"skip",
"(",
"structure",
".",
"size",
")",
"return",
"structure",
".",
"read",
"(",
"self",
".",
"buf",
",",
"start",
")"
] | Read and advance. | [
"Read",
"and",
"advance",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ioctl.py#L259-L263 | train | 61,442 |
AmesCornish/buttersink | buttersink/ioctl.py | Buffer.readView | def readView(self, newLength=None):
""" Return a view of the next newLength bytes, and skip it. """
if newLength is None:
newLength = self.len
result = self.peekView(newLength)
self.skip(newLength)
return result | python | def readView(self, newLength=None):
""" Return a view of the next newLength bytes, and skip it. """
if newLength is None:
newLength = self.len
result = self.peekView(newLength)
self.skip(newLength)
return result | [
"def",
"readView",
"(",
"self",
",",
"newLength",
"=",
"None",
")",
":",
"if",
"newLength",
"is",
"None",
":",
"newLength",
"=",
"self",
".",
"len",
"result",
"=",
"self",
".",
"peekView",
"(",
"newLength",
")",
"self",
".",
"skip",
"(",
"newLength",
... | Return a view of the next newLength bytes, and skip it. | [
"Return",
"a",
"view",
"of",
"the",
"next",
"newLength",
"bytes",
"and",
"skip",
"it",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ioctl.py#L269-L275 | train | 61,443 |
AmesCornish/buttersink | buttersink/ioctl.py | Buffer.peekView | def peekView(self, newLength):
""" Return a view of the next newLength bytes. """
# Note: In Python 2.7, memoryviews can't be written to
# by the struct module. (BUG)
return memoryview(self.buf)[self.offset:self.offset + newLength] | python | def peekView(self, newLength):
""" Return a view of the next newLength bytes. """
# Note: In Python 2.7, memoryviews can't be written to
# by the struct module. (BUG)
return memoryview(self.buf)[self.offset:self.offset + newLength] | [
"def",
"peekView",
"(",
"self",
",",
"newLength",
")",
":",
"# Note: In Python 2.7, memoryviews can't be written to",
"# by the struct module. (BUG)",
"return",
"memoryview",
"(",
"self",
".",
"buf",
")",
"[",
"self",
".",
"offset",
":",
"self",
".",
"offset",
"+",
... | Return a view of the next newLength bytes. | [
"Return",
"a",
"view",
"of",
"the",
"next",
"newLength",
"bytes",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ioctl.py#L277-L281 | train | 61,444 |
AmesCornish/buttersink | buttersink/ioctl.py | Buffer.readBuffer | def readBuffer(self, newLength):
""" Read next chunk as another buffer. """
result = Buffer(self.buf, self.offset, newLength)
self.skip(newLength)
return result | python | def readBuffer(self, newLength):
""" Read next chunk as another buffer. """
result = Buffer(self.buf, self.offset, newLength)
self.skip(newLength)
return result | [
"def",
"readBuffer",
"(",
"self",
",",
"newLength",
")",
":",
"result",
"=",
"Buffer",
"(",
"self",
".",
"buf",
",",
"self",
".",
"offset",
",",
"newLength",
")",
"self",
".",
"skip",
"(",
"newLength",
")",
"return",
"result"
] | Read next chunk as another buffer. | [
"Read",
"next",
"chunk",
"as",
"another",
"buffer",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ioctl.py#L283-L287 | train | 61,445 |
AmesCornish/buttersink | buttersink/ioctl.py | Control._IOC | def _IOC(cls, dir, op, structure=None):
""" Encode an ioctl id. """
control = cls(dir, op, structure)
def do(dev, **args):
return control(dev, **args)
return do | python | def _IOC(cls, dir, op, structure=None):
""" Encode an ioctl id. """
control = cls(dir, op, structure)
def do(dev, **args):
return control(dev, **args)
return do | [
"def",
"_IOC",
"(",
"cls",
",",
"dir",
",",
"op",
",",
"structure",
"=",
"None",
")",
":",
"control",
"=",
"cls",
"(",
"dir",
",",
"op",
",",
"structure",
")",
"def",
"do",
"(",
"dev",
",",
"*",
"*",
"args",
")",
":",
"return",
"control",
"(",
... | Encode an ioctl id. | [
"Encode",
"an",
"ioctl",
"id",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ioctl.py#L337-L343 | train | 61,446 |
AmesCornish/buttersink | buttersink/ioctl.py | Control.IOWR | def IOWR(cls, op, structure):
""" Returns an ioctl Device method with READ and WRITE arguments. """
return cls._IOC(READ | WRITE, op, structure) | python | def IOWR(cls, op, structure):
""" Returns an ioctl Device method with READ and WRITE arguments. """
return cls._IOC(READ | WRITE, op, structure) | [
"def",
"IOWR",
"(",
"cls",
",",
"op",
",",
"structure",
")",
":",
"return",
"cls",
".",
"_IOC",
"(",
"READ",
"|",
"WRITE",
",",
"op",
",",
"structure",
")"
] | Returns an ioctl Device method with READ and WRITE arguments. | [
"Returns",
"an",
"ioctl",
"Device",
"method",
"with",
"READ",
"and",
"WRITE",
"arguments",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/ioctl.py#L356-L358 | train | 61,447 |
AmesCornish/buttersink | buttersink/btrfs.py | bytes2uuid | def bytes2uuid(b):
""" Return standard human-friendly UUID. """
if b.strip(chr(0)) == '':
return None
s = b.encode('hex')
return "%s-%s-%s-%s-%s" % (s[0:8], s[8:12], s[12:16], s[16:20], s[20:]) | python | def bytes2uuid(b):
""" Return standard human-friendly UUID. """
if b.strip(chr(0)) == '':
return None
s = b.encode('hex')
return "%s-%s-%s-%s-%s" % (s[0:8], s[8:12], s[12:16], s[16:20], s[20:]) | [
"def",
"bytes2uuid",
"(",
"b",
")",
":",
"if",
"b",
".",
"strip",
"(",
"chr",
"(",
"0",
")",
")",
"==",
"''",
":",
"return",
"None",
"s",
"=",
"b",
".",
"encode",
"(",
"'hex'",
")",
"return",
"\"%s-%s-%s-%s-%s\"",
"%",
"(",
"s",
"[",
"0",
":",
... | Return standard human-friendly UUID. | [
"Return",
"standard",
"human",
"-",
"friendly",
"UUID",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/btrfs.py#L24-L30 | train | 61,448 |
AmesCornish/buttersink | buttersink/btrfs.py | _Volume.fullPath | def fullPath(self):
""" Return full butter path from butter root. """
for ((dirTree, dirID, dirSeq), (dirPath, name)) in self.links.items():
try:
path = self.fileSystem.volumes[dirTree].fullPath
if path is not None:
return path + ("/" if pa... | python | def fullPath(self):
""" Return full butter path from butter root. """
for ((dirTree, dirID, dirSeq), (dirPath, name)) in self.links.items():
try:
path = self.fileSystem.volumes[dirTree].fullPath
if path is not None:
return path + ("/" if pa... | [
"def",
"fullPath",
"(",
"self",
")",
":",
"for",
"(",
"(",
"dirTree",
",",
"dirID",
",",
"dirSeq",
")",
",",
"(",
"dirPath",
",",
"name",
")",
")",
"in",
"self",
".",
"links",
".",
"items",
"(",
")",
":",
"try",
":",
"path",
"=",
"self",
".",
... | Return full butter path from butter root. | [
"Return",
"full",
"butter",
"path",
"from",
"butter",
"root",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/btrfs.py#L394-L407 | train | 61,449 |
AmesCornish/buttersink | buttersink/btrfs.py | _Volume.linuxPaths | def linuxPaths(self):
""" Return full paths from linux root.
The first path returned will be the path through the top-most mount.
(Usually the root).
"""
for ((dirTree, dirID, dirSeq), (dirPath, name)) in self.links.items():
for path in self.fileSystem.volumes[dirTre... | python | def linuxPaths(self):
""" Return full paths from linux root.
The first path returned will be the path through the top-most mount.
(Usually the root).
"""
for ((dirTree, dirID, dirSeq), (dirPath, name)) in self.links.items():
for path in self.fileSystem.volumes[dirTre... | [
"def",
"linuxPaths",
"(",
"self",
")",
":",
"for",
"(",
"(",
"dirTree",
",",
"dirID",
",",
"dirSeq",
")",
",",
"(",
"dirPath",
",",
"name",
")",
")",
"in",
"self",
".",
"links",
".",
"items",
"(",
")",
":",
"for",
"path",
"in",
"self",
".",
"fi... | Return full paths from linux root.
The first path returned will be the path through the top-most mount.
(Usually the root). | [
"Return",
"full",
"paths",
"from",
"linux",
"root",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/btrfs.py#L410-L420 | train | 61,450 |
AmesCornish/buttersink | buttersink/btrfs.py | _Volume.destroy | def destroy(self):
""" Delete this subvolume from the filesystem. """
path = next(iter(self.linuxPaths))
directory = _Directory(os.path.dirname(path))
with directory as device:
device.SNAP_DESTROY(name=str(os.path.basename(path)), ) | python | def destroy(self):
""" Delete this subvolume from the filesystem. """
path = next(iter(self.linuxPaths))
directory = _Directory(os.path.dirname(path))
with directory as device:
device.SNAP_DESTROY(name=str(os.path.basename(path)), ) | [
"def",
"destroy",
"(",
"self",
")",
":",
"path",
"=",
"next",
"(",
"iter",
"(",
"self",
".",
"linuxPaths",
")",
")",
"directory",
"=",
"_Directory",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
")",
"with",
"directory",
"as",
"device",
... | Delete this subvolume from the filesystem. | [
"Delete",
"this",
"subvolume",
"from",
"the",
"filesystem",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/btrfs.py#L446-L451 | train | 61,451 |
AmesCornish/buttersink | buttersink/btrfs.py | _Volume.copy | def copy(self, path):
""" Make another snapshot of this into dirName. """
directoryPath = os.path.dirname(path)
if not os.path.exists(directoryPath):
os.makedirs(directoryPath)
logger.debug('Create copy of %s in %s', os.path.basename(path), directoryPath)
with self.... | python | def copy(self, path):
""" Make another snapshot of this into dirName. """
directoryPath = os.path.dirname(path)
if not os.path.exists(directoryPath):
os.makedirs(directoryPath)
logger.debug('Create copy of %s in %s', os.path.basename(path), directoryPath)
with self.... | [
"def",
"copy",
"(",
"self",
",",
"path",
")",
":",
"directoryPath",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"directoryPath",
")",
":",
"os",
".",
"makedirs",
"(",
"directoryPath",
... | Make another snapshot of this into dirName. | [
"Make",
"another",
"snapshot",
"of",
"this",
"into",
"dirName",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/btrfs.py#L453-L479 | train | 61,452 |
AmesCornish/buttersink | buttersink/btrfs.py | FileSystem.subvolumes | def subvolumes(self):
""" Subvolumes contained in this mount. """
self.SYNC()
self._getDevices()
self._getRoots()
self._getMounts()
self._getUsage()
volumes = self.volumes.values()
volumes.sort(key=(lambda v: v.fullPath))
return volumes | python | def subvolumes(self):
""" Subvolumes contained in this mount. """
self.SYNC()
self._getDevices()
self._getRoots()
self._getMounts()
self._getUsage()
volumes = self.volumes.values()
volumes.sort(key=(lambda v: v.fullPath))
return volumes | [
"def",
"subvolumes",
"(",
"self",
")",
":",
"self",
".",
"SYNC",
"(",
")",
"self",
".",
"_getDevices",
"(",
")",
"self",
".",
"_getRoots",
"(",
")",
"self",
".",
"_getMounts",
"(",
")",
"self",
".",
"_getUsage",
"(",
")",
"volumes",
"=",
"self",
".... | Subvolumes contained in this mount. | [
"Subvolumes",
"contained",
"in",
"this",
"mount",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/btrfs.py#L515-L525 | train | 61,453 |
AmesCornish/buttersink | buttersink/btrfs.py | FileSystem._rescanSizes | def _rescanSizes(self, force=True):
""" Zero and recalculate quota sizes to subvolume sizes will be correct. """
status = self.QUOTA_CTL(cmd=BTRFS_QUOTA_CTL_ENABLE).status
logger.debug("CTL Status: %s", hex(status))
status = self.QUOTA_RESCAN_STATUS()
logger.debug("RESCAN Status... | python | def _rescanSizes(self, force=True):
""" Zero and recalculate quota sizes to subvolume sizes will be correct. """
status = self.QUOTA_CTL(cmd=BTRFS_QUOTA_CTL_ENABLE).status
logger.debug("CTL Status: %s", hex(status))
status = self.QUOTA_RESCAN_STATUS()
logger.debug("RESCAN Status... | [
"def",
"_rescanSizes",
"(",
"self",
",",
"force",
"=",
"True",
")",
":",
"status",
"=",
"self",
".",
"QUOTA_CTL",
"(",
"cmd",
"=",
"BTRFS_QUOTA_CTL_ENABLE",
")",
".",
"status",
"logger",
".",
"debug",
"(",
"\"CTL Status: %s\"",
",",
"hex",
"(",
"status",
... | Zero and recalculate quota sizes to subvolume sizes will be correct. | [
"Zero",
"and",
"recalculate",
"quota",
"sizes",
"to",
"subvolume",
"sizes",
"will",
"be",
"correct",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/btrfs.py#L527-L541 | train | 61,454 |
AmesCornish/buttersink | buttersink/send.py | TLV_GET | def TLV_GET(attrs, attrNum, format):
""" Get a tag-length-value encoded attribute. """
attrView = attrs[attrNum]
if format == 's':
format = str(attrView.len) + format
try:
(result,) = struct.unpack_from(format, attrView.buf, attrView.offset)
except TypeError:
# Working around... | python | def TLV_GET(attrs, attrNum, format):
""" Get a tag-length-value encoded attribute. """
attrView = attrs[attrNum]
if format == 's':
format = str(attrView.len) + format
try:
(result,) = struct.unpack_from(format, attrView.buf, attrView.offset)
except TypeError:
# Working around... | [
"def",
"TLV_GET",
"(",
"attrs",
",",
"attrNum",
",",
"format",
")",
":",
"attrView",
"=",
"attrs",
"[",
"attrNum",
"]",
"if",
"format",
"==",
"'s'",
":",
"format",
"=",
"str",
"(",
"attrView",
".",
"len",
")",
"+",
"format",
"try",
":",
"(",
"resul... | Get a tag-length-value encoded attribute. | [
"Get",
"a",
"tag",
"-",
"length",
"-",
"value",
"encoded",
"attribute",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/send.py#L127-L137 | train | 61,455 |
AmesCornish/buttersink | buttersink/send.py | TLV_PUT | def TLV_PUT(attrs, attrNum, format, value):
""" Put a tag-length-value encoded attribute. """
attrView = attrs[attrNum]
if format == 's':
format = str(attrView.len) + format
struct.pack_into(format, attrView.buf, attrView.offset, value) | python | def TLV_PUT(attrs, attrNum, format, value):
""" Put a tag-length-value encoded attribute. """
attrView = attrs[attrNum]
if format == 's':
format = str(attrView.len) + format
struct.pack_into(format, attrView.buf, attrView.offset, value) | [
"def",
"TLV_PUT",
"(",
"attrs",
",",
"attrNum",
",",
"format",
",",
"value",
")",
":",
"attrView",
"=",
"attrs",
"[",
"attrNum",
"]",
"if",
"format",
"==",
"'s'",
":",
"format",
"=",
"str",
"(",
"attrView",
".",
"len",
")",
"+",
"format",
"struct",
... | Put a tag-length-value encoded attribute. | [
"Put",
"a",
"tag",
"-",
"length",
"-",
"value",
"encoded",
"attribute",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/send.py#L140-L145 | train | 61,456 |
AmesCornish/buttersink | buttersink/SSHStore.py | command | def command(name, mode):
""" Label a method as a command with name. """
def decorator(fn):
commands[name] = fn.__name__
_Client._addMethod(fn.__name__, name, mode)
return fn
return decorator | python | def command(name, mode):
""" Label a method as a command with name. """
def decorator(fn):
commands[name] = fn.__name__
_Client._addMethod(fn.__name__, name, mode)
return fn
return decorator | [
"def",
"command",
"(",
"name",
",",
"mode",
")",
":",
"def",
"decorator",
"(",
"fn",
")",
":",
"commands",
"[",
"name",
"]",
"=",
"fn",
".",
"__name__",
"_Client",
".",
"_addMethod",
"(",
"fn",
".",
"__name__",
",",
"name",
",",
"mode",
")",
"retur... | Label a method as a command with name. | [
"Label",
"a",
"method",
"as",
"a",
"command",
"with",
"name",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L431-L437 | train | 61,457 |
AmesCornish/buttersink | buttersink/SSHStore.py | _Obj2Dict.diff | def diff(self, diff):
""" Serialize to a dictionary. """
if diff is None:
return None
return dict(
toVol=diff.toUUID,
fromVol=diff.fromUUID,
size=diff.size,
sizeIsEstimated=diff.sizeIsEstimated,
) | python | def diff(self, diff):
""" Serialize to a dictionary. """
if diff is None:
return None
return dict(
toVol=diff.toUUID,
fromVol=diff.fromUUID,
size=diff.size,
sizeIsEstimated=diff.sizeIsEstimated,
) | [
"def",
"diff",
"(",
"self",
",",
"diff",
")",
":",
"if",
"diff",
"is",
"None",
":",
"return",
"None",
"return",
"dict",
"(",
"toVol",
"=",
"diff",
".",
"toUUID",
",",
"fromVol",
"=",
"diff",
".",
"fromUUID",
",",
"size",
"=",
"diff",
".",
"size",
... | Serialize to a dictionary. | [
"Serialize",
"to",
"a",
"dictionary",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L74-L83 | train | 61,458 |
AmesCornish/buttersink | buttersink/SSHStore.py | _Client._open | def _open(self):
""" Open connection to remote host. """
if self._process is not None:
return
cmd = [
'ssh',
self._host,
'sudo',
'buttersink',
'--server',
'--mode',
self._mode,
self._dire... | python | def _open(self):
""" Open connection to remote host. """
if self._process is not None:
return
cmd = [
'ssh',
self._host,
'sudo',
'buttersink',
'--server',
'--mode',
self._mode,
self._dire... | [
"def",
"_open",
"(",
"self",
")",
":",
"if",
"self",
".",
"_process",
"is",
"not",
"None",
":",
"return",
"cmd",
"=",
"[",
"'ssh'",
",",
"self",
".",
"_host",
",",
"'sudo'",
",",
"'buttersink'",
",",
"'--server'",
",",
"'--mode'",
",",
"self",
".",
... | Open connection to remote host. | [
"Open",
"connection",
"to",
"remote",
"host",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L325-L350 | train | 61,459 |
AmesCornish/buttersink | buttersink/SSHStore.py | _Client._close | def _close(self):
""" Close connection to remote host. """
if self._process is None:
return
self.quit()
self._process.stdin.close()
logger.debug("Waiting for ssh process to finish...")
self._process.wait() # Wait for ssh session to finish.
# self.... | python | def _close(self):
""" Close connection to remote host. """
if self._process is None:
return
self.quit()
self._process.stdin.close()
logger.debug("Waiting for ssh process to finish...")
self._process.wait() # Wait for ssh session to finish.
# self.... | [
"def",
"_close",
"(",
"self",
")",
":",
"if",
"self",
".",
"_process",
"is",
"None",
":",
"return",
"self",
".",
"quit",
"(",
")",
"self",
".",
"_process",
".",
"stdin",
".",
"close",
"(",
")",
"logger",
".",
"debug",
"(",
"\"Waiting for ssh process to... | Close connection to remote host. | [
"Close",
"connection",
"to",
"remote",
"host",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L352-L367 | train | 61,460 |
AmesCornish/buttersink | buttersink/SSHStore.py | StoreProxyServer.run | def run(self):
""" Run the server. Returns with system error code. """
normalized = os.path.normpath(self.path) + ("/" if self.path.endswith("/") else "")
if self.path != normalized:
sys.stderr.write("Please use full path '%s'" % (normalized,))
return -1
self.bu... | python | def run(self):
""" Run the server. Returns with system error code. """
normalized = os.path.normpath(self.path) + ("/" if self.path.endswith("/") else "")
if self.path != normalized:
sys.stderr.write("Please use full path '%s'" % (normalized,))
return -1
self.bu... | [
"def",
"run",
"(",
"self",
")",
":",
"normalized",
"=",
"os",
".",
"path",
".",
"normpath",
"(",
"self",
".",
"path",
")",
"+",
"(",
"\"/\"",
"if",
"self",
".",
"path",
".",
"endswith",
"(",
"\"/\"",
")",
"else",
"\"\"",
")",
"if",
"self",
".",
... | Run the server. Returns with system error code. | [
"Run",
"the",
"server",
".",
"Returns",
"with",
"system",
"error",
"code",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L488-L508 | train | 61,461 |
AmesCornish/buttersink | buttersink/SSHStore.py | StoreProxyServer._sendResult | def _sendResult(self, result):
""" Send parseable json result of command. """
# logger.debug("Result: %s", result)
try:
result = json.dumps(result)
except Exception as error:
result = json.dumps(self._errorInfo(command, error))
sys.stdout.write(result)
... | python | def _sendResult(self, result):
""" Send parseable json result of command. """
# logger.debug("Result: %s", result)
try:
result = json.dumps(result)
except Exception as error:
result = json.dumps(self._errorInfo(command, error))
sys.stdout.write(result)
... | [
"def",
"_sendResult",
"(",
"self",
",",
"result",
")",
":",
"# logger.debug(\"Result: %s\", result)",
"try",
":",
"result",
"=",
"json",
".",
"dumps",
"(",
"result",
")",
"except",
"Exception",
"as",
"error",
":",
"result",
"=",
"json",
".",
"dumps",
"(",
... | Send parseable json result of command. | [
"Send",
"parseable",
"json",
"result",
"of",
"command",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L525-L536 | train | 61,462 |
AmesCornish/buttersink | buttersink/SSHStore.py | StoreProxyServer.version | def version(self):
""" Return kernel and btrfs version. """
return dict(
buttersink=theVersion,
btrfs=self.butterStore.butter.btrfsVersion,
linux=platform.platform(),
) | python | def version(self):
""" Return kernel and btrfs version. """
return dict(
buttersink=theVersion,
btrfs=self.butterStore.butter.btrfsVersion,
linux=platform.platform(),
) | [
"def",
"version",
"(",
"self",
")",
":",
"return",
"dict",
"(",
"buttersink",
"=",
"theVersion",
",",
"btrfs",
"=",
"self",
".",
"butterStore",
".",
"butter",
".",
"btrfsVersion",
",",
"linux",
"=",
"platform",
".",
"platform",
"(",
")",
",",
")"
] | Return kernel and btrfs version. | [
"Return",
"kernel",
"and",
"btrfs",
"version",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L577-L583 | train | 61,463 |
AmesCornish/buttersink | buttersink/SSHStore.py | StoreProxyServer.send | def send(self, diffTo, diffFrom):
""" Do a btrfs send. """
diff = self.toObj.diff(diffTo, diffFrom)
self._open(self.butterStore.send(diff)) | python | def send(self, diffTo, diffFrom):
""" Do a btrfs send. """
diff = self.toObj.diff(diffTo, diffFrom)
self._open(self.butterStore.send(diff)) | [
"def",
"send",
"(",
"self",
",",
"diffTo",
",",
"diffFrom",
")",
":",
"diff",
"=",
"self",
".",
"toObj",
".",
"diff",
"(",
"diffTo",
",",
"diffFrom",
")",
"self",
".",
"_open",
"(",
"self",
".",
"butterStore",
".",
"send",
"(",
"diff",
")",
")"
] | Do a btrfs send. | [
"Do",
"a",
"btrfs",
"send",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L586-L589 | train | 61,464 |
AmesCornish/buttersink | buttersink/SSHStore.py | StoreProxyServer.receive | def receive(self, path, diffTo, diffFrom):
""" Receive a btrfs diff. """
diff = self.toObj.diff(diffTo, diffFrom)
self._open(self.butterStore.receive(diff, [path, ])) | python | def receive(self, path, diffTo, diffFrom):
""" Receive a btrfs diff. """
diff = self.toObj.diff(diffTo, diffFrom)
self._open(self.butterStore.receive(diff, [path, ])) | [
"def",
"receive",
"(",
"self",
",",
"path",
",",
"diffTo",
",",
"diffFrom",
")",
":",
"diff",
"=",
"self",
".",
"toObj",
".",
"diff",
"(",
"diffTo",
",",
"diffFrom",
")",
"self",
".",
"_open",
"(",
"self",
".",
"butterStore",
".",
"receive",
"(",
"... | Receive a btrfs diff. | [
"Receive",
"a",
"btrfs",
"diff",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L592-L595 | train | 61,465 |
AmesCornish/buttersink | buttersink/SSHStore.py | StoreProxyServer.fillVolumesAndPaths | def fillVolumesAndPaths(self):
""" Get all volumes for initialization. """
return [
(self.toDict.vol(vol), paths)
for vol, paths in self.butterStore.paths.items()
] | python | def fillVolumesAndPaths(self):
""" Get all volumes for initialization. """
return [
(self.toDict.vol(vol), paths)
for vol, paths in self.butterStore.paths.items()
] | [
"def",
"fillVolumesAndPaths",
"(",
"self",
")",
":",
"return",
"[",
"(",
"self",
".",
"toDict",
".",
"vol",
"(",
"vol",
")",
",",
"paths",
")",
"for",
"vol",
",",
"paths",
"in",
"self",
".",
"butterStore",
".",
"paths",
".",
"items",
"(",
")",
"]"
... | Get all volumes for initialization. | [
"Get",
"all",
"volumes",
"for",
"initialization",
"."
] | 5cc37e30d9f8071fcf3497dca8b8a91b910321ea | https://github.com/AmesCornish/buttersink/blob/5cc37e30d9f8071fcf3497dca8b8a91b910321ea/buttersink/SSHStore.py#L629-L634 | train | 61,466 |
brennv/namedtupled | namedtupled/integrations.py | load_lists | def load_lists(keys=[], values=[], name='NT'):
""" Map namedtuples given a pair of key, value lists. """
mapping = dict(zip(keys, values))
return mapper(mapping, _nt_name=name) | python | def load_lists(keys=[], values=[], name='NT'):
""" Map namedtuples given a pair of key, value lists. """
mapping = dict(zip(keys, values))
return mapper(mapping, _nt_name=name) | [
"def",
"load_lists",
"(",
"keys",
"=",
"[",
"]",
",",
"values",
"=",
"[",
"]",
",",
"name",
"=",
"'NT'",
")",
":",
"mapping",
"=",
"dict",
"(",
"zip",
"(",
"keys",
",",
"values",
")",
")",
"return",
"mapper",
"(",
"mapping",
",",
"_nt_name",
"=",... | Map namedtuples given a pair of key, value lists. | [
"Map",
"namedtuples",
"given",
"a",
"pair",
"of",
"key",
"value",
"lists",
"."
] | 2b8e3bafd82835ef01549d7a266c34454637ff70 | https://github.com/brennv/namedtupled/blob/2b8e3bafd82835ef01549d7a266c34454637ff70/namedtupled/integrations.py#L8-L11 | train | 61,467 |
brennv/namedtupled | namedtupled/integrations.py | load_json | def load_json(data=None, path=None, name='NT'):
""" Map namedtuples with json data. """
if data and not path:
return mapper(json.loads(data), _nt_name=name)
if path and not data:
return mapper(json.load(path), _nt_name=name)
if data and path:
raise ValueError('expected one source... | python | def load_json(data=None, path=None, name='NT'):
""" Map namedtuples with json data. """
if data and not path:
return mapper(json.loads(data), _nt_name=name)
if path and not data:
return mapper(json.load(path), _nt_name=name)
if data and path:
raise ValueError('expected one source... | [
"def",
"load_json",
"(",
"data",
"=",
"None",
",",
"path",
"=",
"None",
",",
"name",
"=",
"'NT'",
")",
":",
"if",
"data",
"and",
"not",
"path",
":",
"return",
"mapper",
"(",
"json",
".",
"loads",
"(",
"data",
")",
",",
"_nt_name",
"=",
"name",
")... | Map namedtuples with json data. | [
"Map",
"namedtuples",
"with",
"json",
"data",
"."
] | 2b8e3bafd82835ef01549d7a266c34454637ff70 | https://github.com/brennv/namedtupled/blob/2b8e3bafd82835ef01549d7a266c34454637ff70/namedtupled/integrations.py#L14-L21 | train | 61,468 |
brennv/namedtupled | namedtupled/integrations.py | load_yaml | def load_yaml(data=None, path=None, name='NT'):
""" Map namedtuples with yaml data. """
if data and not path:
return mapper(yaml.load(data), _nt_name=name)
if path and not data:
with open(path, 'r') as f:
data = yaml.load(f)
return mapper(data, _nt_name=name)
if data ... | python | def load_yaml(data=None, path=None, name='NT'):
""" Map namedtuples with yaml data. """
if data and not path:
return mapper(yaml.load(data), _nt_name=name)
if path and not data:
with open(path, 'r') as f:
data = yaml.load(f)
return mapper(data, _nt_name=name)
if data ... | [
"def",
"load_yaml",
"(",
"data",
"=",
"None",
",",
"path",
"=",
"None",
",",
"name",
"=",
"'NT'",
")",
":",
"if",
"data",
"and",
"not",
"path",
":",
"return",
"mapper",
"(",
"yaml",
".",
"load",
"(",
"data",
")",
",",
"_nt_name",
"=",
"name",
")"... | Map namedtuples with yaml data. | [
"Map",
"namedtuples",
"with",
"yaml",
"data",
"."
] | 2b8e3bafd82835ef01549d7a266c34454637ff70 | https://github.com/brennv/namedtupled/blob/2b8e3bafd82835ef01549d7a266c34454637ff70/namedtupled/integrations.py#L24-L33 | train | 61,469 |
brennv/namedtupled | namedtupled/namedtupled.py | mapper | def mapper(mapping, _nt_name='NT'):
""" Convert mappings to namedtuples recursively. """
if isinstance(mapping, Mapping) and not isinstance(mapping, AsDict):
for key, value in list(mapping.items()):
mapping[key] = mapper(value)
return namedtuple_wrapper(_nt_name, **mapping)
elif ... | python | def mapper(mapping, _nt_name='NT'):
""" Convert mappings to namedtuples recursively. """
if isinstance(mapping, Mapping) and not isinstance(mapping, AsDict):
for key, value in list(mapping.items()):
mapping[key] = mapper(value)
return namedtuple_wrapper(_nt_name, **mapping)
elif ... | [
"def",
"mapper",
"(",
"mapping",
",",
"_nt_name",
"=",
"'NT'",
")",
":",
"if",
"isinstance",
"(",
"mapping",
",",
"Mapping",
")",
"and",
"not",
"isinstance",
"(",
"mapping",
",",
"AsDict",
")",
":",
"for",
"key",
",",
"value",
"in",
"list",
"(",
"map... | Convert mappings to namedtuples recursively. | [
"Convert",
"mappings",
"to",
"namedtuples",
"recursively",
"."
] | 2b8e3bafd82835ef01549d7a266c34454637ff70 | https://github.com/brennv/namedtupled/blob/2b8e3bafd82835ef01549d7a266c34454637ff70/namedtupled/namedtupled.py#L6-L14 | train | 61,470 |
brennv/namedtupled | namedtupled/namedtupled.py | ignore | def ignore(mapping):
""" Use ignore to prevent a mapping from being mapped to a namedtuple. """
if isinstance(mapping, Mapping):
return AsDict(mapping)
elif isinstance(mapping, list):
return [ignore(item) for item in mapping]
return mapping | python | def ignore(mapping):
""" Use ignore to prevent a mapping from being mapped to a namedtuple. """
if isinstance(mapping, Mapping):
return AsDict(mapping)
elif isinstance(mapping, list):
return [ignore(item) for item in mapping]
return mapping | [
"def",
"ignore",
"(",
"mapping",
")",
":",
"if",
"isinstance",
"(",
"mapping",
",",
"Mapping",
")",
":",
"return",
"AsDict",
"(",
"mapping",
")",
"elif",
"isinstance",
"(",
"mapping",
",",
"list",
")",
":",
"return",
"[",
"ignore",
"(",
"item",
")",
... | Use ignore to prevent a mapping from being mapped to a namedtuple. | [
"Use",
"ignore",
"to",
"prevent",
"a",
"mapping",
"from",
"being",
"mapped",
"to",
"a",
"namedtuple",
"."
] | 2b8e3bafd82835ef01549d7a266c34454637ff70 | https://github.com/brennv/namedtupled/blob/2b8e3bafd82835ef01549d7a266c34454637ff70/namedtupled/namedtupled.py#L26-L32 | train | 61,471 |
mongolab/mongoctl | mongoctl/utils.py | ensure_dir | def ensure_dir(dir_path):
"""
If DIR_PATH does not exist, makes it. Failing that, raises Exception.
Returns True if dir already existed; False if it had to be made.
"""
exists = dir_exists(dir_path)
if not exists:
try:
os.makedirs(dir_path)
except(Exception,RuntimeErr... | python | def ensure_dir(dir_path):
"""
If DIR_PATH does not exist, makes it. Failing that, raises Exception.
Returns True if dir already existed; False if it had to be made.
"""
exists = dir_exists(dir_path)
if not exists:
try:
os.makedirs(dir_path)
except(Exception,RuntimeErr... | [
"def",
"ensure_dir",
"(",
"dir_path",
")",
":",
"exists",
"=",
"dir_exists",
"(",
"dir_path",
")",
"if",
"not",
"exists",
":",
"try",
":",
"os",
".",
"makedirs",
"(",
"dir_path",
")",
"except",
"(",
"Exception",
",",
"RuntimeError",
")",
",",
"e",
":",... | If DIR_PATH does not exist, makes it. Failing that, raises Exception.
Returns True if dir already existed; False if it had to be made. | [
"If",
"DIR_PATH",
"does",
"not",
"exist",
"makes",
"it",
".",
"Failing",
"that",
"raises",
"Exception",
".",
"Returns",
"True",
"if",
"dir",
"already",
"existed",
";",
"False",
"if",
"it",
"had",
"to",
"be",
"made",
"."
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/utils.py#L97-L109 | train | 61,472 |
mongolab/mongoctl | mongoctl/utils.py | validate_openssl | def validate_openssl():
"""
Validates OpenSSL to ensure it has TLS_FALLBACK_SCSV supported
"""
try:
open_ssl_exe = which("openssl")
if not open_ssl_exe:
raise Exception("No openssl exe found in path")
try:
# execute a an invalid command to get output ... | python | def validate_openssl():
"""
Validates OpenSSL to ensure it has TLS_FALLBACK_SCSV supported
"""
try:
open_ssl_exe = which("openssl")
if not open_ssl_exe:
raise Exception("No openssl exe found in path")
try:
# execute a an invalid command to get output ... | [
"def",
"validate_openssl",
"(",
")",
":",
"try",
":",
"open_ssl_exe",
"=",
"which",
"(",
"\"openssl\"",
")",
"if",
"not",
"open_ssl_exe",
":",
"raise",
"Exception",
"(",
"\"No openssl exe found in path\"",
")",
"try",
":",
"# execute a an invalid command to get output... | Validates OpenSSL to ensure it has TLS_FALLBACK_SCSV supported | [
"Validates",
"OpenSSL",
"to",
"ensure",
"it",
"has",
"TLS_FALLBACK_SCSV",
"supported"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/utils.py#L366-L383 | train | 61,473 |
mongolab/mongoctl | mongoctl/objects/replicaset_cluster.py | ReplicaSetClusterMember.validate_against_current_config | def validate_against_current_config(self, current_rs_conf):
"""
Validates the member document against current rs conf
1- If there is a member in current config with _id equals to my id
then ensure hosts addresses resolve to the same host
2- If there is a member i... | python | def validate_against_current_config(self, current_rs_conf):
"""
Validates the member document against current rs conf
1- If there is a member in current config with _id equals to my id
then ensure hosts addresses resolve to the same host
2- If there is a member i... | [
"def",
"validate_against_current_config",
"(",
"self",
",",
"current_rs_conf",
")",
":",
"# if rs is not configured yet then there is nothing to validate",
"if",
"not",
"current_rs_conf",
":",
"return",
"my_host",
"=",
"self",
".",
"get_host",
"(",
")",
"current_member_conf... | Validates the member document against current rs conf
1- If there is a member in current config with _id equals to my id
then ensure hosts addresses resolve to the same host
2- If there is a member in current config with host resolving to my
host then ensure that ... | [
"Validates",
"the",
"member",
"document",
"against",
"current",
"rs",
"conf",
"1",
"-",
"If",
"there",
"is",
"a",
"member",
"in",
"current",
"config",
"with",
"_id",
"equals",
"to",
"my",
"id",
"then",
"ensure",
"hosts",
"addresses",
"resolve",
"to",
"the"... | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/objects/replicaset_cluster.py#L179-L221 | train | 61,474 |
mongolab/mongoctl | mongoctl/objects/replicaset_cluster.py | ReplicaSetCluster.get_dump_best_secondary | def get_dump_best_secondary(self, max_repl_lag=None):
"""
Returns the best secondary member to be used for dumping
best = passives with least lags, if no passives then least lag
"""
secondary_lag_tuples = []
primary_member = self.get_primary_member()
if not prima... | python | def get_dump_best_secondary(self, max_repl_lag=None):
"""
Returns the best secondary member to be used for dumping
best = passives with least lags, if no passives then least lag
"""
secondary_lag_tuples = []
primary_member = self.get_primary_member()
if not prima... | [
"def",
"get_dump_best_secondary",
"(",
"self",
",",
"max_repl_lag",
"=",
"None",
")",
":",
"secondary_lag_tuples",
"=",
"[",
"]",
"primary_member",
"=",
"self",
".",
"get_primary_member",
"(",
")",
"if",
"not",
"primary_member",
":",
"raise",
"MongoctlException",
... | Returns the best secondary member to be used for dumping
best = passives with least lags, if no passives then least lag | [
"Returns",
"the",
"best",
"secondary",
"member",
"to",
"be",
"used",
"for",
"dumping",
"best",
"=",
"passives",
"with",
"least",
"lags",
"if",
"no",
"passives",
"then",
"least",
"lag"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/objects/replicaset_cluster.py#L377-L422 | train | 61,475 |
mongolab/mongoctl | mongoctl/objects/replicaset_cluster.py | ReplicaSetCluster.is_replicaset_initialized | def is_replicaset_initialized(self):
"""
iterate on all members and check if any has joined the replica
"""
# it's possible isMaster returns an "incomplete" result if we
# query a replica set member while it's loading the replica set config
# https://jira.mongodb.org/bro... | python | def is_replicaset_initialized(self):
"""
iterate on all members and check if any has joined the replica
"""
# it's possible isMaster returns an "incomplete" result if we
# query a replica set member while it's loading the replica set config
# https://jira.mongodb.org/bro... | [
"def",
"is_replicaset_initialized",
"(",
"self",
")",
":",
"# it's possible isMaster returns an \"incomplete\" result if we",
"# query a replica set member while it's loading the replica set config",
"# https://jira.mongodb.org/browse/SERVER-13458",
"# let's try to detect this state before proceed... | iterate on all members and check if any has joined the replica | [
"iterate",
"on",
"all",
"members",
"and",
"check",
"if",
"any",
"has",
"joined",
"the",
"replica"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/objects/replicaset_cluster.py#L425-L444 | train | 61,476 |
mongolab/mongoctl | mongoctl/objects/replicaset_cluster.py | ReplicaSetCluster.match_member_id | def match_member_id(self, member_conf, current_member_confs):
"""
Attempts to find an id for member_conf where fom current members confs
there exists a element.
Returns the id of an element of current confs
WHERE member_conf.host and element.host are EQUAL or map to same host
... | python | def match_member_id(self, member_conf, current_member_confs):
"""
Attempts to find an id for member_conf where fom current members confs
there exists a element.
Returns the id of an element of current confs
WHERE member_conf.host and element.host are EQUAL or map to same host
... | [
"def",
"match_member_id",
"(",
"self",
",",
"member_conf",
",",
"current_member_confs",
")",
":",
"if",
"current_member_confs",
"is",
"None",
":",
"return",
"None",
"for",
"curr_mem_conf",
"in",
"current_member_confs",
":",
"if",
"is_same_address",
"(",
"member_conf... | Attempts to find an id for member_conf where fom current members confs
there exists a element.
Returns the id of an element of current confs
WHERE member_conf.host and element.host are EQUAL or map to same host | [
"Attempts",
"to",
"find",
"an",
"id",
"for",
"member_conf",
"where",
"fom",
"current",
"members",
"confs",
"there",
"exists",
"a",
"element",
".",
"Returns",
"the",
"id",
"of",
"an",
"element",
"of",
"current",
"confs",
"WHERE",
"member_conf",
".",
"host",
... | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/objects/replicaset_cluster.py#L763-L777 | train | 61,477 |
mongolab/mongoctl | mongoctl/binary_repo.py | get_os_dist_info | def get_os_dist_info():
"""
Returns the distribution info
"""
distribution = platform.dist()
dist_name = distribution[0].lower()
dist_version_str = distribution[1]
if dist_name and dist_version_str:
return dist_name, dist_version_str
else:
return None, None | python | def get_os_dist_info():
"""
Returns the distribution info
"""
distribution = platform.dist()
dist_name = distribution[0].lower()
dist_version_str = distribution[1]
if dist_name and dist_version_str:
return dist_name, dist_version_str
else:
return None, None | [
"def",
"get_os_dist_info",
"(",
")",
":",
"distribution",
"=",
"platform",
".",
"dist",
"(",
")",
"dist_name",
"=",
"distribution",
"[",
"0",
"]",
".",
"lower",
"(",
")",
"dist_version_str",
"=",
"distribution",
"[",
"1",
"]",
"if",
"dist_name",
"and",
"... | Returns the distribution info | [
"Returns",
"the",
"distribution",
"info"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/binary_repo.py#L442-L453 | train | 61,478 |
mongolab/mongoctl | mongoctl/objects/server.py | Server.get_mongo_version | def get_mongo_version(self):
"""
Gets mongo version of the server if it is running. Otherwise return
version configured in mongoVersion property
"""
if self._mongo_version:
return self._mongo_version
mongo_version = self.read_current_mongo_version()
... | python | def get_mongo_version(self):
"""
Gets mongo version of the server if it is running. Otherwise return
version configured in mongoVersion property
"""
if self._mongo_version:
return self._mongo_version
mongo_version = self.read_current_mongo_version()
... | [
"def",
"get_mongo_version",
"(",
"self",
")",
":",
"if",
"self",
".",
"_mongo_version",
":",
"return",
"self",
".",
"_mongo_version",
"mongo_version",
"=",
"self",
".",
"read_current_mongo_version",
"(",
")",
"if",
"not",
"mongo_version",
":",
"mongo_version",
"... | Gets mongo version of the server if it is running. Otherwise return
version configured in mongoVersion property | [
"Gets",
"mongo",
"version",
"of",
"the",
"server",
"if",
"it",
"is",
"running",
".",
"Otherwise",
"return",
"version",
"configured",
"in",
"mongoVersion",
"property"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/objects/server.py#L258-L273 | train | 61,479 |
mongolab/mongoctl | mongoctl/objects/server.py | Server.get_server_build_info | def get_server_build_info(self):
"""
issues a buildinfo command
"""
if self.is_online():
try:
return self.get_mongo_client().server_info()
except OperationFailure, ofe:
log_exception(ofe)
if "there are no users authe... | python | def get_server_build_info(self):
"""
issues a buildinfo command
"""
if self.is_online():
try:
return self.get_mongo_client().server_info()
except OperationFailure, ofe:
log_exception(ofe)
if "there are no users authe... | [
"def",
"get_server_build_info",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_online",
"(",
")",
":",
"try",
":",
"return",
"self",
".",
"get_mongo_client",
"(",
")",
".",
"server_info",
"(",
")",
"except",
"OperationFailure",
",",
"ofe",
":",
"log_excepti... | issues a buildinfo command | [
"issues",
"a",
"buildinfo",
"command"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/objects/server.py#L290-L307 | train | 61,480 |
mongolab/mongoctl | mongoctl/objects/server.py | Server.authenticate_db | def authenticate_db(self, db, dbname, retry=True):
"""
Returns True if we manage to auth to the given db, else False.
"""
log_verbose("Server '%s' attempting to authenticate to db '%s'" % (self.id, dbname))
login_user = self.get_login_user(dbname)
username = None
... | python | def authenticate_db(self, db, dbname, retry=True):
"""
Returns True if we manage to auth to the given db, else False.
"""
log_verbose("Server '%s' attempting to authenticate to db '%s'" % (self.id, dbname))
login_user = self.get_login_user(dbname)
username = None
... | [
"def",
"authenticate_db",
"(",
"self",
",",
"db",
",",
"dbname",
",",
"retry",
"=",
"True",
")",
":",
"log_verbose",
"(",
"\"Server '%s' attempting to authenticate to db '%s'\"",
"%",
"(",
"self",
".",
"id",
",",
"dbname",
")",
")",
"login_user",
"=",
"self",
... | Returns True if we manage to auth to the given db, else False. | [
"Returns",
"True",
"if",
"we",
"manage",
"to",
"auth",
"to",
"the",
"given",
"db",
"else",
"False",
"."
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/objects/server.py#L619-L671 | train | 61,481 |
mongolab/mongoctl | mongoctl/objects/server.py | Server.needs_repl_key | def needs_repl_key(self):
"""
We need a repl key if you are auth + a cluster member +
version is None or >= 2.0.0
"""
cluster = self.get_cluster()
return (self.supports_repl_key() and
cluster is not None and cluster.get_repl_key() is not None) | python | def needs_repl_key(self):
"""
We need a repl key if you are auth + a cluster member +
version is None or >= 2.0.0
"""
cluster = self.get_cluster()
return (self.supports_repl_key() and
cluster is not None and cluster.get_repl_key() is not None) | [
"def",
"needs_repl_key",
"(",
"self",
")",
":",
"cluster",
"=",
"self",
".",
"get_cluster",
"(",
")",
"return",
"(",
"self",
".",
"supports_repl_key",
"(",
")",
"and",
"cluster",
"is",
"not",
"None",
"and",
"cluster",
".",
"get_repl_key",
"(",
")",
"is",... | We need a repl key if you are auth + a cluster member +
version is None or >= 2.0.0 | [
"We",
"need",
"a",
"repl",
"key",
"if",
"you",
"are",
"auth",
"+",
"a",
"cluster",
"member",
"+",
"version",
"is",
"None",
"or",
">",
"=",
"2",
".",
"0",
".",
"0"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/objects/server.py#L1003-L1010 | train | 61,482 |
mongolab/mongoctl | mongoctl/commands/command_utils.py | exact_or_minor_exe_version_match | def exact_or_minor_exe_version_match(executable_name,
exe_version_tuples,
version):
"""
IF there is an exact match then use it
OTHERWISE try to find a minor version match
"""
exe = exact_exe_version_match(executable_name,
... | python | def exact_or_minor_exe_version_match(executable_name,
exe_version_tuples,
version):
"""
IF there is an exact match then use it
OTHERWISE try to find a minor version match
"""
exe = exact_exe_version_match(executable_name,
... | [
"def",
"exact_or_minor_exe_version_match",
"(",
"executable_name",
",",
"exe_version_tuples",
",",
"version",
")",
":",
"exe",
"=",
"exact_exe_version_match",
"(",
"executable_name",
",",
"exe_version_tuples",
",",
"version",
")",
"if",
"not",
"exe",
":",
"exe",
"="... | IF there is an exact match then use it
OTHERWISE try to find a minor version match | [
"IF",
"there",
"is",
"an",
"exact",
"match",
"then",
"use",
"it",
"OTHERWISE",
"try",
"to",
"find",
"a",
"minor",
"version",
"match"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/commands/command_utils.py#L231-L246 | train | 61,483 |
jgillick/python-pause | pause/__init__.py | seconds | def seconds(num):
"""
Pause for this many seconds
"""
now = pytime.time()
end = now + num
until(end) | python | def seconds(num):
"""
Pause for this many seconds
"""
now = pytime.time()
end = now + num
until(end) | [
"def",
"seconds",
"(",
"num",
")",
":",
"now",
"=",
"pytime",
".",
"time",
"(",
")",
"end",
"=",
"now",
"+",
"num",
"until",
"(",
"end",
")"
] | Pause for this many seconds | [
"Pause",
"for",
"this",
"many",
"seconds"
] | ac53175b19693ac8e89b874443a29662eb0c15d5 | https://github.com/jgillick/python-pause/blob/ac53175b19693ac8e89b874443a29662eb0c15d5/pause/__init__.py#L75-L81 | train | 61,484 |
mongolab/mongoctl | mongoctl/commands/server/start.py | _pre_mongod_server_start | def _pre_mongod_server_start(server, options_override=None):
"""
Does necessary work before starting a server
1- An efficiency step for arbiters running with --no-journal
* there is a lock file ==>
* server must not have exited cleanly from last run, and does not know
how to auto-... | python | def _pre_mongod_server_start(server, options_override=None):
"""
Does necessary work before starting a server
1- An efficiency step for arbiters running with --no-journal
* there is a lock file ==>
* server must not have exited cleanly from last run, and does not know
how to auto-... | [
"def",
"_pre_mongod_server_start",
"(",
"server",
",",
"options_override",
"=",
"None",
")",
":",
"lock_file_path",
"=",
"server",
".",
"get_lock_file_path",
"(",
")",
"no_journal",
"=",
"(",
"server",
".",
"get_cmd_option",
"(",
"\"nojournal\"",
")",
"or",
"(",... | Does necessary work before starting a server
1- An efficiency step for arbiters running with --no-journal
* there is a lock file ==>
* server must not have exited cleanly from last run, and does not know
how to auto-recover (as a journalled server would)
* however: this is an arb... | [
"Does",
"necessary",
"work",
"before",
"starting",
"a",
"server"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/commands/server/start.py#L191-L221 | train | 61,485 |
mongolab/mongoctl | mongoctl/commands/server/start.py | prepare_mongod_server | def prepare_mongod_server(server):
"""
Contains post start server operations
"""
log_info("Preparing server '%s' for use as configured..." %
server.id)
cluster = server.get_cluster()
# setup the local users if server supports that
if server.supports_local_users():
user... | python | def prepare_mongod_server(server):
"""
Contains post start server operations
"""
log_info("Preparing server '%s' for use as configured..." %
server.id)
cluster = server.get_cluster()
# setup the local users if server supports that
if server.supports_local_users():
user... | [
"def",
"prepare_mongod_server",
"(",
"server",
")",
":",
"log_info",
"(",
"\"Preparing server '%s' for use as configured...\"",
"%",
"server",
".",
"id",
")",
"cluster",
"=",
"server",
".",
"get_cluster",
"(",
")",
"# setup the local users if server supports that",
"if",
... | Contains post start server operations | [
"Contains",
"post",
"start",
"server",
"operations"
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/commands/server/start.py#L254-L270 | train | 61,486 |
mongolab/mongoctl | mongoctl/commands/server/start.py | _rlimit_min | def _rlimit_min(one_val, nother_val):
"""Returns the more stringent rlimit value. -1 means no limit."""
if one_val < 0 or nother_val < 0 :
return max(one_val, nother_val)
else:
return min(one_val, nother_val) | python | def _rlimit_min(one_val, nother_val):
"""Returns the more stringent rlimit value. -1 means no limit."""
if one_val < 0 or nother_val < 0 :
return max(one_val, nother_val)
else:
return min(one_val, nother_val) | [
"def",
"_rlimit_min",
"(",
"one_val",
",",
"nother_val",
")",
":",
"if",
"one_val",
"<",
"0",
"or",
"nother_val",
"<",
"0",
":",
"return",
"max",
"(",
"one_val",
",",
"nother_val",
")",
"else",
":",
"return",
"min",
"(",
"one_val",
",",
"nother_val",
"... | Returns the more stringent rlimit value. -1 means no limit. | [
"Returns",
"the",
"more",
"stringent",
"rlimit",
"value",
".",
"-",
"1",
"means",
"no",
"limit",
"."
] | fab15216127ad4bf8ea9aa8a95d75504c0ef01a2 | https://github.com/mongolab/mongoctl/blob/fab15216127ad4bf8ea9aa8a95d75504c0ef01a2/mongoctl/commands/server/start.py#L492-L497 | train | 61,487 |
openwisp/netdiff | netdiff/parsers/netjson.py | NetJsonParser.parse | def parse(self, data):
"""
Converts a NetJSON 'NetworkGraph' object
to a NetworkX Graph object,which is then returned.
Additionally checks for protocol version, revision and metric.
"""
graph = self._init_graph()
# ensure is NetJSON NetworkGraph object
if ... | python | def parse(self, data):
"""
Converts a NetJSON 'NetworkGraph' object
to a NetworkX Graph object,which is then returned.
Additionally checks for protocol version, revision and metric.
"""
graph = self._init_graph()
# ensure is NetJSON NetworkGraph object
if ... | [
"def",
"parse",
"(",
"self",
",",
"data",
")",
":",
"graph",
"=",
"self",
".",
"_init_graph",
"(",
")",
"# ensure is NetJSON NetworkGraph object",
"if",
"'type'",
"not",
"in",
"data",
"or",
"data",
"[",
"'type'",
"]",
"!=",
"'NetworkGraph'",
":",
"raise",
... | Converts a NetJSON 'NetworkGraph' object
to a NetworkX Graph object,which is then returned.
Additionally checks for protocol version, revision and metric. | [
"Converts",
"a",
"NetJSON",
"NetworkGraph",
"object",
"to",
"a",
"NetworkX",
"Graph",
"object",
"which",
"is",
"then",
"returned",
".",
"Additionally",
"checks",
"for",
"protocol",
"version",
"revision",
"and",
"metric",
"."
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/parsers/netjson.py#L8-L45 | train | 61,488 |
openwisp/netdiff | netdiff/parsers/openvpn.py | OpenvpnParser.parse | def parse(self, data):
"""
Converts a OpenVPN JSON to a NetworkX Graph object
which is then returned.
"""
# initialize graph and list of aggregated nodes
graph = self._init_graph()
server = self._server_common_name
# add server (central node) to graph
... | python | def parse(self, data):
"""
Converts a OpenVPN JSON to a NetworkX Graph object
which is then returned.
"""
# initialize graph and list of aggregated nodes
graph = self._init_graph()
server = self._server_common_name
# add server (central node) to graph
... | [
"def",
"parse",
"(",
"self",
",",
"data",
")",
":",
"# initialize graph and list of aggregated nodes",
"graph",
"=",
"self",
".",
"_init_graph",
"(",
")",
"server",
"=",
"self",
".",
"_server_common_name",
"# add server (central node) to graph",
"graph",
".",
"add_nod... | Converts a OpenVPN JSON to a NetworkX Graph object
which is then returned. | [
"Converts",
"a",
"OpenVPN",
"JSON",
"to",
"a",
"NetworkX",
"Graph",
"object",
"which",
"is",
"then",
"returned",
"."
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/parsers/openvpn.py#L25-L67 | train | 61,489 |
openwisp/netdiff | netdiff/parsers/batman.py | BatmanParser._txtinfo_to_python | def _txtinfo_to_python(self, data):
"""
Converts txtinfo format to python
"""
self._format = 'txtinfo'
# find interesting section
lines = data.split('\n')
try:
start = lines.index('Table: Topology') + 2
except ValueError:
raise Pars... | python | def _txtinfo_to_python(self, data):
"""
Converts txtinfo format to python
"""
self._format = 'txtinfo'
# find interesting section
lines = data.split('\n')
try:
start = lines.index('Table: Topology') + 2
except ValueError:
raise Pars... | [
"def",
"_txtinfo_to_python",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"_format",
"=",
"'txtinfo'",
"# find interesting section",
"lines",
"=",
"data",
".",
"split",
"(",
"'\\n'",
")",
"try",
":",
"start",
"=",
"lines",
".",
"index",
"(",
"'Table: T... | Converts txtinfo format to python | [
"Converts",
"txtinfo",
"format",
"to",
"python"
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/parsers/batman.py#L23-L44 | train | 61,490 |
openwisp/netdiff | netdiff/parsers/batman.py | BatmanParser._get_primary_address | def _get_primary_address(self, mac_address, node_list):
"""
Uses the _get_aggregated_node_list structure to find
the primary mac address associated to a secondary one,
if none is found returns itself.
"""
for local_addresses in node_list:
if mac_address in loc... | python | def _get_primary_address(self, mac_address, node_list):
"""
Uses the _get_aggregated_node_list structure to find
the primary mac address associated to a secondary one,
if none is found returns itself.
"""
for local_addresses in node_list:
if mac_address in loc... | [
"def",
"_get_primary_address",
"(",
"self",
",",
"mac_address",
",",
"node_list",
")",
":",
"for",
"local_addresses",
"in",
"node_list",
":",
"if",
"mac_address",
"in",
"local_addresses",
":",
"return",
"local_addresses",
"[",
"0",
"]",
"return",
"mac_address"
] | Uses the _get_aggregated_node_list structure to find
the primary mac address associated to a secondary one,
if none is found returns itself. | [
"Uses",
"the",
"_get_aggregated_node_list",
"structure",
"to",
"find",
"the",
"primary",
"mac",
"address",
"associated",
"to",
"a",
"secondary",
"one",
"if",
"none",
"is",
"found",
"returns",
"itself",
"."
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/parsers/batman.py#L46-L55 | train | 61,491 |
openwisp/netdiff | netdiff/parsers/batman.py | BatmanParser._get_aggregated_node_list | def _get_aggregated_node_list(self, data):
"""
Returns list of main and secondary mac addresses.
"""
node_list = []
for node in data:
local_addresses = [node['primary']]
if 'secondary' in node:
local_addresses += node['secondary']
... | python | def _get_aggregated_node_list(self, data):
"""
Returns list of main and secondary mac addresses.
"""
node_list = []
for node in data:
local_addresses = [node['primary']]
if 'secondary' in node:
local_addresses += node['secondary']
... | [
"def",
"_get_aggregated_node_list",
"(",
"self",
",",
"data",
")",
":",
"node_list",
"=",
"[",
"]",
"for",
"node",
"in",
"data",
":",
"local_addresses",
"=",
"[",
"node",
"[",
"'primary'",
"]",
"]",
"if",
"'secondary'",
"in",
"node",
":",
"local_addresses"... | Returns list of main and secondary mac addresses. | [
"Returns",
"list",
"of",
"main",
"and",
"secondary",
"mac",
"addresses",
"."
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/parsers/batman.py#L57-L67 | train | 61,492 |
openwisp/netdiff | netdiff/parsers/batman.py | BatmanParser._parse_alfred_vis | def _parse_alfred_vis(self, data):
"""
Converts a alfred-vis JSON object
to a NetworkX Graph object which is then returned.
Additionally checks for "source_vesion" to determine the batman-adv version.
"""
# initialize graph and list of aggregated nodes
graph = sel... | python | def _parse_alfred_vis(self, data):
"""
Converts a alfred-vis JSON object
to a NetworkX Graph object which is then returned.
Additionally checks for "source_vesion" to determine the batman-adv version.
"""
# initialize graph and list of aggregated nodes
graph = sel... | [
"def",
"_parse_alfred_vis",
"(",
"self",
",",
"data",
")",
":",
"# initialize graph and list of aggregated nodes",
"graph",
"=",
"self",
".",
"_init_graph",
"(",
")",
"if",
"'source_version'",
"in",
"data",
":",
"self",
".",
"version",
"=",
"data",
"[",
"'source... | Converts a alfred-vis JSON object
to a NetworkX Graph object which is then returned.
Additionally checks for "source_vesion" to determine the batman-adv version. | [
"Converts",
"a",
"alfred",
"-",
"vis",
"JSON",
"object",
"to",
"a",
"NetworkX",
"Graph",
"object",
"which",
"is",
"then",
"returned",
".",
"Additionally",
"checks",
"for",
"source_vesion",
"to",
"determine",
"the",
"batman",
"-",
"adv",
"version",
"."
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/parsers/batman.py#L79-L106 | train | 61,493 |
openwisp/netdiff | netdiff/parsers/base.py | BaseParser.json | def json(self, dict=False, **kwargs):
"""
Outputs NetJSON format
"""
try:
graph = self.graph
except AttributeError:
raise NotImplementedError()
return _netjson_networkgraph(self.protocol,
self.version,
... | python | def json(self, dict=False, **kwargs):
"""
Outputs NetJSON format
"""
try:
graph = self.graph
except AttributeError:
raise NotImplementedError()
return _netjson_networkgraph(self.protocol,
self.version,
... | [
"def",
"json",
"(",
"self",
",",
"dict",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"graph",
"=",
"self",
".",
"graph",
"except",
"AttributeError",
":",
"raise",
"NotImplementedError",
"(",
")",
"return",
"_netjson_networkgraph",
"(",
"... | Outputs NetJSON format | [
"Outputs",
"NetJSON",
"format"
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/parsers/base.py#L135-L150 | train | 61,494 |
openwisp/netdiff | netdiff/utils.py | diff | def diff(old, new):
"""
Returns differences of two network topologies old and new
in NetJSON NetworkGraph compatible format
"""
protocol = new.protocol
version = new.version
revision = new.revision
metric = new.metric
# calculate differences
in_both = _find_unchanged(old.graph, n... | python | def diff(old, new):
"""
Returns differences of two network topologies old and new
in NetJSON NetworkGraph compatible format
"""
protocol = new.protocol
version = new.version
revision = new.revision
metric = new.metric
# calculate differences
in_both = _find_unchanged(old.graph, n... | [
"def",
"diff",
"(",
"old",
",",
"new",
")",
":",
"protocol",
"=",
"new",
".",
"protocol",
"version",
"=",
"new",
".",
"version",
"revision",
"=",
"new",
".",
"revision",
"metric",
"=",
"new",
".",
"metric",
"# calculate differences",
"in_both",
"=",
"_fi... | Returns differences of two network topologies old and new
in NetJSON NetworkGraph compatible format | [
"Returns",
"differences",
"of",
"two",
"network",
"topologies",
"old",
"and",
"new",
"in",
"NetJSON",
"NetworkGraph",
"compatible",
"format"
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/utils.py#L7-L48 | train | 61,495 |
openwisp/netdiff | netdiff/utils.py | _make_diff | def _make_diff(old, new, both):
"""
calculates differences between topologies 'old' and 'new'
returns a tuple with two network graph objects
the first graph contains the added nodes, the secnod contains the added links
"""
# make a copy of old topology to avoid tampering with it
diff_edges =... | python | def _make_diff(old, new, both):
"""
calculates differences between topologies 'old' and 'new'
returns a tuple with two network graph objects
the first graph contains the added nodes, the secnod contains the added links
"""
# make a copy of old topology to avoid tampering with it
diff_edges =... | [
"def",
"_make_diff",
"(",
"old",
",",
"new",
",",
"both",
")",
":",
"# make a copy of old topology to avoid tampering with it",
"diff_edges",
"=",
"new",
".",
"copy",
"(",
")",
"not_different",
"=",
"[",
"tuple",
"(",
"edge",
")",
"for",
"edge",
"in",
"both",
... | calculates differences between topologies 'old' and 'new'
returns a tuple with two network graph objects
the first graph contains the added nodes, the secnod contains the added links | [
"calculates",
"differences",
"between",
"topologies",
"old",
"and",
"new",
"returns",
"a",
"tuple",
"with",
"two",
"network",
"graph",
"objects",
"the",
"first",
"graph",
"contains",
"the",
"added",
"nodes",
"the",
"secnod",
"contains",
"the",
"added",
"links"
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/utils.py#L51-L70 | train | 61,496 |
openwisp/netdiff | netdiff/utils.py | _find_unchanged | def _find_unchanged(old, new):
"""
returns edges that are in both old and new
"""
edges = []
old_edges = [set(edge) for edge in old.edges()]
new_edges = [set(edge) for edge in new.edges()]
for old_edge in old_edges:
if old_edge in new_edges:
edges.append(set(old_edge))
... | python | def _find_unchanged(old, new):
"""
returns edges that are in both old and new
"""
edges = []
old_edges = [set(edge) for edge in old.edges()]
new_edges = [set(edge) for edge in new.edges()]
for old_edge in old_edges:
if old_edge in new_edges:
edges.append(set(old_edge))
... | [
"def",
"_find_unchanged",
"(",
"old",
",",
"new",
")",
":",
"edges",
"=",
"[",
"]",
"old_edges",
"=",
"[",
"set",
"(",
"edge",
")",
"for",
"edge",
"in",
"old",
".",
"edges",
"(",
")",
"]",
"new_edges",
"=",
"[",
"set",
"(",
"edge",
")",
"for",
... | returns edges that are in both old and new | [
"returns",
"edges",
"that",
"are",
"in",
"both",
"old",
"and",
"new"
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/utils.py#L73-L83 | train | 61,497 |
openwisp/netdiff | netdiff/utils.py | _find_changed | def _find_changed(old, new, both):
"""
returns links that have changed cost
"""
# create two list of sets of old and new edges including cost
old_edges = []
for edge in old.edges(data=True):
# skip links that are not in both
if set((edge[0], edge[1])) not in both:
con... | python | def _find_changed(old, new, both):
"""
returns links that have changed cost
"""
# create two list of sets of old and new edges including cost
old_edges = []
for edge in old.edges(data=True):
# skip links that are not in both
if set((edge[0], edge[1])) not in both:
con... | [
"def",
"_find_changed",
"(",
"old",
",",
"new",
",",
"both",
")",
":",
"# create two list of sets of old and new edges including cost",
"old_edges",
"=",
"[",
"]",
"for",
"edge",
"in",
"old",
".",
"edges",
"(",
"data",
"=",
"True",
")",
":",
"# skip links that a... | returns links that have changed cost | [
"returns",
"links",
"that",
"have",
"changed",
"cost"
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/utils.py#L86-L119 | train | 61,498 |
openwisp/netdiff | netdiff/parsers/bmx6.py | Bmx6Parser.parse | def parse(self, data):
"""
Converts a BMX6 b6m JSON to a NetworkX Graph object
which is then returned.
"""
# initialize graph and list of aggregated nodes
graph = self._init_graph()
if len(data) != 0:
if "links" not in data[0]:
raise Pa... | python | def parse(self, data):
"""
Converts a BMX6 b6m JSON to a NetworkX Graph object
which is then returned.
"""
# initialize graph and list of aggregated nodes
graph = self._init_graph()
if len(data) != 0:
if "links" not in data[0]:
raise Pa... | [
"def",
"parse",
"(",
"self",
",",
"data",
")",
":",
"# initialize graph and list of aggregated nodes",
"graph",
"=",
"self",
".",
"_init_graph",
"(",
")",
"if",
"len",
"(",
"data",
")",
"!=",
"0",
":",
"if",
"\"links\"",
"not",
"in",
"data",
"[",
"0",
"]... | Converts a BMX6 b6m JSON to a NetworkX Graph object
which is then returned. | [
"Converts",
"a",
"BMX6",
"b6m",
"JSON",
"to",
"a",
"NetworkX",
"Graph",
"object",
"which",
"is",
"then",
"returned",
"."
] | f7fda2ed78ad815b8c56eae27dfd193172fb23f5 | https://github.com/openwisp/netdiff/blob/f7fda2ed78ad815b8c56eae27dfd193172fb23f5/netdiff/parsers/bmx6.py#L11-L31 | train | 61,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.