partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | set_log_level_format | Set logger level and format.
:param level: logging level; see the :py:mod:`logging` constants.
:type level: int
:param format: logging formatter format string
:type format: str | pypi_download_stats/runner.py | def set_log_level_format(level, format):
"""
Set logger level and format.
:param level: logging level; see the :py:mod:`logging` constants.
:type level: int
:param format: logging formatter format string
:type format: str
"""
formatter = logging.Formatter(fmt=format)
logger.handlers... | def set_log_level_format(level, format):
"""
Set logger level and format.
:param level: logging level; see the :py:mod:`logging` constants.
:type level: int
:param format: logging formatter format string
:type format: str
"""
formatter = logging.Formatter(fmt=format)
logger.handlers... | [
"Set",
"logger",
"level",
"and",
"format",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/runner.py#L139-L150 | [
"def",
"set_log_level_format",
"(",
"level",
",",
"format",
")",
":",
"formatter",
"=",
"logging",
".",
"Formatter",
"(",
"fmt",
"=",
"format",
")",
"logger",
".",
"handlers",
"[",
"0",
"]",
".",
"setFormatter",
"(",
"formatter",
")",
"logger",
".",
"set... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | _pypi_get_projects_for_user | Given the username of a PyPI user, return a list of all of the user's
projects from the XMLRPC interface.
See: https://wiki.python.org/moin/PyPIXmlRpc
:param username: PyPI username
:type username: str
:return: list of string project names
:rtype: ``list`` | pypi_download_stats/runner.py | def _pypi_get_projects_for_user(username):
"""
Given the username of a PyPI user, return a list of all of the user's
projects from the XMLRPC interface.
See: https://wiki.python.org/moin/PyPIXmlRpc
:param username: PyPI username
:type username: str
:return: list of string project names
... | def _pypi_get_projects_for_user(username):
"""
Given the username of a PyPI user, return a list of all of the user's
projects from the XMLRPC interface.
See: https://wiki.python.org/moin/PyPIXmlRpc
:param username: PyPI username
:type username: str
:return: list of string project names
... | [
"Given",
"the",
"username",
"of",
"a",
"PyPI",
"user",
"return",
"a",
"list",
"of",
"all",
"of",
"the",
"user",
"s",
"projects",
"from",
"the",
"XMLRPC",
"interface",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/runner.py#L153-L167 | [
"def",
"_pypi_get_projects_for_user",
"(",
"username",
")",
":",
"client",
"=",
"xmlrpclib",
".",
"ServerProxy",
"(",
"'https://pypi.python.org/pypi'",
")",
"pkgs",
"=",
"client",
".",
"user_packages",
"(",
"username",
")",
"# returns [role, package]",
"return",
"[",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | main | Main entry point | pypi_download_stats/runner.py | def main(args=None):
"""
Main entry point
"""
# parse args
if args is None:
args = parse_args(sys.argv[1:])
# set logging level
if args.verbose > 1:
set_log_debug()
elif args.verbose == 1:
set_log_info()
outpath = os.path.abspath(os.path.expanduser(args.out_... | def main(args=None):
"""
Main entry point
"""
# parse args
if args is None:
args = parse_args(sys.argv[1:])
# set logging level
if args.verbose > 1:
set_log_debug()
elif args.verbose == 1:
set_log_info()
outpath = os.path.abspath(os.path.expanduser(args.out_... | [
"Main",
"entry",
"point"
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/runner.py#L170-L205 | [
"def",
"main",
"(",
"args",
"=",
"None",
")",
":",
"# parse args",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"parse_args",
"(",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
")",
"# set logging level",
"if",
"args",
".",
"verbose",
">",
"1",
":",
"se... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | FancyAreaGraph.generate_graph | Generate the graph; return a 2-tuple of strings, script to place in the
head of the HTML document and div content for the graph itself.
:return: 2-tuple (script, div)
:rtype: tuple | pypi_download_stats/graphs.py | def generate_graph(self):
"""
Generate the graph; return a 2-tuple of strings, script to place in the
head of the HTML document and div content for the graph itself.
:return: 2-tuple (script, div)
:rtype: tuple
"""
logger.debug('Generating graph for %s', self._gr... | def generate_graph(self):
"""
Generate the graph; return a 2-tuple of strings, script to place in the
head of the HTML document and div content for the graph itself.
:return: 2-tuple (script, div)
:rtype: tuple
"""
logger.debug('Generating graph for %s', self._gr... | [
"Generate",
"the",
"graph",
";",
"return",
"a",
"2",
"-",
"tuple",
"of",
"strings",
"script",
"to",
"place",
"in",
"the",
"head",
"of",
"the",
"HTML",
"document",
"and",
"div",
"content",
"for",
"the",
"graph",
"itself",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/graphs.py#L88-L153 | [
"def",
"generate_graph",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"'Generating graph for %s'",
",",
"self",
".",
"_graph_id",
")",
"# tools to use",
"tools",
"=",
"[",
"PanTool",
"(",
")",
",",
"BoxZoomTool",
"(",
")",
",",
"WheelZoomTool",
"(",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | FancyAreaGraph._line_for_patches | Add a line along the top edge of a Patch in a stacked Area Chart; return
the new Glyph for addition to HoverTool.
:param data: original data for the graph
:type data: dict
:param chart: Chart to add the line to
:type chart: bokeh.charts.Chart
:param renderer: GlyphRender... | pypi_download_stats/graphs.py | def _line_for_patches(self, data, chart, renderer, series_name):
"""
Add a line along the top edge of a Patch in a stacked Area Chart; return
the new Glyph for addition to HoverTool.
:param data: original data for the graph
:type data: dict
:param chart: Chart to add the... | def _line_for_patches(self, data, chart, renderer, series_name):
"""
Add a line along the top edge of a Patch in a stacked Area Chart; return
the new Glyph for addition to HoverTool.
:param data: original data for the graph
:type data: dict
:param chart: Chart to add the... | [
"Add",
"a",
"line",
"along",
"the",
"top",
"edge",
"of",
"a",
"Patch",
"in",
"a",
"stacked",
"Area",
"Chart",
";",
"return",
"the",
"new",
"Glyph",
"for",
"addition",
"to",
"HoverTool",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/graphs.py#L155-L240 | [
"def",
"_line_for_patches",
"(",
"self",
",",
"data",
",",
"chart",
",",
"renderer",
",",
"series_name",
")",
":",
"# @TODO this method needs a major refactor",
"# get the original x and y values, and color",
"xvals",
"=",
"deepcopy",
"(",
"renderer",
".",
"data_source",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats._get_cache_dates | Get s list of dates (:py:class:`datetime.datetime`) present in cache,
beginning with the longest contiguous set of dates that isn't missing
more than one date in series.
:return: list of datetime objects for contiguous dates in cache
:rtype: ``list`` | pypi_download_stats/projectstats.py | def _get_cache_dates(self):
"""
Get s list of dates (:py:class:`datetime.datetime`) present in cache,
beginning with the longest contiguous set of dates that isn't missing
more than one date in series.
:return: list of datetime objects for contiguous dates in cache
:rtyp... | def _get_cache_dates(self):
"""
Get s list of dates (:py:class:`datetime.datetime`) present in cache,
beginning with the longest contiguous set of dates that isn't missing
more than one date in series.
:return: list of datetime objects for contiguous dates in cache
:rtyp... | [
"Get",
"s",
"list",
"of",
"dates",
"(",
":",
"py",
":",
"class",
":",
"datetime",
".",
"datetime",
")",
"present",
"in",
"cache",
"beginning",
"with",
"the",
"longest",
"contiguous",
"set",
"of",
"dates",
"that",
"isn",
"t",
"missing",
"more",
"than",
... | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L68-L98 | [
"def",
"_get_cache_dates",
"(",
"self",
")",
":",
"all_dates",
"=",
"self",
".",
"cache",
".",
"get_dates_for_project",
"(",
"self",
".",
"project_name",
")",
"dates",
"=",
"[",
"]",
"last_date",
"=",
"None",
"for",
"val",
"in",
"sorted",
"(",
"all_dates",... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats._is_empty_cache_record | Return True if the specified cache record has no data, False otherwise.
:param rec: cache record returned by :py:meth:`~._cache_get`
:type rec: dict
:return: True if record is empty, False otherwise
:rtype: bool | pypi_download_stats/projectstats.py | def _is_empty_cache_record(self, rec):
"""
Return True if the specified cache record has no data, False otherwise.
:param rec: cache record returned by :py:meth:`~._cache_get`
:type rec: dict
:return: True if record is empty, False otherwise
:rtype: bool
"""
... | def _is_empty_cache_record(self, rec):
"""
Return True if the specified cache record has no data, False otherwise.
:param rec: cache record returned by :py:meth:`~._cache_get`
:type rec: dict
:return: True if record is empty, False otherwise
:rtype: bool
"""
... | [
"Return",
"True",
"if",
"the",
"specified",
"cache",
"record",
"has",
"no",
"data",
"False",
"otherwise",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L100-L121 | [
"def",
"_is_empty_cache_record",
"(",
"self",
",",
"rec",
")",
":",
"# these are taken from DataQuery.query_one_table()",
"for",
"k",
"in",
"[",
"'by_version'",
",",
"'by_file_type'",
",",
"'by_installer'",
",",
"'by_implementation'",
",",
"'by_system'",
",",
"'by_distr... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats._cache_get | Return cache data for the specified day; cache locally in this class.
:param date: date to get data for
:type date: datetime.datetime
:return: cache data for date
:rtype: dict | pypi_download_stats/projectstats.py | def _cache_get(self, date):
"""
Return cache data for the specified day; cache locally in this class.
:param date: date to get data for
:type date: datetime.datetime
:return: cache data for date
:rtype: dict
"""
if date in self.cache_data:
log... | def _cache_get(self, date):
"""
Return cache data for the specified day; cache locally in this class.
:param date: date to get data for
:type date: datetime.datetime
:return: cache data for date
:rtype: dict
"""
if date in self.cache_data:
log... | [
"Return",
"cache",
"data",
"for",
"the",
"specified",
"day",
";",
"cache",
"locally",
"in",
"this",
"class",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L123-L140 | [
"def",
"_cache_get",
"(",
"self",
",",
"date",
")",
":",
"if",
"date",
"in",
"self",
".",
"cache_data",
":",
"logger",
".",
"debug",
"(",
"'Using class-cached data for date %s'",
",",
"date",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
")",
"return",
"self",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats._compound_column_value | Like :py:meth:`~._column_value` but collapses two unknowns into one.
:param k1: first (top-level) value
:param k2: second (bottom-level) value
:return: display key
:rtype: str | pypi_download_stats/projectstats.py | def _compound_column_value(k1, k2):
"""
Like :py:meth:`~._column_value` but collapses two unknowns into one.
:param k1: first (top-level) value
:param k2: second (bottom-level) value
:return: display key
:rtype: str
"""
k1 = ProjectStats._column_value(k1)... | def _compound_column_value(k1, k2):
"""
Like :py:meth:`~._column_value` but collapses two unknowns into one.
:param k1: first (top-level) value
:param k2: second (bottom-level) value
:return: display key
:rtype: str
"""
k1 = ProjectStats._column_value(k1)... | [
"Like",
":",
"py",
":",
"meth",
":",
"~",
".",
"_column_value",
"but",
"collapses",
"two",
"unknowns",
"into",
"one",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L176-L189 | [
"def",
"_compound_column_value",
"(",
"k1",
",",
"k2",
")",
":",
"k1",
"=",
"ProjectStats",
".",
"_column_value",
"(",
"k1",
")",
"k2",
"=",
"ProjectStats",
".",
"_column_value",
"(",
"k2",
")",
"if",
"k1",
"==",
"'unknown'",
"and",
"k2",
"==",
"'unknown... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats._shorten_version | If ``ver`` is a dot-separated string with at least (num_components +1)
components, return only the first two. Else return the original string.
:param ver: version string
:type ver: str
:return: shortened (major, minor) version
:rtype: str | pypi_download_stats/projectstats.py | def _shorten_version(ver, num_components=2):
"""
If ``ver`` is a dot-separated string with at least (num_components +1)
components, return only the first two. Else return the original string.
:param ver: version string
:type ver: str
:return: shortened (major, minor) ver... | def _shorten_version(ver, num_components=2):
"""
If ``ver`` is a dot-separated string with at least (num_components +1)
components, return only the first two. Else return the original string.
:param ver: version string
:type ver: str
:return: shortened (major, minor) ver... | [
"If",
"ver",
"is",
"a",
"dot",
"-",
"separated",
"string",
"with",
"at",
"least",
"(",
"num_components",
"+",
"1",
")",
"components",
"return",
"only",
"the",
"first",
"two",
".",
"Else",
"return",
"the",
"original",
"string",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L192-L205 | [
"def",
"_shorten_version",
"(",
"ver",
",",
"num_components",
"=",
"2",
")",
":",
"parts",
"=",
"ver",
".",
"split",
"(",
"'.'",
")",
"if",
"len",
"(",
"parts",
")",
"<=",
"num_components",
":",
"return",
"ver",
"return",
"'.'",
".",
"join",
"(",
"pa... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.per_version_data | Return download data by version.
:return: dict of cache data; keys are datetime objects, values are
dict of version (str) to count (int)
:rtype: dict | pypi_download_stats/projectstats.py | def per_version_data(self):
"""
Return download data by version.
:return: dict of cache data; keys are datetime objects, values are
dict of version (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = sel... | def per_version_data(self):
"""
Return download data by version.
:return: dict of cache data; keys are datetime objects, values are
dict of version (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = sel... | [
"Return",
"download",
"data",
"by",
"version",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L208-L222 | [
"def",
"per_version_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"if",
"len",
"(",
"data",
"[",
"'by_version'",
"]",
")",... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.per_file_type_data | Return download data by file type.
:return: dict of cache data; keys are datetime objects, values are
dict of file type (str) to count (int)
:rtype: dict | pypi_download_stats/projectstats.py | def per_file_type_data(self):
"""
Return download data by file type.
:return: dict of cache data; keys are datetime objects, values are
dict of file type (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data... | def per_file_type_data(self):
"""
Return download data by file type.
:return: dict of cache data; keys are datetime objects, values are
dict of file type (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data... | [
"Return",
"download",
"data",
"by",
"file",
"type",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L225-L239 | [
"def",
"per_file_type_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"if",
"len",
"(",
"data",
"[",
"'by_file_type'",
"]",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.per_installer_data | Return download data by installer name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of installer name/version (str) to count (int).
:rtype: dict | pypi_download_stats/projectstats.py | def per_installer_data(self):
"""
Return download data by installer name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of installer name/version (str) to count (int).
:rtype: dict
"""
ret = {}
for cache_date in sel... | def per_installer_data(self):
"""
Return download data by installer name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of installer name/version (str) to count (int).
:rtype: dict
"""
ret = {}
for cache_date in sel... | [
"Return",
"download",
"data",
"by",
"installer",
"name",
"and",
"version",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L242-L263 | [
"def",
"per_installer_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"}",
"for",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.per_implementation_data | Return download data by python impelementation name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of implementation name/version (str) to count (int).
:rtype: dict | pypi_download_stats/projectstats.py | def per_implementation_data(self):
"""
Return download data by python impelementation name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of implementation name/version (str) to count (int).
:rtype: dict
"""
ret = {}
... | def per_implementation_data(self):
"""
Return download data by python impelementation name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of implementation name/version (str) to count (int).
:rtype: dict
"""
ret = {}
... | [
"Return",
"download",
"data",
"by",
"python",
"impelementation",
"name",
"and",
"version",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L266-L287 | [
"def",
"per_implementation_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"}",
"fo... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.per_system_data | Return download data by system.
:return: dict of cache data; keys are datetime objects, values are
dict of system (str) to count (int)
:rtype: dict | pypi_download_stats/projectstats.py | def per_system_data(self):
"""
Return download data by system.
:return: dict of cache data; keys are datetime objects, values are
dict of system (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = self._... | def per_system_data(self):
"""
Return download data by system.
:return: dict of cache data; keys are datetime objects, values are
dict of system (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = self._... | [
"Return",
"download",
"data",
"by",
"system",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L290-L307 | [
"def",
"per_system_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"self",
".",
"... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.per_country_data | Return download data by country.
:return: dict of cache data; keys are datetime objects, values are
dict of country (str) to count (int)
:rtype: dict | pypi_download_stats/projectstats.py | def per_country_data(self):
"""
Return download data by country.
:return: dict of cache data; keys are datetime objects, values are
dict of country (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = sel... | def per_country_data(self):
"""
Return download data by country.
:return: dict of cache data; keys are datetime objects, values are
dict of country (str) to count (int)
:rtype: dict
"""
ret = {}
for cache_date in self.cache_dates:
data = sel... | [
"Return",
"download",
"data",
"by",
"country",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L310-L327 | [
"def",
"per_country_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"}",
"for",
"... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.per_distro_data | Return download data by distro name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of distro name/version (str) to count (int).
:rtype: dict | pypi_download_stats/projectstats.py | def per_distro_data(self):
"""
Return download data by distro name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of distro name/version (str) to count (int).
:rtype: dict
"""
ret = {}
for cache_date in self.cache_d... | def per_distro_data(self):
"""
Return download data by distro name and version.
:return: dict of cache data; keys are datetime objects, values are
dict of distro name/version (str) to count (int).
:rtype: dict
"""
ret = {}
for cache_date in self.cache_d... | [
"Return",
"download",
"data",
"by",
"distro",
"name",
"and",
"version",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L330-L354 | [
"def",
"per_distro_data",
"(",
"self",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"cache_date",
"in",
"self",
".",
"cache_dates",
":",
"data",
"=",
"self",
".",
"_cache_get",
"(",
"cache_date",
")",
"ret",
"[",
"cache_date",
"]",
"=",
"{",
"}",
"for",
"d... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.downloads_per_day | Return the number of downloads per day, averaged over the past 7 days
of data.
:return: average number of downloads per day
:rtype: int | pypi_download_stats/projectstats.py | def downloads_per_day(self):
"""
Return the number of downloads per day, averaged over the past 7 days
of data.
:return: average number of downloads per day
:rtype: int
"""
count, num_days = self._downloads_for_num_days(7)
res = ceil(count / num_days)
... | def downloads_per_day(self):
"""
Return the number of downloads per day, averaged over the past 7 days
of data.
:return: average number of downloads per day
:rtype: int
"""
count, num_days = self._downloads_for_num_days(7)
res = ceil(count / num_days)
... | [
"Return",
"the",
"number",
"of",
"downloads",
"per",
"day",
"averaged",
"over",
"the",
"past",
"7",
"days",
"of",
"data",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L357-L368 | [
"def",
"downloads_per_day",
"(",
"self",
")",
":",
"count",
",",
"num_days",
"=",
"self",
".",
"_downloads_for_num_days",
"(",
"7",
")",
"res",
"=",
"ceil",
"(",
"count",
"/",
"num_days",
")",
"logger",
".",
"debug",
"(",
"\"Downloads per day = (%d / %d) = %d\... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats.downloads_per_week | Return the number of downloads in the last 7 days.
:return: number of downloads in the last 7 days; if we have less than
7 days of data, returns None.
:rtype: int | pypi_download_stats/projectstats.py | def downloads_per_week(self):
"""
Return the number of downloads in the last 7 days.
:return: number of downloads in the last 7 days; if we have less than
7 days of data, returns None.
:rtype: int
"""
if len(self.cache_dates) < 7:
logger.error("Only... | def downloads_per_week(self):
"""
Return the number of downloads in the last 7 days.
:return: number of downloads in the last 7 days; if we have less than
7 days of data, returns None.
:rtype: int
"""
if len(self.cache_dates) < 7:
logger.error("Only... | [
"Return",
"the",
"number",
"of",
"downloads",
"in",
"the",
"last",
"7",
"days",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L371-L385 | [
"def",
"downloads_per_week",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"cache_dates",
")",
"<",
"7",
":",
"logger",
".",
"error",
"(",
"\"Only have %d days of data; cannot calculate \"",
"\"downloads per week\"",
",",
"len",
"(",
"self",
".",
"cache_... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | ProjectStats._downloads_for_num_days | Given a number of days of historical data to look at (starting with
today and working backwards), return the total number of downloads
for that time range, and the number of days of data we had (in cases
where we had less data than requested).
:param num_days: number of days of data to ... | pypi_download_stats/projectstats.py | def _downloads_for_num_days(self, num_days):
"""
Given a number of days of historical data to look at (starting with
today and working backwards), return the total number of downloads
for that time range, and the number of days of data we had (in cases
where we had less data than... | def _downloads_for_num_days(self, num_days):
"""
Given a number of days of historical data to look at (starting with
today and working backwards), return the total number of downloads
for that time range, and the number of days of data we had (in cases
where we had less data than... | [
"Given",
"a",
"number",
"of",
"days",
"of",
"historical",
"data",
"to",
"look",
"at",
"(",
"starting",
"with",
"today",
"and",
"working",
"backwards",
")",
"return",
"the",
"total",
"number",
"of",
"downloads",
"for",
"that",
"time",
"range",
"and",
"the",... | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/projectstats.py#L406-L429 | [
"def",
"_downloads_for_num_days",
"(",
"self",
",",
"num_days",
")",
":",
"logger",
".",
"debug",
"(",
"\"Getting download total for last %d days\"",
",",
"num_days",
")",
"dates",
"=",
"self",
".",
"cache_dates",
"logger",
".",
"debug",
"(",
"\"Cache has %d days of... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._get_project_id | Get our projectId from the ``GOOGLE_APPLICATION_CREDENTIALS`` creds
JSON file.
:return: project ID
:rtype: str | pypi_download_stats/dataquery.py | def _get_project_id(self):
"""
Get our projectId from the ``GOOGLE_APPLICATION_CREDENTIALS`` creds
JSON file.
:return: project ID
:rtype: str
"""
fpath = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', None)
if fpath is None:
raise Exception(... | def _get_project_id(self):
"""
Get our projectId from the ``GOOGLE_APPLICATION_CREDENTIALS`` creds
JSON file.
:return: project ID
:rtype: str
"""
fpath = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', None)
if fpath is None:
raise Exception(... | [
"Get",
"our",
"projectId",
"from",
"the",
"GOOGLE_APPLICATION_CREDENTIALS",
"creds",
"JSON",
"file",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L94-L110 | [
"def",
"_get_project_id",
"(",
"self",
")",
":",
"fpath",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'GOOGLE_APPLICATION_CREDENTIALS'",
",",
"None",
")",
"if",
"fpath",
"is",
"None",
":",
"raise",
"Exception",
"(",
"'ERROR: No project ID specified, and '",
"'G... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._get_bigquery_service | Connect to the BigQuery service.
Calling ``GoogleCredentials.get_application_default`` requires that
you either be running in the Google Cloud, or have the
``GOOGLE_APPLICATION_CREDENTIALS`` environment variable set to the path
to a credentials JSON file.
:return: authenticated... | pypi_download_stats/dataquery.py | def _get_bigquery_service(self):
"""
Connect to the BigQuery service.
Calling ``GoogleCredentials.get_application_default`` requires that
you either be running in the Google Cloud, or have the
``GOOGLE_APPLICATION_CREDENTIALS`` environment variable set to the path
to a c... | def _get_bigquery_service(self):
"""
Connect to the BigQuery service.
Calling ``GoogleCredentials.get_application_default`` requires that
you either be running in the Google Cloud, or have the
``GOOGLE_APPLICATION_CREDENTIALS`` environment variable set to the path
to a c... | [
"Connect",
"to",
"the",
"BigQuery",
"service",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L112-L130 | [
"def",
"_get_bigquery_service",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"'Getting Google Credentials'",
")",
"credentials",
"=",
"GoogleCredentials",
".",
"get_application_default",
"(",
")",
"logger",
".",
"debug",
"(",
"'Building BigQuery service instance'... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._get_download_table_ids | Get a list of PyPI downloads table (sharded per day) IDs.
:return: list of table names (strings)
:rtype: ``list`` | pypi_download_stats/dataquery.py | def _get_download_table_ids(self):
"""
Get a list of PyPI downloads table (sharded per day) IDs.
:return: list of table names (strings)
:rtype: ``list``
"""
all_table_names = [] # matching per-date table names
logger.info('Querying for all tables in dataset')
... | def _get_download_table_ids(self):
"""
Get a list of PyPI downloads table (sharded per day) IDs.
:return: list of table names (strings)
:rtype: ``list``
"""
all_table_names = [] # matching per-date table names
logger.info('Querying for all tables in dataset')
... | [
"Get",
"a",
"list",
"of",
"PyPI",
"downloads",
"table",
"(",
"sharded",
"per",
"day",
")",
"IDs",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L132-L164 | [
"def",
"_get_download_table_ids",
"(",
"self",
")",
":",
"all_table_names",
"=",
"[",
"]",
"# matching per-date table names",
"logger",
".",
"info",
"(",
"'Querying for all tables in dataset'",
")",
"tables",
"=",
"self",
".",
"service",
".",
"tables",
"(",
")",
"... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._datetime_for_table_name | Return a :py:class:`datetime.datetime` object for the date of the
data in the specified table name.
:param table_name: name of the table
:type table_name: str
:return: datetime that the table holds data for
:rtype: datetime.datetime | pypi_download_stats/dataquery.py | def _datetime_for_table_name(self, table_name):
"""
Return a :py:class:`datetime.datetime` object for the date of the
data in the specified table name.
:param table_name: name of the table
:type table_name: str
:return: datetime that the table holds data for
:rty... | def _datetime_for_table_name(self, table_name):
"""
Return a :py:class:`datetime.datetime` object for the date of the
data in the specified table name.
:param table_name: name of the table
:type table_name: str
:return: datetime that the table holds data for
:rty... | [
"Return",
"a",
":",
"py",
":",
"class",
":",
"datetime",
".",
"datetime",
"object",
"for",
"the",
"date",
"of",
"the",
"data",
"in",
"the",
"specified",
"table",
"name",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L166-L178 | [
"def",
"_datetime_for_table_name",
"(",
"self",
",",
"table_name",
")",
":",
"m",
"=",
"self",
".",
"_table_re",
".",
"match",
"(",
"table_name",
")",
"dt",
"=",
"datetime",
".",
"strptime",
"(",
"m",
".",
"group",
"(",
"1",
")",
",",
"'%Y%m%d'",
")",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._run_query | Run one query against BigQuery and return the result.
:param query: the query to run
:type query: str
:return: list of per-row response dicts (key => value)
:rtype: ``list`` | pypi_download_stats/dataquery.py | def _run_query(self, query):
"""
Run one query against BigQuery and return the result.
:param query: the query to run
:type query: str
:return: list of per-row response dicts (key => value)
:rtype: ``list``
"""
query_request = self.service.jobs()
... | def _run_query(self, query):
"""
Run one query against BigQuery and return the result.
:param query: the query to run
:type query: str
:return: list of per-row response dicts (key => value)
:rtype: ``list``
"""
query_request = self.service.jobs()
... | [
"Run",
"one",
"query",
"against",
"BigQuery",
"and",
"return",
"the",
"result",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L191-L222 | [
"def",
"_run_query",
"(",
"self",
",",
"query",
")",
":",
"query_request",
"=",
"self",
".",
"service",
".",
"jobs",
"(",
")",
"logger",
".",
"debug",
"(",
"'Running query: %s'",
",",
"query",
")",
"start",
"=",
"datetime",
".",
"now",
"(",
")",
"resp"... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._get_newest_ts_in_table | Return the timestamp for the newest record in the given table.
:param table_name: name of the table to query
:type table_name: str
:return: timestamp of newest row in table
:rtype: int | pypi_download_stats/dataquery.py | def _get_newest_ts_in_table(self, table_name):
"""
Return the timestamp for the newest record in the given table.
:param table_name: name of the table to query
:type table_name: str
:return: timestamp of newest row in table
:rtype: int
"""
logger.debug(
... | def _get_newest_ts_in_table(self, table_name):
"""
Return the timestamp for the newest record in the given table.
:param table_name: name of the table to query
:type table_name: str
:return: timestamp of newest row in table
:rtype: int
"""
logger.debug(
... | [
"Return",
"the",
"timestamp",
"for",
"the",
"newest",
"record",
"in",
"the",
"given",
"table",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L248-L266 | [
"def",
"_get_newest_ts_in_table",
"(",
"self",
",",
"table_name",
")",
":",
"logger",
".",
"debug",
"(",
"'Querying for newest timestamp in table %s'",
",",
"table_name",
")",
"q",
"=",
"\"SELECT TIMESTAMP_TO_SEC(MAX(timestamp)) AS max_ts %s;\"",
"%",
"(",
"self",
".",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._query_by_installer | Query for download data broken down by installer, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by installer; keys are project
name, values are a dict of installer names to dicts of installer
version t... | pypi_download_stats/dataquery.py | def _query_by_installer(self, table_name):
"""
Query for download data broken down by installer, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by installer; keys are project
name, values are a di... | def _query_by_installer(self, table_name):
"""
Query for download data broken down by installer, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by installer; keys are project
name, values are a di... | [
"Query",
"for",
"download",
"data",
"broken",
"down",
"by",
"installer",
"for",
"one",
"day",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L320-L356 | [
"def",
"_query_by_installer",
"(",
"self",
",",
"table_name",
")",
":",
"logger",
".",
"info",
"(",
"'Querying for downloads by installer in table %s'",
",",
"table_name",
")",
"q",
"=",
"\"SELECT file.project, details.installer.name, \"",
"\"details.installer.version, COUNT(*)... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._query_by_system | Query for download data broken down by system, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by system; keys are project name,
values are a dict of system names to download count.
:rtype: dict | pypi_download_stats/dataquery.py | def _query_by_system(self, table_name):
"""
Query for download data broken down by system, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by system; keys are project name,
values are a dict of sys... | def _query_by_system(self, table_name):
"""
Query for download data broken down by system, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by system; keys are project name,
values are a dict of sys... | [
"Query",
"for",
"download",
"data",
"broken",
"down",
"by",
"system",
"for",
"one",
"day",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L397-L422 | [
"def",
"_query_by_system",
"(",
"self",
",",
"table_name",
")",
":",
"logger",
".",
"info",
"(",
"'Querying for downloads by system in table %s'",
",",
"table_name",
")",
"q",
"=",
"\"SELECT file.project, details.system.name, COUNT(*) as dl_count \"",
"\"%s \"",
"\"%s \"",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._query_by_distro | Query for download data broken down by OS distribution, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by distro; keys are project name,
values are a dict of distro names to dicts of distro version to
d... | pypi_download_stats/dataquery.py | def _query_by_distro(self, table_name):
"""
Query for download data broken down by OS distribution, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by distro; keys are project name,
values are a di... | def _query_by_distro(self, table_name):
"""
Query for download data broken down by OS distribution, for one day.
:param table_name: table name to query against
:type table_name: str
:return: dict of download information by distro; keys are project name,
values are a di... | [
"Query",
"for",
"download",
"data",
"broken",
"down",
"by",
"OS",
"distribution",
"for",
"one",
"day",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L424-L459 | [
"def",
"_query_by_distro",
"(",
"self",
",",
"table_name",
")",
":",
"logger",
".",
"info",
"(",
"'Querying for downloads by distro in table %s'",
",",
"table_name",
")",
"q",
"=",
"\"SELECT file.project, details.distro.name, \"",
"\"details.distro.version, COUNT(*) as dl_count... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery.query_one_table | Run all queries for the given table name (date) and update the cache.
:param table_name: table name to query against
:type table_name: str | pypi_download_stats/dataquery.py | def query_one_table(self, table_name):
"""
Run all queries for the given table name (date) and update the cache.
:param table_name: table name to query against
:type table_name: str
"""
table_date = self._datetime_for_table_name(table_name)
logger.info('Running a... | def query_one_table(self, table_name):
"""
Run all queries for the given table name (date) and update the cache.
:param table_name: table name to query against
:type table_name: str
"""
table_date = self._datetime_for_table_name(table_name)
logger.info('Running a... | [
"Run",
"all",
"queries",
"for",
"the",
"given",
"table",
"name",
"(",
"date",
")",
"and",
"update",
"the",
"cache",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L487-L527 | [
"def",
"query_one_table",
"(",
"self",
",",
"table_name",
")",
":",
"table_date",
"=",
"self",
".",
"_datetime_for_table_name",
"(",
"table_name",
")",
"logger",
".",
"info",
"(",
"'Running all queries for date table: %s (%s)'",
",",
"table_name",
",",
"table_date",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery._have_cache_for_date | Return True if we have cached data for all projects for the specified
datetime. Return False otherwise.
:param dt: datetime to find cache for
:type dt: datetime.datetime
:return: True if we have cache for all projects for this date, False
otherwise
:rtype: bool | pypi_download_stats/dataquery.py | def _have_cache_for_date(self, dt):
"""
Return True if we have cached data for all projects for the specified
datetime. Return False otherwise.
:param dt: datetime to find cache for
:type dt: datetime.datetime
:return: True if we have cache for all projects for this date... | def _have_cache_for_date(self, dt):
"""
Return True if we have cached data for all projects for the specified
datetime. Return False otherwise.
:param dt: datetime to find cache for
:type dt: datetime.datetime
:return: True if we have cache for all projects for this date... | [
"Return",
"True",
"if",
"we",
"have",
"cached",
"data",
"for",
"all",
"projects",
"for",
"the",
"specified",
"datetime",
".",
"Return",
"False",
"otherwise",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L529-L543 | [
"def",
"_have_cache_for_date",
"(",
"self",
",",
"dt",
")",
":",
"for",
"p",
"in",
"self",
".",
"projects",
":",
"if",
"self",
".",
"cache",
".",
"get",
"(",
"p",
",",
"dt",
")",
"is",
"None",
":",
"return",
"False",
"return",
"True"
] | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery.backfill_history | Backfill historical data for days that are missing.
:param num_days: number of days of historical data to backfill,
if missing
:type num_days: int
:param available_table_names: names of available per-date tables
:type available_table_names: ``list`` | pypi_download_stats/dataquery.py | def backfill_history(self, num_days, available_table_names):
"""
Backfill historical data for days that are missing.
:param num_days: number of days of historical data to backfill,
if missing
:type num_days: int
:param available_table_names: names of available per-date... | def backfill_history(self, num_days, available_table_names):
"""
Backfill historical data for days that are missing.
:param num_days: number of days of historical data to backfill,
if missing
:type num_days: int
:param available_table_names: names of available per-date... | [
"Backfill",
"historical",
"data",
"for",
"days",
"that",
"are",
"missing",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L545-L580 | [
"def",
"backfill_history",
"(",
"self",
",",
"num_days",
",",
"available_table_names",
")",
":",
"if",
"num_days",
"==",
"-",
"1",
":",
"# skip the first date, under the assumption that data may be",
"# incomplete",
"logger",
".",
"info",
"(",
"'Backfilling all available ... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | DataQuery.run_queries | Run the data queries for the specified projects.
:param backfill_num_days: number of days of historical data to backfill,
if missing
:type backfill_num_days: int | pypi_download_stats/dataquery.py | def run_queries(self, backfill_num_days=7):
"""
Run the data queries for the specified projects.
:param backfill_num_days: number of days of historical data to backfill,
if missing
:type backfill_num_days: int
"""
available_tables = self._get_download_table_ids... | def run_queries(self, backfill_num_days=7):
"""
Run the data queries for the specified projects.
:param backfill_num_days: number of days of historical data to backfill,
if missing
:type backfill_num_days: int
"""
available_tables = self._get_download_table_ids... | [
"Run",
"the",
"data",
"queries",
"for",
"the",
"specified",
"projects",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/dataquery.py#L582-L597 | [
"def",
"run_queries",
"(",
"self",
",",
"backfill_num_days",
"=",
"7",
")",
":",
"available_tables",
"=",
"self",
".",
"_get_download_table_ids",
"(",
")",
"logger",
".",
"debug",
"(",
"'Found %d available download tables: %s'",
",",
"len",
"(",
"available_tables",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | filter_data_columns | Given a dict of data such as those in :py:class:`~.ProjectStats` attributes,
made up of :py:class:`datetime.datetime` keys and values of dicts of column
keys to counts, return a list of the distinct column keys in sorted order.
:param data: data dict as returned by ProjectStats attributes
:type data: d... | pypi_download_stats/outputgenerator.py | def filter_data_columns(data):
"""
Given a dict of data such as those in :py:class:`~.ProjectStats` attributes,
made up of :py:class:`datetime.datetime` keys and values of dicts of column
keys to counts, return a list of the distinct column keys in sorted order.
:param data: data dict as returned b... | def filter_data_columns(data):
"""
Given a dict of data such as those in :py:class:`~.ProjectStats` attributes,
made up of :py:class:`datetime.datetime` keys and values of dicts of column
keys to counts, return a list of the distinct column keys in sorted order.
:param data: data dict as returned b... | [
"Given",
"a",
"dict",
"of",
"data",
"such",
"as",
"those",
"in",
":",
"py",
":",
"class",
":",
"~",
".",
"ProjectStats",
"attributes",
"made",
"up",
"of",
":",
"py",
":",
"class",
":",
"datetime",
".",
"datetime",
"keys",
"and",
"values",
"of",
"dict... | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L352-L367 | [
"def",
"filter_data_columns",
"(",
"data",
")",
":",
"keys",
"=",
"set",
"(",
")",
"for",
"dt",
",",
"d",
"in",
"data",
".",
"items",
"(",
")",
":",
"for",
"k",
"in",
"d",
":",
"keys",
".",
"add",
"(",
"k",
")",
"return",
"sorted",
"(",
"[",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | OutputGenerator._generate_html | Generate the HTML for the specified graphs.
:return:
:rtype: | pypi_download_stats/outputgenerator.py | def _generate_html(self):
"""
Generate the HTML for the specified graphs.
:return:
:rtype:
"""
logger.debug('Generating templated HTML')
env = Environment(
loader=PackageLoader('pypi_download_stats', 'templates'),
extensions=['jinja2.ext.l... | def _generate_html(self):
"""
Generate the HTML for the specified graphs.
:return:
:rtype:
"""
logger.debug('Generating templated HTML')
env = Environment(
loader=PackageLoader('pypi_download_stats', 'templates'),
extensions=['jinja2.ext.l... | [
"Generate",
"the",
"HTML",
"for",
"the",
"specified",
"graphs",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L93-L123 | [
"def",
"_generate_html",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"'Generating templated HTML'",
")",
"env",
"=",
"Environment",
"(",
"loader",
"=",
"PackageLoader",
"(",
"'pypi_download_stats'",
",",
"'templates'",
")",
",",
"extensions",
"=",
"[",
... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | OutputGenerator._data_dict_to_bokeh_chart_data | Take a dictionary of data, as returned by the :py:class:`~.ProjectStats`
per_*_data properties, return a 2-tuple of data dict and x labels list
usable by bokeh.charts.
:param data: data dict from :py:class:`~.ProjectStats` property
:type data: dict
:return: 2-tuple of data dict,... | pypi_download_stats/outputgenerator.py | def _data_dict_to_bokeh_chart_data(self, data):
"""
Take a dictionary of data, as returned by the :py:class:`~.ProjectStats`
per_*_data properties, return a 2-tuple of data dict and x labels list
usable by bokeh.charts.
:param data: data dict from :py:class:`~.ProjectStats` prop... | def _data_dict_to_bokeh_chart_data(self, data):
"""
Take a dictionary of data, as returned by the :py:class:`~.ProjectStats`
per_*_data properties, return a 2-tuple of data dict and x labels list
usable by bokeh.charts.
:param data: data dict from :py:class:`~.ProjectStats` prop... | [
"Take",
"a",
"dictionary",
"of",
"data",
"as",
"returned",
"by",
"the",
":",
"py",
":",
"class",
":",
"~",
".",
"ProjectStats",
"per_",
"*",
"_data",
"properties",
"return",
"a",
"2",
"-",
"tuple",
"of",
"data",
"dict",
"and",
"x",
"labels",
"list",
... | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L125-L154 | [
"def",
"_data_dict_to_bokeh_chart_data",
"(",
"self",
",",
"data",
")",
":",
"labels",
"=",
"[",
"]",
"# find all the data keys",
"keys",
"=",
"set",
"(",
")",
"for",
"date",
"in",
"data",
":",
"for",
"k",
"in",
"data",
"[",
"date",
"]",
":",
"keys",
"... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | OutputGenerator._limit_data | Find the per-day average of each series in the data over the last 7
days; drop all but the top 10.
:param data: original graph data
:type data: dict
:return: dict containing only the top 10 series, based on average over
the last 7 days.
:rtype: dict | pypi_download_stats/outputgenerator.py | def _limit_data(self, data):
"""
Find the per-day average of each series in the data over the last 7
days; drop all but the top 10.
:param data: original graph data
:type data: dict
:return: dict containing only the top 10 series, based on average over
the last... | def _limit_data(self, data):
"""
Find the per-day average of each series in the data over the last 7
days; drop all but the top 10.
:param data: original graph data
:type data: dict
:return: dict containing only the top 10 series, based on average over
the last... | [
"Find",
"the",
"per",
"-",
"day",
"average",
"of",
"each",
"series",
"in",
"the",
"data",
"over",
"the",
"last",
"7",
"days",
";",
"drop",
"all",
"but",
"the",
"top",
"10",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L156-L195 | [
"def",
"_limit_data",
"(",
"self",
",",
"data",
")",
":",
"if",
"len",
"(",
"data",
".",
"keys",
"(",
")",
")",
"<=",
"10",
":",
"logger",
".",
"debug",
"(",
"\"Data has less than 10 keys; not limiting\"",
")",
"return",
"data",
"# average last 7 days of each ... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | OutputGenerator._generate_graph | Generate a downloads graph; append it to ``self._graphs``.
:param name: HTML name of the graph, also used in ``self.GRAPH_KEYS``
:type name: str
:param title: human-readable title for the graph
:type title: str
:param stats_data: data dict from ``self._stats``
:type stat... | pypi_download_stats/outputgenerator.py | def _generate_graph(self, name, title, stats_data, y_name):
"""
Generate a downloads graph; append it to ``self._graphs``.
:param name: HTML name of the graph, also used in ``self.GRAPH_KEYS``
:type name: str
:param title: human-readable title for the graph
:type title: ... | def _generate_graph(self, name, title, stats_data, y_name):
"""
Generate a downloads graph; append it to ``self._graphs``.
:param name: HTML name of the graph, also used in ``self.GRAPH_KEYS``
:type name: str
:param title: human-readable title for the graph
:type title: ... | [
"Generate",
"a",
"downloads",
"graph",
";",
"append",
"it",
"to",
"self",
".",
"_graphs",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L197-L223 | [
"def",
"_generate_graph",
"(",
"self",
",",
"name",
",",
"title",
",",
"stats_data",
",",
"y_name",
")",
":",
"logger",
".",
"debug",
"(",
"'Generating chart data for %s graph'",
",",
"name",
")",
"orig_data",
",",
"labels",
"=",
"self",
".",
"_data_dict_to_bo... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | OutputGenerator._generate_badges | Generate download badges. Append them to ``self._badges``. | pypi_download_stats/outputgenerator.py | def _generate_badges(self):
"""
Generate download badges. Append them to ``self._badges``.
"""
daycount = self._stats.downloads_per_day
day = self._generate_badge('Downloads', '%d/day' % daycount)
self._badges['per-day'] = day
weekcount = self._stats.downloads_per... | def _generate_badges(self):
"""
Generate download badges. Append them to ``self._badges``.
"""
daycount = self._stats.downloads_per_day
day = self._generate_badge('Downloads', '%d/day' % daycount)
self._badges['per-day'] = day
weekcount = self._stats.downloads_per... | [
"Generate",
"download",
"badges",
".",
"Append",
"them",
"to",
"self",
".",
"_badges",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L225-L243 | [
"def",
"_generate_badges",
"(",
"self",
")",
":",
"daycount",
"=",
"self",
".",
"_stats",
".",
"downloads_per_day",
"day",
"=",
"self",
".",
"_generate_badge",
"(",
"'Downloads'",
",",
"'%d/day'",
"%",
"daycount",
")",
"self",
".",
"_badges",
"[",
"'per-day'... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | OutputGenerator._generate_badge | Generate SVG for one badge via shields.io.
:param subject: subject; left-hand side of badge
:type subject: str
:param status: status; right-hand side of badge
:type status: str
:return: badge SVG
:rtype: str | pypi_download_stats/outputgenerator.py | def _generate_badge(self, subject, status):
"""
Generate SVG for one badge via shields.io.
:param subject: subject; left-hand side of badge
:type subject: str
:param status: status; right-hand side of badge
:type status: str
:return: badge SVG
:rtype: str... | def _generate_badge(self, subject, status):
"""
Generate SVG for one badge via shields.io.
:param subject: subject; left-hand side of badge
:type subject: str
:param status: status; right-hand side of badge
:type status: str
:return: badge SVG
:rtype: str... | [
"Generate",
"SVG",
"for",
"one",
"badge",
"via",
"shields",
".",
"io",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L245-L264 | [
"def",
"_generate_badge",
"(",
"self",
",",
"subject",
",",
"status",
")",
":",
"url",
"=",
"'https://img.shields.io/badge/%s-%s-brightgreen.svg'",
"'?style=flat&maxAge=3600'",
"%",
"(",
"subject",
",",
"status",
")",
"logger",
".",
"debug",
"(",
"\"Getting badge for ... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | OutputGenerator.generate | Generate all output types and write to disk. | pypi_download_stats/outputgenerator.py | def generate(self):
"""
Generate all output types and write to disk.
"""
logger.info('Generating graphs')
self._generate_graph(
'by-version',
'Downloads by Version',
self._stats.per_version_data,
'Version'
)
self._ge... | def generate(self):
"""
Generate all output types and write to disk.
"""
logger.info('Generating graphs')
self._generate_graph(
'by-version',
'Downloads by Version',
self._stats.per_version_data,
'Version'
)
self._ge... | [
"Generate",
"all",
"output",
"types",
"and",
"write",
"to",
"disk",
"."
] | jantman/pypi-download-stats | python | https://github.com/jantman/pypi-download-stats/blob/44a7a6bbcd61a9e7f02bd02c52584a98183f80c5/pypi_download_stats/outputgenerator.py#L266-L325 | [
"def",
"generate",
"(",
"self",
")",
":",
"logger",
".",
"info",
"(",
"'Generating graphs'",
")",
"self",
".",
"_generate_graph",
"(",
"'by-version'",
",",
"'Downloads by Version'",
",",
"self",
".",
"_stats",
".",
"per_version_data",
",",
"'Version'",
")",
"s... | 44a7a6bbcd61a9e7f02bd02c52584a98183f80c5 |
train | datetime_format | Replaces format style phrases (listed in the dt_exps dictionary)
with this datetime instance's information.
.. code :: python
reusables.datetime_format("Hey, it's {month-full} already!")
"Hey, it's March already!"
:param desired_format: string to add datetime details too
:param dateti... | reusables/dt.py | def datetime_format(desired_format, datetime_instance=None, *args, **kwargs):
"""
Replaces format style phrases (listed in the dt_exps dictionary)
with this datetime instance's information.
.. code :: python
reusables.datetime_format("Hey, it's {month-full} already!")
"Hey, it's March... | def datetime_format(desired_format, datetime_instance=None, *args, **kwargs):
"""
Replaces format style phrases (listed in the dt_exps dictionary)
with this datetime instance's information.
.. code :: python
reusables.datetime_format("Hey, it's {month-full} already!")
"Hey, it's March... | [
"Replaces",
"format",
"style",
"phrases",
"(",
"listed",
"in",
"the",
"dt_exps",
"dictionary",
")",
"with",
"this",
"datetime",
"instance",
"s",
"information",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/dt.py#L55-L75 | [
"def",
"datetime_format",
"(",
"desired_format",
",",
"datetime_instance",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"strf",
",",
"exp",
"in",
"datetime_regex",
".",
"datetime",
".",
"format",
".",
"items",
"(",
")",
":",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | datetime_from_iso | Create a DateTime object from a ISO string
.. code :: python
reusables.datetime_from_iso('2017-03-10T12:56:55.031863')
datetime.datetime(2017, 3, 10, 12, 56, 55, 31863)
:param iso_string: string of an ISO datetime
:return: DateTime object | reusables/dt.py | def datetime_from_iso(iso_string):
"""
Create a DateTime object from a ISO string
.. code :: python
reusables.datetime_from_iso('2017-03-10T12:56:55.031863')
datetime.datetime(2017, 3, 10, 12, 56, 55, 31863)
:param iso_string: string of an ISO datetime
:return: DateTime object
... | def datetime_from_iso(iso_string):
"""
Create a DateTime object from a ISO string
.. code :: python
reusables.datetime_from_iso('2017-03-10T12:56:55.031863')
datetime.datetime(2017, 3, 10, 12, 56, 55, 31863)
:param iso_string: string of an ISO datetime
:return: DateTime object
... | [
"Create",
"a",
"DateTime",
"object",
"from",
"a",
"ISO",
"string"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/dt.py#L78-L97 | [
"def",
"datetime_from_iso",
"(",
"iso_string",
")",
":",
"try",
":",
"assert",
"datetime_regex",
".",
"datetime",
".",
"datetime",
".",
"match",
"(",
"iso_string",
")",
".",
"groups",
"(",
")",
"[",
"0",
"]",
"except",
"(",
"ValueError",
",",
"AssertionErr... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | now | Get a current DateTime object. By default is local.
.. code:: python
reusables.now()
# DateTime(2016, 12, 8, 22, 5, 2, 517000)
reusables.now().format("It's {24-hour}:{min}")
# "It's 22:05"
:param utc: bool, default False, UTC time not local
:param tz: TimeZone as specifie... | reusables/dt.py | def now(utc=False, tz=None):
"""
Get a current DateTime object. By default is local.
.. code:: python
reusables.now()
# DateTime(2016, 12, 8, 22, 5, 2, 517000)
reusables.now().format("It's {24-hour}:{min}")
# "It's 22:05"
:param utc: bool, default False, UTC time not ... | def now(utc=False, tz=None):
"""
Get a current DateTime object. By default is local.
.. code:: python
reusables.now()
# DateTime(2016, 12, 8, 22, 5, 2, 517000)
reusables.now().format("It's {24-hour}:{min}")
# "It's 22:05"
:param utc: bool, default False, UTC time not ... | [
"Get",
"a",
"current",
"DateTime",
"object",
".",
"By",
"default",
"is",
"local",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/dt.py#L100-L116 | [
"def",
"now",
"(",
"utc",
"=",
"False",
",",
"tz",
"=",
"None",
")",
":",
"return",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"if",
"utc",
"else",
"datetime",
".",
"datetime",
".",
"now",
"(",
"tz",
"=",
"tz",
")"
] | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | run | Cross platform compatible subprocess with CompletedProcess return.
No formatting or encoding is performed on the output of subprocess, so it's
output will appear the same on each version / interpreter as before.
.. code:: python
reusables.run('echo "hello world!', shell=True)
# CPython 3.... | reusables/process_helpers.py | def run(command, input=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=None, copy_local_env=False, **kwargs):
"""
Cross platform compatible subprocess with CompletedProcess return.
No formatting or encoding is performed on the output of subprocess, so it's
output will appear the s... | def run(command, input=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
timeout=None, copy_local_env=False, **kwargs):
"""
Cross platform compatible subprocess with CompletedProcess return.
No formatting or encoding is performed on the output of subprocess, so it's
output will appear the s... | [
"Cross",
"platform",
"compatible",
"subprocess",
"with",
"CompletedProcess",
"return",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/process_helpers.py#L18-L97 | [
"def",
"run",
"(",
"command",
",",
"input",
"=",
"None",
",",
"stdout",
"=",
"subprocess",
".",
"PIPE",
",",
"stderr",
"=",
"subprocess",
".",
"PIPE",
",",
"timeout",
"=",
"None",
",",
"copy_local_env",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | run_in_pool | Run a set of iterables to a function in a Threaded or MP Pool.
.. code: python
def func(a):
return a + a
reusables.run_in_pool(func, [1,2,3,4,5])
# [1, 4, 9, 16, 25]
:param target: function to run
:param iterable: positional arg to pass to function
:param threade... | reusables/process_helpers.py | def run_in_pool(target, iterable, threaded=True, processes=4,
asynchronous=False, target_kwargs=None):
""" Run a set of iterables to a function in a Threaded or MP Pool.
.. code: python
def func(a):
return a + a
reusables.run_in_pool(func, [1,2,3,4,5])
# [1... | def run_in_pool(target, iterable, threaded=True, processes=4,
asynchronous=False, target_kwargs=None):
""" Run a set of iterables to a function in a Threaded or MP Pool.
.. code: python
def func(a):
return a + a
reusables.run_in_pool(func, [1,2,3,4,5])
# [1... | [
"Run",
"a",
"set",
"of",
"iterables",
"to",
"a",
"function",
"in",
"a",
"Threaded",
"or",
"MP",
"Pool",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/process_helpers.py#L100-L133 | [
"def",
"run_in_pool",
"(",
"target",
",",
"iterable",
",",
"threaded",
"=",
"True",
",",
"processes",
"=",
"4",
",",
"asynchronous",
"=",
"False",
",",
"target_kwargs",
"=",
"None",
")",
":",
"my_pool",
"=",
"pool",
".",
"ThreadPool",
"if",
"threaded",
"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | tree_view | View a dictionary as a tree. | reusables/namespace.py | def tree_view(dictionary, level=0, sep="| "):
"""
View a dictionary as a tree.
"""
return "".join(["{0}{1}\n{2}".format(sep * level, k,
tree_view(v, level + 1, sep=sep) if isinstance(v, dict)
else "") for k, v in dictionary.items()]) | def tree_view(dictionary, level=0, sep="| "):
"""
View a dictionary as a tree.
"""
return "".join(["{0}{1}\n{2}".format(sep * level, k,
tree_view(v, level + 1, sep=sep) if isinstance(v, dict)
else "") for k, v in dictionary.items()]) | [
"View",
"a",
"dictionary",
"as",
"a",
"tree",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/namespace.py#L132-L138 | [
"def",
"tree_view",
"(",
"dictionary",
",",
"level",
"=",
"0",
",",
"sep",
"=",
"\"| \"",
")",
":",
"return",
"\"\"",
".",
"join",
"(",
"[",
"\"{0}{1}\\n{2}\"",
".",
"format",
"(",
"sep",
"*",
"level",
",",
"k",
",",
"tree_view",
"(",
"v",
",",
"l... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | Namespace.to_dict | Turn the Namespace and sub Namespaces back into a native
python dictionary.
:param in_dict: Do not use, for self recursion
:return: python dictionary of this Namespace | reusables/namespace.py | def to_dict(self, in_dict=None):
"""
Turn the Namespace and sub Namespaces back into a native
python dictionary.
:param in_dict: Do not use, for self recursion
:return: python dictionary of this Namespace
"""
in_dict = in_dict if in_dict else self
out_dic... | def to_dict(self, in_dict=None):
"""
Turn the Namespace and sub Namespaces back into a native
python dictionary.
:param in_dict: Do not use, for self recursion
:return: python dictionary of this Namespace
"""
in_dict = in_dict if in_dict else self
out_dic... | [
"Turn",
"the",
"Namespace",
"and",
"sub",
"Namespaces",
"back",
"into",
"a",
"native",
"python",
"dictionary",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/namespace.py#L111-L125 | [
"def",
"to_dict",
"(",
"self",
",",
"in_dict",
"=",
"None",
")",
":",
"in_dict",
"=",
"in_dict",
"if",
"in_dict",
"else",
"self",
"out_dict",
"=",
"dict",
"(",
")",
"for",
"k",
",",
"v",
"in",
"in_dict",
".",
"items",
"(",
")",
":",
"if",
"isinstan... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | ConfigNamespace.list | Return value of key as a list
:param item: key of value to transform
:param mod: function to map against list
:param default: value to return if item does not exist
:param spliter: character to split str on
:param strip: clean the list with the `strip`
:return: list of i... | reusables/namespace.py | def list(self, item, default=None, spliter=",", strip=True, mod=None):
""" Return value of key as a list
:param item: key of value to transform
:param mod: function to map against list
:param default: value to return if item does not exist
:param spliter: character to split str ... | def list(self, item, default=None, spliter=",", strip=True, mod=None):
""" Return value of key as a list
:param item: key of value to transform
:param mod: function to map against list
:param default: value to return if item does not exist
:param spliter: character to split str ... | [
"Return",
"value",
"of",
"key",
"as",
"a",
"list"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/namespace.py#L220-L241 | [
"def",
"list",
"(",
"self",
",",
"item",
",",
"default",
"=",
"None",
",",
"spliter",
"=",
"\",\"",
",",
"strip",
"=",
"True",
",",
"mod",
"=",
"None",
")",
":",
"try",
":",
"item",
"=",
"self",
".",
"__getattr__",
"(",
"item",
")",
"except",
"At... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | download | Download a given URL to either file or memory
:param url: Full url (with protocol) of path to download
:param save_to_file: boolean if it should be saved to file or not
:param save_dir: location of saved file, default is current working dir
:param filename: filename to save as
:param block_size: do... | reusables/web.py | def download(url, save_to_file=True, save_dir=".", filename=None,
block_size=64000, overwrite=False, quiet=False):
"""
Download a given URL to either file or memory
:param url: Full url (with protocol) of path to download
:param save_to_file: boolean if it should be saved to file or not
... | def download(url, save_to_file=True, save_dir=".", filename=None,
block_size=64000, overwrite=False, quiet=False):
"""
Download a given URL to either file or memory
:param url: Full url (with protocol) of path to download
:param save_to_file: boolean if it should be saved to file or not
... | [
"Download",
"a",
"given",
"URL",
"to",
"either",
"file",
"or",
"memory"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/web.py#L31-L93 | [
"def",
"download",
"(",
"url",
",",
"save_to_file",
"=",
"True",
",",
"save_dir",
"=",
"\".\"",
",",
"filename",
"=",
"None",
",",
"block_size",
"=",
"64000",
",",
"overwrite",
"=",
"False",
",",
"quiet",
"=",
"False",
")",
":",
"if",
"save_to_file",
"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | url_to_ips | Provide a list of IP addresses, uses `socket.getaddrinfo`
.. code:: python
reusables.url_to_ips("example.com", ipv6=True)
# ['2606:2800:220:1:248:1893:25c8:1946']
:param url: hostname to resolve to IP addresses
:param port: port to send to getaddrinfo
:param ipv6: Return IPv6 address ... | reusables/web.py | def url_to_ips(url, port=None, ipv6=False, connect_type=socket.SOCK_STREAM,
proto=socket.IPPROTO_TCP, flags=0):
"""
Provide a list of IP addresses, uses `socket.getaddrinfo`
.. code:: python
reusables.url_to_ips("example.com", ipv6=True)
# ['2606:2800:220:1:248:1893:25c8:194... | def url_to_ips(url, port=None, ipv6=False, connect_type=socket.SOCK_STREAM,
proto=socket.IPPROTO_TCP, flags=0):
"""
Provide a list of IP addresses, uses `socket.getaddrinfo`
.. code:: python
reusables.url_to_ips("example.com", ipv6=True)
# ['2606:2800:220:1:248:1893:25c8:194... | [
"Provide",
"a",
"list",
"of",
"IP",
"addresses",
"uses",
"socket",
".",
"getaddrinfo"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/web.py#L137-L166 | [
"def",
"url_to_ips",
"(",
"url",
",",
"port",
"=",
"None",
",",
"ipv6",
"=",
"False",
",",
"connect_type",
"=",
"socket",
".",
"SOCK_STREAM",
",",
"proto",
"=",
"socket",
".",
"IPPROTO_TCP",
",",
"flags",
"=",
"0",
")",
":",
"try",
":",
"results",
"=... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | ip_to_url | Resolve a hostname based off an IP address.
This is very limited and will
probably not return any results if it is a shared IP address or an
address with improperly setup DNS records.
.. code:: python
reusables.ip_to_url('93.184.216.34') # example.com
# None
reusables.ip_to_u... | reusables/web.py | def ip_to_url(ip_addr):
"""
Resolve a hostname based off an IP address.
This is very limited and will
probably not return any results if it is a shared IP address or an
address with improperly setup DNS records.
.. code:: python
reusables.ip_to_url('93.184.216.34') # example.com
... | def ip_to_url(ip_addr):
"""
Resolve a hostname based off an IP address.
This is very limited and will
probably not return any results if it is a shared IP address or an
address with improperly setup DNS records.
.. code:: python
reusables.ip_to_url('93.184.216.34') # example.com
... | [
"Resolve",
"a",
"hostname",
"based",
"off",
"an",
"IP",
"address",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/web.py#L187-L210 | [
"def",
"ip_to_url",
"(",
"ip_addr",
")",
":",
"try",
":",
"return",
"socket",
".",
"gethostbyaddr",
"(",
"ip_addr",
")",
"[",
"0",
"]",
"except",
"(",
"socket",
".",
"gaierror",
",",
"socket",
".",
"herror",
")",
":",
"logger",
".",
"exception",
"(",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | ThreadedServer.start | Create a background thread for httpd and serve 'forever | reusables/web.py | def start(self):
"""Create a background thread for httpd and serve 'forever'"""
self._process = threading.Thread(target=self._background_runner)
self._process.start() | def start(self):
"""Create a background thread for httpd and serve 'forever'"""
self._process = threading.Thread(target=self._background_runner)
self._process.start() | [
"Create",
"a",
"background",
"thread",
"for",
"httpd",
"and",
"serve",
"forever"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/web.py#L126-L129 | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"_process",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"self",
".",
"_background_runner",
")",
"self",
".",
"_process",
".",
"start",
"(",
")"
] | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | get_stream_handler | Returns a set up stream handler to add to a logger.
:param stream: which stream to use, defaults to sys.stderr
:param level: logging level to set handler at
:param log_format: formatter to use
:return: stream handler | reusables/log.py | def get_stream_handler(stream=sys.stderr, level=logging.INFO,
log_format=log_formats.easy_read):
"""
Returns a set up stream handler to add to a logger.
:param stream: which stream to use, defaults to sys.stderr
:param level: logging level to set handler at
:param log_format:... | def get_stream_handler(stream=sys.stderr, level=logging.INFO,
log_format=log_formats.easy_read):
"""
Returns a set up stream handler to add to a logger.
:param stream: which stream to use, defaults to sys.stderr
:param level: logging level to set handler at
:param log_format:... | [
"Returns",
"a",
"set",
"up",
"stream",
"handler",
"to",
"add",
"to",
"a",
"logger",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L46-L59 | [
"def",
"get_stream_handler",
"(",
"stream",
"=",
"sys",
".",
"stderr",
",",
"level",
"=",
"logging",
".",
"INFO",
",",
"log_format",
"=",
"log_formats",
".",
"easy_read",
")",
":",
"sh",
"=",
"logging",
".",
"StreamHandler",
"(",
"stream",
")",
"sh",
"."... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | get_file_handler | Set up a file handler to add to a logger.
:param file_path: file to write the log to, defaults to out.log
:param level: logging level to set handler at
:param log_format: formatter to use
:param handler: logging handler to use, defaults to FileHandler
:param handler_kwargs: options to pass to the h... | reusables/log.py | def get_file_handler(file_path="out.log", level=logging.INFO,
log_format=log_formats.easy_read,
handler=logging.FileHandler,
**handler_kwargs):
"""
Set up a file handler to add to a logger.
:param file_path: file to write the log to, defaults t... | def get_file_handler(file_path="out.log", level=logging.INFO,
log_format=log_formats.easy_read,
handler=logging.FileHandler,
**handler_kwargs):
"""
Set up a file handler to add to a logger.
:param file_path: file to write the log to, defaults t... | [
"Set",
"up",
"a",
"file",
"handler",
"to",
"add",
"to",
"a",
"logger",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L62-L79 | [
"def",
"get_file_handler",
"(",
"file_path",
"=",
"\"out.log\"",
",",
"level",
"=",
"logging",
".",
"INFO",
",",
"log_format",
"=",
"log_formats",
".",
"easy_read",
",",
"handler",
"=",
"logging",
".",
"FileHandler",
",",
"*",
"*",
"handler_kwargs",
")",
":"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | setup_logger | Grabs the specified logger and adds wanted handlers to it. Will
default to adding a stream handler.
:param module_name: logger name to use
:param level: logging level to set logger at
:param stream: stream to log to, or None
:param file_path: file path to log to, or None
:param log_format: form... | reusables/log.py | def setup_logger(module_name=None, level=logging.INFO, stream=sys.stderr,
file_path=None, log_format=log_formats.easy_read,
suppress_warning=True):
"""
Grabs the specified logger and adds wanted handlers to it. Will
default to adding a stream handler.
:param module_nam... | def setup_logger(module_name=None, level=logging.INFO, stream=sys.stderr,
file_path=None, log_format=log_formats.easy_read,
suppress_warning=True):
"""
Grabs the specified logger and adds wanted handlers to it. Will
default to adding a stream handler.
:param module_nam... | [
"Grabs",
"the",
"specified",
"logger",
"and",
"adds",
"wanted",
"handlers",
"to",
"it",
".",
"Will",
"default",
"to",
"adding",
"a",
"stream",
"handler",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L82-L108 | [
"def",
"setup_logger",
"(",
"module_name",
"=",
"None",
",",
"level",
"=",
"logging",
".",
"INFO",
",",
"stream",
"=",
"sys",
".",
"stderr",
",",
"file_path",
"=",
"None",
",",
"log_format",
"=",
"log_formats",
".",
"easy_read",
",",
"suppress_warning",
"=... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | add_stream_handler | Addes a newly created stream handler to the specified logger
:param logger: logging name or object to modify, defaults to root logger
:param stream: which stream to use, defaults to sys.stderr
:param level: logging level to set handler at
:param log_format: formatter to use | reusables/log.py | def add_stream_handler(logger=None, stream=sys.stderr, level=logging.INFO,
log_format=log_formats.easy_read):
"""
Addes a newly created stream handler to the specified logger
:param logger: logging name or object to modify, defaults to root logger
:param stream: which stream to u... | def add_stream_handler(logger=None, stream=sys.stderr, level=logging.INFO,
log_format=log_formats.easy_read):
"""
Addes a newly created stream handler to the specified logger
:param logger: logging name or object to modify, defaults to root logger
:param stream: which stream to u... | [
"Addes",
"a",
"newly",
"created",
"stream",
"handler",
"to",
"the",
"specified",
"logger"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L118-L131 | [
"def",
"add_stream_handler",
"(",
"logger",
"=",
"None",
",",
"stream",
"=",
"sys",
".",
"stderr",
",",
"level",
"=",
"logging",
".",
"INFO",
",",
"log_format",
"=",
"log_formats",
".",
"easy_read",
")",
":",
"if",
"not",
"isinstance",
"(",
"logger",
","... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | add_file_handler | Addes a newly created file handler to the specified logger
:param logger: logging name or object to modify, defaults to root logger
:param file_path: path to file to log to
:param level: logging level to set handler at
:param log_format: formatter to use | reusables/log.py | def add_file_handler(logger=None, file_path="out.log", level=logging.INFO,
log_format=log_formats.easy_read):
"""
Addes a newly created file handler to the specified logger
:param logger: logging name or object to modify, defaults to root logger
:param file_path: path to file to lo... | def add_file_handler(logger=None, file_path="out.log", level=logging.INFO,
log_format=log_formats.easy_read):
"""
Addes a newly created file handler to the specified logger
:param logger: logging name or object to modify, defaults to root logger
:param file_path: path to file to lo... | [
"Addes",
"a",
"newly",
"created",
"file",
"handler",
"to",
"the",
"specified",
"logger"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L134-L147 | [
"def",
"add_file_handler",
"(",
"logger",
"=",
"None",
",",
"file_path",
"=",
"\"out.log\"",
",",
"level",
"=",
"logging",
".",
"INFO",
",",
"log_format",
"=",
"log_formats",
".",
"easy_read",
")",
":",
"if",
"not",
"isinstance",
"(",
"logger",
",",
"loggi... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | add_rotating_file_handler | Adds a rotating file handler to the specified logger.
:param logger: logging name or object to modify, defaults to root logger
:param file_path: path to file to log to
:param level: logging level to set handler at
:param log_format: log formatter
:param max_bytes: Max file size in bytes before rota... | reusables/log.py | def add_rotating_file_handler(logger=None, file_path="out.log",
level=logging.INFO,
log_format=log_formats.easy_read,
max_bytes=10*sizes.mb, backup_count=5,
**handler_kwargs):
""" Adds a rotating ... | def add_rotating_file_handler(logger=None, file_path="out.log",
level=logging.INFO,
log_format=log_formats.easy_read,
max_bytes=10*sizes.mb, backup_count=5,
**handler_kwargs):
""" Adds a rotating ... | [
"Adds",
"a",
"rotating",
"file",
"handler",
"to",
"the",
"specified",
"logger",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L150-L172 | [
"def",
"add_rotating_file_handler",
"(",
"logger",
"=",
"None",
",",
"file_path",
"=",
"\"out.log\"",
",",
"level",
"=",
"logging",
".",
"INFO",
",",
"log_format",
"=",
"log_formats",
".",
"easy_read",
",",
"max_bytes",
"=",
"10",
"*",
"sizes",
".",
"mb",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | add_timed_rotating_file_handler | Adds a timed rotating file handler to the specified logger.
Defaults to weekly rotation, with 5 backups.
:param logger: logging name or object to modify, defaults to root logger
:param file_path: path to file to log to
:param level: logging level to set handler at
:param log_format: log formatter
... | reusables/log.py | def add_timed_rotating_file_handler(logger=None, file_path="out.log",
level=logging.INFO,
log_format=log_formats.easy_read,
when='w0', interval=1, backup_count=5,
**handler_kwa... | def add_timed_rotating_file_handler(logger=None, file_path="out.log",
level=logging.INFO,
log_format=log_formats.easy_read,
when='w0', interval=1, backup_count=5,
**handler_kwa... | [
"Adds",
"a",
"timed",
"rotating",
"file",
"handler",
"to",
"the",
"specified",
"logger",
".",
"Defaults",
"to",
"weekly",
"rotation",
"with",
"5",
"backups",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L175-L200 | [
"def",
"add_timed_rotating_file_handler",
"(",
"logger",
"=",
"None",
",",
"file_path",
"=",
"\"out.log\"",
",",
"level",
"=",
"logging",
".",
"INFO",
",",
"log_format",
"=",
"log_formats",
".",
"easy_read",
",",
"when",
"=",
"'w0'",
",",
"interval",
"=",
"1... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | remove_stream_handlers | Remove only stream handlers from the specified logger
:param logger: logging name or object to modify, defaults to root logger | reusables/log.py | def remove_stream_handlers(logger=None):
"""
Remove only stream handlers from the specified logger
:param logger: logging name or object to modify, defaults to root logger
"""
if not isinstance(logger, logging.Logger):
logger = logging.getLogger(logger)
new_handlers = []
for handle... | def remove_stream_handlers(logger=None):
"""
Remove only stream handlers from the specified logger
:param logger: logging name or object to modify, defaults to root logger
"""
if not isinstance(logger, logging.Logger):
logger = logging.getLogger(logger)
new_handlers = []
for handle... | [
"Remove",
"only",
"stream",
"handlers",
"from",
"the",
"specified",
"logger"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L203-L221 | [
"def",
"remove_stream_handlers",
"(",
"logger",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"logger",
",",
"logging",
".",
"Logger",
")",
":",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"logger",
")",
"new_handlers",
"=",
"[",
"]",
"for"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | remove_file_handlers | Remove only file handlers from the specified logger. Will go through
and close each handler for safety.
:param logger: logging name or object to modify, defaults to root logger | reusables/log.py | def remove_file_handlers(logger=None):
"""
Remove only file handlers from the specified logger. Will go through
and close each handler for safety.
:param logger: logging name or object to modify, defaults to root logger
"""
if not isinstance(logger, logging.Logger):
logger = logging.get... | def remove_file_handlers(logger=None):
"""
Remove only file handlers from the specified logger. Will go through
and close each handler for safety.
:param logger: logging name or object to modify, defaults to root logger
"""
if not isinstance(logger, logging.Logger):
logger = logging.get... | [
"Remove",
"only",
"file",
"handlers",
"from",
"the",
"specified",
"logger",
".",
"Will",
"go",
"through",
"and",
"close",
"each",
"handler",
"for",
"safety",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L224-L240 | [
"def",
"remove_file_handlers",
"(",
"logger",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"logger",
",",
"logging",
".",
"Logger",
")",
":",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"logger",
")",
"new_handlers",
"=",
"[",
"]",
"for",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | remove_all_handlers | Safely remove all handlers from the logger
:param logger: logging name or object to modify, defaults to root logger | reusables/log.py | def remove_all_handlers(logger=None):
"""
Safely remove all handlers from the logger
:param logger: logging name or object to modify, defaults to root logger
"""
if not isinstance(logger, logging.Logger):
logger = logging.getLogger(logger)
remove_file_handlers(logger)
logger.handle... | def remove_all_handlers(logger=None):
"""
Safely remove all handlers from the logger
:param logger: logging name or object to modify, defaults to root logger
"""
if not isinstance(logger, logging.Logger):
logger = logging.getLogger(logger)
remove_file_handlers(logger)
logger.handle... | [
"Safely",
"remove",
"all",
"handlers",
"from",
"the",
"logger"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L243-L253 | [
"def",
"remove_all_handlers",
"(",
"logger",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"logger",
",",
"logging",
".",
"Logger",
")",
":",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"logger",
")",
"remove_file_handlers",
"(",
"logger",
")... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | change_logger_levels | Go through the logger and handlers and update their levels to the
one specified.
:param logger: logging name or object to modify, defaults to root logger
:param level: logging level to set at (10=Debug, 20=Info, 30=Warn, 40=Error) | reusables/log.py | def change_logger_levels(logger=None, level=logging.DEBUG):
"""
Go through the logger and handlers and update their levels to the
one specified.
:param logger: logging name or object to modify, defaults to root logger
:param level: logging level to set at (10=Debug, 20=Info, 30=Warn, 40=Error)
... | def change_logger_levels(logger=None, level=logging.DEBUG):
"""
Go through the logger and handlers and update their levels to the
one specified.
:param logger: logging name or object to modify, defaults to root logger
:param level: logging level to set at (10=Debug, 20=Info, 30=Warn, 40=Error)
... | [
"Go",
"through",
"the",
"logger",
"and",
"handlers",
"and",
"update",
"their",
"levels",
"to",
"the",
"one",
"specified",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L256-L269 | [
"def",
"change_logger_levels",
"(",
"logger",
"=",
"None",
",",
"level",
"=",
"logging",
".",
"DEBUG",
")",
":",
"if",
"not",
"isinstance",
"(",
"logger",
",",
"logging",
".",
"Logger",
")",
":",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"logger",... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | get_registered_loggers | Find the names of all loggers currently registered
:param hide_children: only return top level logger names
:param hide_reusables: hide the reusables loggers
:return: list of logger names | reusables/log.py | def get_registered_loggers(hide_children=False, hide_reusables=False):
"""
Find the names of all loggers currently registered
:param hide_children: only return top level logger names
:param hide_reusables: hide the reusables loggers
:return: list of logger names
"""
return [logger for logg... | def get_registered_loggers(hide_children=False, hide_reusables=False):
"""
Find the names of all loggers currently registered
:param hide_children: only return top level logger names
:param hide_reusables: hide the reusables loggers
:return: list of logger names
"""
return [logger for logg... | [
"Find",
"the",
"names",
"of",
"all",
"loggers",
"currently",
"registered"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/log.py#L272-L283 | [
"def",
"get_registered_loggers",
"(",
"hide_children",
"=",
"False",
",",
"hide_reusables",
"=",
"False",
")",
":",
"return",
"[",
"logger",
"for",
"logger",
"in",
"logging",
".",
"Logger",
".",
"manager",
".",
"loggerDict",
".",
"keys",
"(",
")",
"if",
"n... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | unique | Wrapper. Makes sure the function's return value has not been returned before
or else it run with the same inputs again.
.. code: python
import reusables
import random
@reusables.unique(max_retries=100)
def poor_uuid():
return random.randint(0, 10)
print([p... | reusables/wrappers.py | def unique(max_retries=10, wait=0, alt_return="-no_alt_return-",
exception=Exception, error_text=None):
"""
Wrapper. Makes sure the function's return value has not been returned before
or else it run with the same inputs again.
.. code: python
import reusables
import random
... | def unique(max_retries=10, wait=0, alt_return="-no_alt_return-",
exception=Exception, error_text=None):
"""
Wrapper. Makes sure the function's return value has not been returned before
or else it run with the same inputs again.
.. code: python
import reusables
import random
... | [
"Wrapper",
".",
"Makes",
"sure",
"the",
"function",
"s",
"return",
"value",
"has",
"not",
"been",
"returned",
"before",
"or",
"else",
"it",
"run",
"with",
"the",
"same",
"inputs",
"again",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/wrappers.py#L37-L87 | [
"def",
"unique",
"(",
"max_retries",
"=",
"10",
",",
"wait",
"=",
"0",
",",
"alt_return",
"=",
"\"-no_alt_return-\"",
",",
"exception",
"=",
"Exception",
",",
"error_text",
"=",
"None",
")",
":",
"def",
"func_wrap",
"(",
"func",
")",
":",
"@",
"wraps",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | lock_it | Wrapper. Simple wrapper to make sure a function is only run once at a time.
.. code: python
import reusables
import time
def func_one(_):
time.sleep(5)
@reusables.lock_it()
def func_two(_):
time.sleep(5)
@reusables.time_it(message="test_1 ... | reusables/wrappers.py | def lock_it(lock=g_lock):
"""
Wrapper. Simple wrapper to make sure a function is only run once at a time.
.. code: python
import reusables
import time
def func_one(_):
time.sleep(5)
@reusables.lock_it()
def func_two(_):
time.sleep(5)
... | def lock_it(lock=g_lock):
"""
Wrapper. Simple wrapper to make sure a function is only run once at a time.
.. code: python
import reusables
import time
def func_one(_):
time.sleep(5)
@reusables.lock_it()
def func_two(_):
time.sleep(5)
... | [
"Wrapper",
".",
"Simple",
"wrapper",
"to",
"make",
"sure",
"a",
"function",
"is",
"only",
"run",
"once",
"at",
"a",
"time",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/wrappers.py#L90-L129 | [
"def",
"lock_it",
"(",
"lock",
"=",
"g_lock",
")",
":",
"def",
"func_wrapper",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"lock",
":",
"return",
"func",
"(... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | time_it | Wrapper. Time the amount of time it takes the execution of the function
and print it.
If log is true, make sure to set the logging level of 'reusables' to INFO
level or lower.
.. code:: python
import time
import reusables
reusables.add_stream_handler('reusables')
@re... | reusables/wrappers.py | def time_it(log=None, message=None, append=None):
"""
Wrapper. Time the amount of time it takes the execution of the function
and print it.
If log is true, make sure to set the logging level of 'reusables' to INFO
level or lower.
.. code:: python
import time
import reusables
... | def time_it(log=None, message=None, append=None):
"""
Wrapper. Time the amount of time it takes the execution of the function
and print it.
If log is true, make sure to set the logging level of 'reusables' to INFO
level or lower.
.. code:: python
import time
import reusables
... | [
"Wrapper",
".",
"Time",
"the",
"amount",
"of",
"time",
"it",
"takes",
"the",
"execution",
"of",
"the",
"function",
"and",
"print",
"it",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/wrappers.py#L132-L193 | [
"def",
"time_it",
"(",
"log",
"=",
"None",
",",
"message",
"=",
"None",
",",
"append",
"=",
"None",
")",
":",
"def",
"func_wrapper",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | queue_it | Wrapper. Instead of returning the result of the function, add it to a queue.
.. code: python
import reusables
import queue
my_queue = queue.Queue()
@reusables.queue_it(my_queue)
def func(a):
return a
func(10)
print(my_queue.get())
# 1... | reusables/wrappers.py | def queue_it(queue=g_queue, **put_args):
"""
Wrapper. Instead of returning the result of the function, add it to a queue.
.. code: python
import reusables
import queue
my_queue = queue.Queue()
@reusables.queue_it(my_queue)
def func(a):
return a
... | def queue_it(queue=g_queue, **put_args):
"""
Wrapper. Instead of returning the result of the function, add it to a queue.
.. code: python
import reusables
import queue
my_queue = queue.Queue()
@reusables.queue_it(my_queue)
def func(a):
return a
... | [
"Wrapper",
".",
"Instead",
"of",
"returning",
"the",
"result",
"of",
"the",
"function",
"add",
"it",
"to",
"a",
"queue",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/wrappers.py#L196-L224 | [
"def",
"queue_it",
"(",
"queue",
"=",
"g_queue",
",",
"*",
"*",
"put_args",
")",
":",
"def",
"func_wrapper",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"queue",
".... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | log_exception | Wrapper. Log the traceback to any exceptions raised. Possible to raise
custom exception.
.. code :: python
@reusables.log_exception()
def test():
raise Exception("Bad")
# 2016-12-26 12:38:01,381 - reusables ERROR Exception in test - Bad
# Traceback (most recent ... | reusables/wrappers.py | def log_exception(log="reusables", message=None, exceptions=(Exception, ),
level=logging.ERROR, show_traceback=True):
"""
Wrapper. Log the traceback to any exceptions raised. Possible to raise
custom exception.
.. code :: python
@reusables.log_exception()
def test():
... | def log_exception(log="reusables", message=None, exceptions=(Exception, ),
level=logging.ERROR, show_traceback=True):
"""
Wrapper. Log the traceback to any exceptions raised. Possible to raise
custom exception.
.. code :: python
@reusables.log_exception()
def test():
... | [
"Wrapper",
".",
"Log",
"the",
"traceback",
"to",
"any",
"exceptions",
"raised",
".",
"Possible",
"to",
"raise",
"custom",
"exception",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/wrappers.py#L227-L272 | [
"def",
"log_exception",
"(",
"log",
"=",
"\"reusables\"",
",",
"message",
"=",
"None",
",",
"exceptions",
"=",
"(",
"Exception",
",",
")",
",",
"level",
"=",
"logging",
".",
"ERROR",
",",
"show_traceback",
"=",
"True",
")",
":",
"def",
"func_wrapper",
"(... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | catch_it | If the function encounters an exception, catch it, and
return the specified default or sent to a handler function instead.
.. code :: python
def handle_error(exception, func, *args, **kwargs):
print(f"{func.__name__} raised {exception} when called with {args}")
@reusables.catch_it... | reusables/wrappers.py | def catch_it(exceptions=(Exception, ), default=None, handler=None):
"""
If the function encounters an exception, catch it, and
return the specified default or sent to a handler function instead.
.. code :: python
def handle_error(exception, func, *args, **kwargs):
print(f"{func.__n... | def catch_it(exceptions=(Exception, ), default=None, handler=None):
"""
If the function encounters an exception, catch it, and
return the specified default or sent to a handler function instead.
.. code :: python
def handle_error(exception, func, *args, **kwargs):
print(f"{func.__n... | [
"If",
"the",
"function",
"encounters",
"an",
"exception",
"catch",
"it",
"and",
"return",
"the",
"specified",
"default",
"or",
"sent",
"to",
"a",
"handler",
"function",
"instead",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/wrappers.py#L275-L304 | [
"def",
"catch_it",
"(",
"exceptions",
"=",
"(",
"Exception",
",",
")",
",",
"default",
"=",
"None",
",",
"handler",
"=",
"None",
")",
":",
"def",
"func_wrapper",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"ar... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | retry_it | Retry a function if an exception is raised, or if output_check returns
False.
Message format options: {func} {args} {kwargs}
:param exceptions: tuple of exceptions to catch
:param tries: number of tries to retry the function
:param wait: time to wait between executions in seconds
:param handle... | reusables/wrappers.py | def retry_it(exceptions=(Exception, ), tries=10, wait=0, handler=None,
raised_exception=ReusablesError, raised_message=None):
"""
Retry a function if an exception is raised, or if output_check returns
False.
Message format options: {func} {args} {kwargs}
:param exceptions: tuple of ex... | def retry_it(exceptions=(Exception, ), tries=10, wait=0, handler=None,
raised_exception=ReusablesError, raised_message=None):
"""
Retry a function if an exception is raised, or if output_check returns
False.
Message format options: {func} {args} {kwargs}
:param exceptions: tuple of ex... | [
"Retry",
"a",
"function",
"if",
"an",
"exception",
"is",
"raised",
"or",
"if",
"output_check",
"returns",
"False",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/wrappers.py#L307-L351 | [
"def",
"retry_it",
"(",
"exceptions",
"=",
"(",
"Exception",
",",
")",
",",
"tries",
"=",
"10",
",",
"wait",
"=",
"0",
",",
"handler",
"=",
"None",
",",
"raised_exception",
"=",
"ReusablesError",
",",
"raised_message",
"=",
"None",
")",
":",
"def",
"fu... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | extract | Automatically detect archive type and extract all files to specified path.
.. code:: python
import os
os.listdir(".")
# ['test_structure.zip']
reusables.extract("test_structure.zip")
os.listdir(".")
# [ 'test_structure', 'test_structure.zip']
:param archive... | reusables/file_operations.py | def extract(archive_file, path=".", delete_on_success=False,
enable_rar=False):
"""
Automatically detect archive type and extract all files to specified path.
.. code:: python
import os
os.listdir(".")
# ['test_structure.zip']
reusables.extract("test_structure... | def extract(archive_file, path=".", delete_on_success=False,
enable_rar=False):
"""
Automatically detect archive type and extract all files to specified path.
.. code:: python
import os
os.listdir(".")
# ['test_structure.zip']
reusables.extract("test_structure... | [
"Automatically",
"detect",
"archive",
"type",
"and",
"extract",
"all",
"files",
"to",
"specified",
"path",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L35-L92 | [
"def",
"extract",
"(",
"archive_file",
",",
"path",
"=",
"\".\"",
",",
"delete_on_success",
"=",
"False",
",",
"enable_rar",
"=",
"False",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"archive_file",
")",
"or",
"not",
"os",
".",
"path"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | archive | Archive a list of files (or files inside a folder), can chose between
- zip
- tar
- gz (tar.gz, tgz)
- bz2 (tar.bz2)
.. code:: python
reusables.archive(['reusables', '.travis.yml'],
name="my_archive.bz2")
# 'C:\\Users\\Me\\Reusables\\m... | reusables/file_operations.py | def archive(files_to_archive, name="archive.zip", archive_type=None,
overwrite=False, store=False, depth=None, err_non_exist=True,
allow_zip_64=True, **tarfile_kwargs):
""" Archive a list of files (or files inside a folder), can chose between
- zip
- tar
- gz (tar.gz... | def archive(files_to_archive, name="archive.zip", archive_type=None,
overwrite=False, store=False, depth=None, err_non_exist=True,
allow_zip_64=True, **tarfile_kwargs):
""" Archive a list of files (or files inside a folder), can chose between
- zip
- tar
- gz (tar.gz... | [
"Archive",
"a",
"list",
"of",
"files",
"(",
"or",
"files",
"inside",
"a",
"folder",
")",
"can",
"chose",
"between"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L95-L183 | [
"def",
"archive",
"(",
"files_to_archive",
",",
"name",
"=",
"\"archive.zip\"",
",",
"archive_type",
"=",
"None",
",",
"overwrite",
"=",
"False",
",",
"store",
"=",
"False",
",",
"depth",
"=",
"None",
",",
"err_non_exist",
"=",
"True",
",",
"allow_zip_64",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | list_to_csv | Save a matrix (list of lists) to a file as a CSV
.. code:: python
my_list = [["Name", "Location"],
["Chris", "South Pole"],
["Harry", "Depth of Winter"],
["Bob", "Skull"]]
reusables.list_to_csv(my_list, "example.csv")
example.csv
... | reusables/file_operations.py | def list_to_csv(my_list, csv_file):
"""
Save a matrix (list of lists) to a file as a CSV
.. code:: python
my_list = [["Name", "Location"],
["Chris", "South Pole"],
["Harry", "Depth of Winter"],
["Bob", "Skull"]]
reusables.list_to_cs... | def list_to_csv(my_list, csv_file):
"""
Save a matrix (list of lists) to a file as a CSV
.. code:: python
my_list = [["Name", "Location"],
["Chris", "South Pole"],
["Harry", "Depth of Winter"],
["Bob", "Skull"]]
reusables.list_to_cs... | [
"Save",
"a",
"matrix",
"(",
"list",
"of",
"lists",
")",
"to",
"a",
"file",
"as",
"a",
"CSV"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L186-L220 | [
"def",
"list_to_csv",
"(",
"my_list",
",",
"csv_file",
")",
":",
"if",
"PY3",
":",
"csv_handler",
"=",
"open",
"(",
"csv_file",
",",
"'w'",
",",
"newline",
"=",
"''",
")",
"else",
":",
"csv_handler",
"=",
"open",
"(",
"csv_file",
",",
"'wb'",
")",
"t... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | csv_to_list | Open and transform a CSV file into a matrix (list of lists).
.. code:: python
reusables.csv_to_list("example.csv")
# [['Name', 'Location'],
# ['Chris', 'South Pole'],
# ['Harry', 'Depth of Winter'],
# ['Bob', 'Skull']]
:param csv_file: Path to CSV file as str
:r... | reusables/file_operations.py | def csv_to_list(csv_file):
"""
Open and transform a CSV file into a matrix (list of lists).
.. code:: python
reusables.csv_to_list("example.csv")
# [['Name', 'Location'],
# ['Chris', 'South Pole'],
# ['Harry', 'Depth of Winter'],
# ['Bob', 'Skull']]
:param c... | def csv_to_list(csv_file):
"""
Open and transform a CSV file into a matrix (list of lists).
.. code:: python
reusables.csv_to_list("example.csv")
# [['Name', 'Location'],
# ['Chris', 'South Pole'],
# ['Harry', 'Depth of Winter'],
# ['Bob', 'Skull']]
:param c... | [
"Open",
"and",
"transform",
"a",
"CSV",
"file",
"into",
"a",
"matrix",
"(",
"list",
"of",
"lists",
")",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L223-L239 | [
"def",
"csv_to_list",
"(",
"csv_file",
")",
":",
"with",
"open",
"(",
"csv_file",
",",
"'r'",
"if",
"PY3",
"else",
"'rb'",
")",
"as",
"f",
":",
"return",
"list",
"(",
"csv",
".",
"reader",
"(",
"f",
")",
")"
] | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | load_json | Open and load data from a JSON file
.. code:: python
reusables.load_json("example.json")
# {u'key_1': u'val_1', u'key_for_dict': {u'sub_dict_key': 8}}
:param json_file: Path to JSON file as string
:param kwargs: Additional arguments for the json.load command
:return: Dictionary | reusables/file_operations.py | def load_json(json_file, **kwargs):
"""
Open and load data from a JSON file
.. code:: python
reusables.load_json("example.json")
# {u'key_1': u'val_1', u'key_for_dict': {u'sub_dict_key': 8}}
:param json_file: Path to JSON file as string
:param kwargs: Additional arguments for the ... | def load_json(json_file, **kwargs):
"""
Open and load data from a JSON file
.. code:: python
reusables.load_json("example.json")
# {u'key_1': u'val_1', u'key_for_dict': {u'sub_dict_key': 8}}
:param json_file: Path to JSON file as string
:param kwargs: Additional arguments for the ... | [
"Open",
"and",
"load",
"data",
"from",
"a",
"JSON",
"file"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L242-L256 | [
"def",
"load_json",
"(",
"json_file",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"open",
"(",
"json_file",
")",
"as",
"f",
":",
"return",
"json",
".",
"load",
"(",
"f",
",",
"*",
"*",
"kwargs",
")"
] | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | save_json | Takes a dictionary and saves it to a file as JSON
.. code:: python
my_dict = {"key_1": "val_1",
"key_for_dict": {"sub_dict_key": 8}}
reusables.save_json(my_dict,"example.json")
example.json
.. code::
{
"key_1": "val_1",
"key_for_dict":... | reusables/file_operations.py | def save_json(data, json_file, indent=4, **kwargs):
"""
Takes a dictionary and saves it to a file as JSON
.. code:: python
my_dict = {"key_1": "val_1",
"key_for_dict": {"sub_dict_key": 8}}
reusables.save_json(my_dict,"example.json")
example.json
.. code::
... | def save_json(data, json_file, indent=4, **kwargs):
"""
Takes a dictionary and saves it to a file as JSON
.. code:: python
my_dict = {"key_1": "val_1",
"key_for_dict": {"sub_dict_key": 8}}
reusables.save_json(my_dict,"example.json")
example.json
.. code::
... | [
"Takes",
"a",
"dictionary",
"and",
"saves",
"it",
"to",
"a",
"file",
"as",
"JSON"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L259-L287 | [
"def",
"save_json",
"(",
"data",
",",
"json_file",
",",
"indent",
"=",
"4",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"open",
"(",
"json_file",
",",
"\"w\"",
")",
"as",
"f",
":",
"json",
".",
"dump",
"(",
"data",
",",
"f",
",",
"indent",
"=",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | config_dict | Return configuration options as dictionary. Accepts either a single
config file or a list of files. Auto find will search for all .cfg, .config
and .ini in the execution directory and package root (unsafe but handy).
.. code:: python
reusables.config_dict(os.path.join("test", "data", "test_config.... | reusables/file_operations.py | def config_dict(config_file=None, auto_find=False, verify=True, **cfg_options):
"""
Return configuration options as dictionary. Accepts either a single
config file or a list of files. Auto find will search for all .cfg, .config
and .ini in the execution directory and package root (unsafe but handy).
... | def config_dict(config_file=None, auto_find=False, verify=True, **cfg_options):
"""
Return configuration options as dictionary. Accepts either a single
config file or a list of files. Auto find will search for all .cfg, .config
and .ini in the execution directory and package root (unsafe but handy).
... | [
"Return",
"configuration",
"options",
"as",
"dictionary",
".",
"Accepts",
"either",
"a",
"single",
"config",
"file",
"or",
"a",
"list",
"of",
"files",
".",
"Auto",
"find",
"will",
"search",
"for",
"all",
".",
"cfg",
".",
"config",
"and",
".",
"ini",
"in"... | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L290-L340 | [
"def",
"config_dict",
"(",
"config_file",
"=",
"None",
",",
"auto_find",
"=",
"False",
",",
"verify",
"=",
"True",
",",
"*",
"*",
"cfg_options",
")",
":",
"if",
"not",
"config_file",
":",
"config_file",
"=",
"[",
"]",
"cfg_parser",
"=",
"ConfigParser",
"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | config_namespace | Return configuration options as a Namespace.
.. code:: python
reusables.config_namespace(os.path.join("test", "data",
"test_config.ini"))
# <Namespace: {'General': {'example': 'A regul...>
:param config_file: path or paths to the files location... | reusables/file_operations.py | def config_namespace(config_file=None, auto_find=False,
verify=True, **cfg_options):
"""
Return configuration options as a Namespace.
.. code:: python
reusables.config_namespace(os.path.join("test", "data",
"test_config.ini"))
... | def config_namespace(config_file=None, auto_find=False,
verify=True, **cfg_options):
"""
Return configuration options as a Namespace.
.. code:: python
reusables.config_namespace(os.path.join("test", "data",
"test_config.ini"))
... | [
"Return",
"configuration",
"options",
"as",
"a",
"Namespace",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L343-L362 | [
"def",
"config_namespace",
"(",
"config_file",
"=",
"None",
",",
"auto_find",
"=",
"False",
",",
"verify",
"=",
"True",
",",
"*",
"*",
"cfg_options",
")",
":",
"return",
"ConfigNamespace",
"(",
"*",
"*",
"config_dict",
"(",
"config_file",
",",
"auto_find",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | _walk | Internal function to return walk generator either from os or scandir
:param directory: directory to traverse
:param enable_scandir: on python < 3.5 enable external scandir package
:param kwargs: arguments to pass to walk function
:return: walk generator | reusables/file_operations.py | def _walk(directory, enable_scandir=False, **kwargs):
"""
Internal function to return walk generator either from os or scandir
:param directory: directory to traverse
:param enable_scandir: on python < 3.5 enable external scandir package
:param kwargs: arguments to pass to walk function
:return... | def _walk(directory, enable_scandir=False, **kwargs):
"""
Internal function to return walk generator either from os or scandir
:param directory: directory to traverse
:param enable_scandir: on python < 3.5 enable external scandir package
:param kwargs: arguments to pass to walk function
:return... | [
"Internal",
"function",
"to",
"return",
"walk",
"generator",
"either",
"from",
"os",
"or",
"scandir"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L365-L378 | [
"def",
"_walk",
"(",
"directory",
",",
"enable_scandir",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"walk",
"=",
"os",
".",
"walk",
"if",
"python_version",
"<",
"(",
"3",
",",
"5",
")",
"and",
"enable_scandir",
":",
"import",
"scandir",
"walk",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | os_tree | Return a directories contents as a dictionary hierarchy.
.. code:: python
reusables.os_tree(".")
# {'doc': {'build': {'doctrees': {},
# 'html': {'_sources': {}, '_static': {}}},
# 'source': {}},
# 'reusables': {'__pycache__': {}},
# 'test... | reusables/file_operations.py | def os_tree(directory, enable_scandir=False):
"""
Return a directories contents as a dictionary hierarchy.
.. code:: python
reusables.os_tree(".")
# {'doc': {'build': {'doctrees': {},
# 'html': {'_sources': {}, '_static': {}}},
# 'source': {}},
... | def os_tree(directory, enable_scandir=False):
"""
Return a directories contents as a dictionary hierarchy.
.. code:: python
reusables.os_tree(".")
# {'doc': {'build': {'doctrees': {},
# 'html': {'_sources': {}, '_static': {}}},
# 'source': {}},
... | [
"Return",
"a",
"directories",
"contents",
"as",
"a",
"dictionary",
"hierarchy",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L381-L422 | [
"def",
"os_tree",
"(",
"directory",
",",
"enable_scandir",
"=",
"False",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"directory",
")",
":",
"raise",
"OSError",
"(",
"\"Directory does not exist\"",
")",
"if",
"not",
"os",
".",
"path",
".... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | file_hash | Hash a given file with md5, or any other and return the hex digest. You
can run `hashlib.algorithms_available` to see which are available on your
system unless you have an archaic python version, you poor soul).
This function is designed to be non memory intensive.
.. code:: python
reusables.... | reusables/file_operations.py | def file_hash(path, hash_type="md5", block_size=65536, hex_digest=True):
"""
Hash a given file with md5, or any other and return the hex digest. You
can run `hashlib.algorithms_available` to see which are available on your
system unless you have an archaic python version, you poor soul).
This funct... | def file_hash(path, hash_type="md5", block_size=65536, hex_digest=True):
"""
Hash a given file with md5, or any other and return the hex digest. You
can run `hashlib.algorithms_available` to see which are available on your
system unless you have an archaic python version, you poor soul).
This funct... | [
"Hash",
"a",
"given",
"file",
"with",
"md5",
"or",
"any",
"other",
"and",
"return",
"the",
"hex",
"digest",
".",
"You",
"can",
"run",
"hashlib",
".",
"algorithms_available",
"to",
"see",
"which",
"are",
"available",
"on",
"your",
"system",
"unless",
"you",... | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L425-L450 | [
"def",
"file_hash",
"(",
"path",
",",
"hash_type",
"=",
"\"md5\"",
",",
"block_size",
"=",
"65536",
",",
"hex_digest",
"=",
"True",
")",
":",
"hashed",
"=",
"hashlib",
".",
"new",
"(",
"hash_type",
")",
"with",
"open",
"(",
"path",
",",
"\"rb\"",
")",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | find_files | Walk through a file directory and return an iterator of files
that match requirements. Will autodetect if name has glob as magic
characters.
Note: For the example below, you can use find_files_list to return as a
list, this is simply an easy way to show the output.
.. code:: python
list(r... | reusables/file_operations.py | def find_files(directory=".", ext=None, name=None,
match_case=False, disable_glob=False, depth=None,
abspath=False, enable_scandir=False):
"""
Walk through a file directory and return an iterator of files
that match requirements. Will autodetect if name has glob as magic
ch... | def find_files(directory=".", ext=None, name=None,
match_case=False, disable_glob=False, depth=None,
abspath=False, enable_scandir=False):
"""
Walk through a file directory and return an iterator of files
that match requirements. Will autodetect if name has glob as magic
ch... | [
"Walk",
"through",
"a",
"file",
"directory",
"and",
"return",
"an",
"iterator",
"of",
"files",
"that",
"match",
"requirements",
".",
"Will",
"autodetect",
"if",
"name",
"has",
"glob",
"as",
"magic",
"characters",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L463-L541 | [
"def",
"find_files",
"(",
"directory",
"=",
"\".\"",
",",
"ext",
"=",
"None",
",",
"name",
"=",
"None",
",",
"match_case",
"=",
"False",
",",
"disable_glob",
"=",
"False",
",",
"depth",
"=",
"None",
",",
"abspath",
"=",
"False",
",",
"enable_scandir",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | remove_empty_directories | Remove all empty folders from a path. Returns list of empty directories.
:param root_directory: base directory to start at
:param dry_run: just return a list of what would be removed
:param ignore_errors: Permissions are a pain, just ignore if you blocked
:param enable_scandir: on python < 3.5 enable e... | reusables/file_operations.py | def remove_empty_directories(root_directory, dry_run=False, ignore_errors=True,
enable_scandir=False):
"""
Remove all empty folders from a path. Returns list of empty directories.
:param root_directory: base directory to start at
:param dry_run: just return a list of what w... | def remove_empty_directories(root_directory, dry_run=False, ignore_errors=True,
enable_scandir=False):
"""
Remove all empty folders from a path. Returns list of empty directories.
:param root_directory: base directory to start at
:param dry_run: just return a list of what w... | [
"Remove",
"all",
"empty",
"folders",
"from",
"a",
"path",
".",
"Returns",
"list",
"of",
"empty",
"directories",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L544-L592 | [
"def",
"remove_empty_directories",
"(",
"root_directory",
",",
"dry_run",
"=",
"False",
",",
"ignore_errors",
"=",
"True",
",",
"enable_scandir",
"=",
"False",
")",
":",
"listdir",
"=",
"os",
".",
"listdir",
"if",
"python_version",
"<",
"(",
"3",
",",
"5",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | remove_empty_files | Remove all empty files from a path. Returns list of the empty files removed.
:param root_directory: base directory to start at
:param dry_run: just return a list of what would be removed
:param ignore_errors: Permissions are a pain, just ignore if you blocked
:param enable_scandir: on python < 3.5 enab... | reusables/file_operations.py | def remove_empty_files(root_directory, dry_run=False, ignore_errors=True,
enable_scandir=False):
"""
Remove all empty files from a path. Returns list of the empty files removed.
:param root_directory: base directory to start at
:param dry_run: just return a list of what would be ... | def remove_empty_files(root_directory, dry_run=False, ignore_errors=True,
enable_scandir=False):
"""
Remove all empty files from a path. Returns list of the empty files removed.
:param root_directory: base directory to start at
:param dry_run: just return a list of what would be ... | [
"Remove",
"all",
"empty",
"files",
"from",
"a",
"path",
".",
"Returns",
"list",
"of",
"the",
"empty",
"files",
"removed",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L595-L627 | [
"def",
"remove_empty_files",
"(",
"root_directory",
",",
"dry_run",
"=",
"False",
",",
"ignore_errors",
"=",
"True",
",",
"enable_scandir",
"=",
"False",
")",
":",
"file_list",
"=",
"[",
"]",
"for",
"root",
",",
"directories",
",",
"files",
"in",
"_walk",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | dup_finder | Check a directory for duplicates of the specified file. This is meant
for a single file only, for checking a directory for dups, use
directory_duplicates.
This is designed to be as fast as possible by doing lighter checks
before progressing to
more extensive ones, in order they are:
1. File si... | reusables/file_operations.py | def dup_finder(file_path, directory=".", enable_scandir=False):
"""
Check a directory for duplicates of the specified file. This is meant
for a single file only, for checking a directory for dups, use
directory_duplicates.
This is designed to be as fast as possible by doing lighter checks
befor... | def dup_finder(file_path, directory=".", enable_scandir=False):
"""
Check a directory for duplicates of the specified file. This is meant
for a single file only, for checking a directory for dups, use
directory_duplicates.
This is designed to be as fast as possible by doing lighter checks
befor... | [
"Check",
"a",
"directory",
"for",
"duplicates",
"of",
"the",
"specified",
"file",
".",
"This",
"is",
"meant",
"for",
"a",
"single",
"file",
"only",
"for",
"checking",
"a",
"directory",
"for",
"dups",
"use",
"directory_duplicates",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L630-L681 | [
"def",
"dup_finder",
"(",
"file_path",
",",
"directory",
"=",
"\".\"",
",",
"enable_scandir",
"=",
"False",
")",
":",
"size",
"=",
"os",
".",
"path",
".",
"getsize",
"(",
"file_path",
")",
"if",
"size",
"==",
"0",
":",
"for",
"empty_file",
"in",
"remov... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | directory_duplicates | Find all duplicates in a directory. Will return a list, in that list
are lists of duplicate files.
.. code: python
dups = reusables.directory_duplicates('C:\\Users\\Me\\Pictures')
print(len(dups))
# 56
print(dups)
# [['C:\\Users\\Me\\Pictures\\IMG_20161127.jpg',
... | reusables/file_operations.py | def directory_duplicates(directory, hash_type='md5', **kwargs):
"""
Find all duplicates in a directory. Will return a list, in that list
are lists of duplicate files.
.. code: python
dups = reusables.directory_duplicates('C:\\Users\\Me\\Pictures')
print(len(dups))
# 56
... | def directory_duplicates(directory, hash_type='md5', **kwargs):
"""
Find all duplicates in a directory. Will return a list, in that list
are lists of duplicate files.
.. code: python
dups = reusables.directory_duplicates('C:\\Users\\Me\\Pictures')
print(len(dups))
# 56
... | [
"Find",
"all",
"duplicates",
"in",
"a",
"directory",
".",
"Will",
"return",
"a",
"list",
"in",
"that",
"list",
"are",
"lists",
"of",
"duplicate",
"files",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L684-L715 | [
"def",
"directory_duplicates",
"(",
"directory",
",",
"hash_type",
"=",
"'md5'",
",",
"*",
"*",
"kwargs",
")",
":",
"size_map",
",",
"hash_map",
"=",
"defaultdict",
"(",
"list",
")",
",",
"defaultdict",
"(",
"list",
")",
"for",
"item",
"in",
"find_files",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | join_paths | Join multiple paths together and return the absolute path of them. If 'safe'
is specified, this function will 'clean' the path with the 'safe_path'
function. This will clean root decelerations from the path
after the first item.
Would like to do 'safe=False' instead of '**kwargs' but stupider versions
... | reusables/file_operations.py | def join_paths(*paths, **kwargs):
"""
Join multiple paths together and return the absolute path of them. If 'safe'
is specified, this function will 'clean' the path with the 'safe_path'
function. This will clean root decelerations from the path
after the first item.
Would like to do 'safe=False... | def join_paths(*paths, **kwargs):
"""
Join multiple paths together and return the absolute path of them. If 'safe'
is specified, this function will 'clean' the path with the 'safe_path'
function. This will clean root decelerations from the path
after the first item.
Would like to do 'safe=False... | [
"Join",
"multiple",
"paths",
"together",
"and",
"return",
"the",
"absolute",
"path",
"of",
"them",
".",
"If",
"safe",
"is",
"specified",
"this",
"function",
"will",
"clean",
"the",
"path",
"with",
"the",
"safe_path",
"function",
".",
"This",
"will",
"clean",... | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L728-L755 | [
"def",
"join_paths",
"(",
"*",
"paths",
",",
"*",
"*",
"kwargs",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"paths",
"[",
"0",
"]",
")",
"for",
"next_path",
"in",
"paths",
"[",
"1",
":",
"]",
":",
"path",
"=",
"os",
".",
"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | join_here | Join any path or paths as a sub directory of the current file's directory.
.. code:: python
reusables.join_here("Makefile")
# 'C:\\Reusables\\Makefile'
:param paths: paths to join together
:param kwargs: 'strict', do not strip os.sep
:param kwargs: 'safe', make them into a safe path i... | reusables/file_operations.py | def join_here(*paths, **kwargs):
"""
Join any path or paths as a sub directory of the current file's directory.
.. code:: python
reusables.join_here("Makefile")
# 'C:\\Reusables\\Makefile'
:param paths: paths to join together
:param kwargs: 'strict', do not strip os.sep
:param... | def join_here(*paths, **kwargs):
"""
Join any path or paths as a sub directory of the current file's directory.
.. code:: python
reusables.join_here("Makefile")
# 'C:\\Reusables\\Makefile'
:param paths: paths to join together
:param kwargs: 'strict', do not strip os.sep
:param... | [
"Join",
"any",
"path",
"or",
"paths",
"as",
"a",
"sub",
"directory",
"of",
"the",
"current",
"file",
"s",
"directory",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L758-L777 | [
"def",
"join_here",
"(",
"*",
"paths",
",",
"*",
"*",
"kwargs",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"\".\"",
")",
"for",
"next_path",
"in",
"paths",
":",
"next_path",
"=",
"next_path",
".",
"lstrip",
"(",
"\"\\\\\"",
")",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | check_filename | Returns a boolean stating if the filename is safe to use or not. Note that
this does not test for "legal" names accepted, but a more restricted set of:
Letters, numbers, spaces, hyphens, underscores and periods.
:param filename: name of a file as a string
:return: boolean if it is a safe file name | reusables/file_operations.py | def check_filename(filename):
"""
Returns a boolean stating if the filename is safe to use or not. Note that
this does not test for "legal" names accepted, but a more restricted set of:
Letters, numbers, spaces, hyphens, underscores and periods.
:param filename: name of a file as a string
:retu... | def check_filename(filename):
"""
Returns a boolean stating if the filename is safe to use or not. Note that
this does not test for "legal" names accepted, but a more restricted set of:
Letters, numbers, spaces, hyphens, underscores and periods.
:param filename: name of a file as a string
:retu... | [
"Returns",
"a",
"boolean",
"stating",
"if",
"the",
"filename",
"is",
"safe",
"to",
"use",
"or",
"not",
".",
"Note",
"that",
"this",
"does",
"not",
"test",
"for",
"legal",
"names",
"accepted",
"but",
"a",
"more",
"restricted",
"set",
"of",
":",
"Letters",... | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L780-L793 | [
"def",
"check_filename",
"(",
"filename",
")",
":",
"if",
"not",
"isinstance",
"(",
"filename",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"filename must be a string\"",
")",
"if",
"regex",
".",
"path",
".",
"linux",
".",
"filename",
".",
"search",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | safe_filename | Replace unsafe filename characters with underscores. Note that this does not
test for "legal" names accepted, but a more restricted set of:
Letters, numbers, spaces, hyphens, underscores and periods.
:param filename: name of a file as a string
:param replacement: character to use as a replacement of ba... | reusables/file_operations.py | def safe_filename(filename, replacement="_"):
"""
Replace unsafe filename characters with underscores. Note that this does not
test for "legal" names accepted, but a more restricted set of:
Letters, numbers, spaces, hyphens, underscores and periods.
:param filename: name of a file as a string
:... | def safe_filename(filename, replacement="_"):
"""
Replace unsafe filename characters with underscores. Note that this does not
test for "legal" names accepted, but a more restricted set of:
Letters, numbers, spaces, hyphens, underscores and periods.
:param filename: name of a file as a string
:... | [
"Replace",
"unsafe",
"filename",
"characters",
"with",
"underscores",
".",
"Note",
"that",
"this",
"does",
"not",
"test",
"for",
"legal",
"names",
"accepted",
"but",
"a",
"more",
"restricted",
"set",
"of",
":",
"Letters",
"numbers",
"spaces",
"hyphens",
"under... | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L796-L814 | [
"def",
"safe_filename",
"(",
"filename",
",",
"replacement",
"=",
"\"_\"",
")",
":",
"if",
"not",
"isinstance",
"(",
"filename",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"filename must be a string\"",
")",
"if",
"regex",
".",
"path",
".",
"linux",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | safe_path | Replace unsafe path characters with underscores. Do NOT use this
with existing paths that cannot be modified, this to to help generate
new, clean paths.
Supports windows and *nix systems.
:param path: path as a string
:param replacement: character to use in place of bad characters
:return: a s... | reusables/file_operations.py | def safe_path(path, replacement="_"):
"""
Replace unsafe path characters with underscores. Do NOT use this
with existing paths that cannot be modified, this to to help generate
new, clean paths.
Supports windows and *nix systems.
:param path: path as a string
:param replacement: character ... | def safe_path(path, replacement="_"):
"""
Replace unsafe path characters with underscores. Do NOT use this
with existing paths that cannot be modified, this to to help generate
new, clean paths.
Supports windows and *nix systems.
:param path: path as a string
:param replacement: character ... | [
"Replace",
"unsafe",
"path",
"characters",
"with",
"underscores",
".",
"Do",
"NOT",
"use",
"this",
"with",
"existing",
"paths",
"that",
"cannot",
"be",
"modified",
"this",
"to",
"to",
"help",
"generate",
"new",
"clean",
"paths",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/file_operations.py#L817-L853 | [
"def",
"safe_path",
"(",
"path",
",",
"replacement",
"=",
"\"_\"",
")",
":",
"if",
"not",
"isinstance",
"(",
"path",
",",
"str",
")",
":",
"raise",
"TypeError",
"(",
"\"path must be a string\"",
")",
"if",
"os",
".",
"sep",
"not",
"in",
"path",
":",
"r... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | Tasker.change_task_size | Blocking request to change number of running tasks | reusables/tasker.py | def change_task_size(self, size):
"""Blocking request to change number of running tasks"""
self._pause.value = True
self.log.debug("About to change task size to {0}".format(size))
try:
size = int(size)
except ValueError:
self.log.error("Cannot change task ... | def change_task_size(self, size):
"""Blocking request to change number of running tasks"""
self._pause.value = True
self.log.debug("About to change task size to {0}".format(size))
try:
size = int(size)
except ValueError:
self.log.error("Cannot change task ... | [
"Blocking",
"request",
"to",
"change",
"number",
"of",
"running",
"tasks"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/tasker.py#L128-L163 | [
"def",
"change_task_size",
"(",
"self",
",",
"size",
")",
":",
"self",
".",
"_pause",
".",
"value",
"=",
"True",
"self",
".",
"log",
".",
"debug",
"(",
"\"About to change task size to {0}\"",
".",
"format",
"(",
"size",
")",
")",
"try",
":",
"size",
"=",... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | Tasker.stop | Hard stop the server and sub process | reusables/tasker.py | def stop(self):
"""Hard stop the server and sub process"""
self._end.value = True
if self.background_process:
try:
self.background_process.terminate()
except Exception:
pass
for task_id, values in self.current_tasks.items():
... | def stop(self):
"""Hard stop the server and sub process"""
self._end.value = True
if self.background_process:
try:
self.background_process.terminate()
except Exception:
pass
for task_id, values in self.current_tasks.items():
... | [
"Hard",
"stop",
"the",
"server",
"and",
"sub",
"process"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/tasker.py#L165-L177 | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"_end",
".",
"value",
"=",
"True",
"if",
"self",
".",
"background_process",
":",
"try",
":",
"self",
".",
"background_process",
".",
"terminate",
"(",
")",
"except",
"Exception",
":",
"pass",
"for",
"t... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | Tasker.get_state | Get general information about the state of the class | reusables/tasker.py | def get_state(self):
"""Get general information about the state of the class"""
return {"started": (True if self.background_process and
self.background_process.is_alive() else False),
"paused": self._pause.value,
"stopped": self._end.value,
... | def get_state(self):
"""Get general information about the state of the class"""
return {"started": (True if self.background_process and
self.background_process.is_alive() else False),
"paused": self._pause.value,
"stopped": self._end.value,
... | [
"Get",
"general",
"information",
"about",
"the",
"state",
"of",
"the",
"class"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/tasker.py#L187-L195 | [
"def",
"get_state",
"(",
"self",
")",
":",
"return",
"{",
"\"started\"",
":",
"(",
"True",
"if",
"self",
".",
"background_process",
"and",
"self",
".",
"background_process",
".",
"is_alive",
"(",
")",
"else",
"False",
")",
",",
"\"paused\"",
":",
"self",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | Tasker.main_loop | Blocking function that can be run directly, if so would probably
want to specify 'stop_at_empty' to true, or have a separate process
adding items to the queue. | reusables/tasker.py | def main_loop(self, stop_at_empty=False):
"""Blocking function that can be run directly, if so would probably
want to specify 'stop_at_empty' to true, or have a separate process
adding items to the queue. """
try:
while True:
self.hook_pre_command()
... | def main_loop(self, stop_at_empty=False):
"""Blocking function that can be run directly, if so would probably
want to specify 'stop_at_empty' to true, or have a separate process
adding items to the queue. """
try:
while True:
self.hook_pre_command()
... | [
"Blocking",
"function",
"that",
"can",
"be",
"run",
"directly",
"if",
"so",
"would",
"probably",
"want",
"to",
"specify",
"stop_at_empty",
"to",
"true",
"or",
"have",
"a",
"separate",
"process",
"adding",
"items",
"to",
"the",
"queue",
"."
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/tasker.py#L232-L269 | [
"def",
"main_loop",
"(",
"self",
",",
"stop_at_empty",
"=",
"False",
")",
":",
"try",
":",
"while",
"True",
":",
"self",
".",
"hook_pre_command",
"(",
")",
"self",
".",
"_check_command_queue",
"(",
")",
"if",
"self",
".",
"run_until",
"and",
"self",
".",... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | Tasker.run | Start the main loop as a background process. *nix only | reusables/tasker.py | def run(self):
"""Start the main loop as a background process. *nix only"""
if win_based:
raise NotImplementedError("Please run main_loop, "
"backgrounding not supported on Windows")
self.background_process = mp.Process(target=self.main_loop)
... | def run(self):
"""Start the main loop as a background process. *nix only"""
if win_based:
raise NotImplementedError("Please run main_loop, "
"backgrounding not supported on Windows")
self.background_process = mp.Process(target=self.main_loop)
... | [
"Start",
"the",
"main",
"loop",
"as",
"a",
"background",
"process",
".",
"*",
"nix",
"only"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/tasker.py#L271-L277 | [
"def",
"run",
"(",
"self",
")",
":",
"if",
"win_based",
":",
"raise",
"NotImplementedError",
"(",
"\"Please run main_loop, \"",
"\"backgrounding not supported on Windows\"",
")",
"self",
".",
"background_process",
"=",
"mp",
".",
"Process",
"(",
"target",
"=",
"self... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | cmd | Run a shell command and have it automatically decoded and printed
:param command: Command to run as str
:param ignore_stderr: To not print stderr
:param raise_on_return: Run CompletedProcess.check_returncode()
:param timeout: timeout to pass to communicate if python 3
:param encoding: How the outpu... | reusables/cli.py | def cmd(command, ignore_stderr=False, raise_on_return=False, timeout=None,
encoding="utf-8"):
""" Run a shell command and have it automatically decoded and printed
:param command: Command to run as str
:param ignore_stderr: To not print stderr
:param raise_on_return: Run CompletedProcess.check_... | def cmd(command, ignore_stderr=False, raise_on_return=False, timeout=None,
encoding="utf-8"):
""" Run a shell command and have it automatically decoded and printed
:param command: Command to run as str
:param ignore_stderr: To not print stderr
:param raise_on_return: Run CompletedProcess.check_... | [
"Run",
"a",
"shell",
"command",
"and",
"have",
"it",
"automatically",
"decoded",
"and",
"printed"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/cli.py#L29-L44 | [
"def",
"cmd",
"(",
"command",
",",
"ignore_stderr",
"=",
"False",
",",
"raise_on_return",
"=",
"False",
",",
"timeout",
"=",
"None",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"result",
"=",
"run",
"(",
"command",
",",
"timeout",
"=",
"timeout",
",",
... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
train | pushd | Change working directories in style and stay organized!
:param directory: Where do you want to go and remember?
:return: saved directory stack | reusables/cli.py | def pushd(directory):
"""Change working directories in style and stay organized!
:param directory: Where do you want to go and remember?
:return: saved directory stack
"""
directory = os.path.expanduser(directory)
_saved_paths.insert(0, os.path.abspath(os.getcwd()))
os.chdir(directory)
... | def pushd(directory):
"""Change working directories in style and stay organized!
:param directory: Where do you want to go and remember?
:return: saved directory stack
"""
directory = os.path.expanduser(directory)
_saved_paths.insert(0, os.path.abspath(os.getcwd()))
os.chdir(directory)
... | [
"Change",
"working",
"directories",
"in",
"style",
"and",
"stay",
"organized!"
] | cdgriffith/Reusables | python | https://github.com/cdgriffith/Reusables/blob/bc32f72e4baee7d76a6d58b88fcb23dd635155cd/reusables/cli.py#L47-L56 | [
"def",
"pushd",
"(",
"directory",
")",
":",
"directory",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"directory",
")",
"_saved_paths",
".",
"insert",
"(",
"0",
",",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"getcwd",
"(",
")",
")",
")"... | bc32f72e4baee7d76a6d58b88fcb23dd635155cd |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.