text stringlengths 0 828 |
|---|
return self" |
3828,"def move_up(self): |
""""""Move up one level in the hierarchy, unless already on top."""""" |
if self.current_item.parent is not None: |
self.current_item = self.current_item.parent |
for f in self._hooks[""up""]: |
f(self) |
if self.current_item is self.root: |
for f in self._hooks[""top""]: |
f(self) |
return self" |
3829,"def move_to(self, id_): |
""""""Select a child item by id (str), reference or index."""""" |
if self.items: |
try: |
self.current_item = self.items[id_] |
except (StopIteration, IndexError, NoSuchItem): |
raise NoSuchItem |
for f in self._hooks[""select""]: |
f(self, id_) |
return self" |
3830,"def descendants(self): |
""""""Recursively return every dataset below current item."""""" |
for i in self.current_item.items: |
self.move_to(i) |
if i.type == TYPE_COLLECTION: |
for c in self.children: |
yield c |
else: |
yield i |
self.move_up()" |
3831,"def children(self): |
""""""Former, misleading name for descendants."""""" |
from warnings import warn |
warn(""Deprecated. Use Scraper.descendants."", DeprecationWarning) |
for descendant in self.descendants: |
yield descendant" |
3832,"def make_python_name(s, default=None, number_prefix='N',encoding=""utf-8""): |
""""""Returns a unicode string that can be used as a legal python identifier. |
:Arguments: |
*s* |
string |
*default* |
use *default* if *s* is ``None`` |
*number_prefix* |
string to prepend if *s* starts with a number |
"""""" |
if s in ('', None): |
s = default |
s = str(s) |
s = re.sub(""[^a-zA-Z0-9_]"", ""_"", s) |
if not re.match('\d', s) is None: |
s = number_prefix+s |
return unicode(s, encoding)" |
3833,"def recarray(self): |
""""""Returns data as :class:`numpy.recarray`."""""" |
return numpy.rec.fromrecords(self.records, names=self.names)" |
3834,"def main(arguments=None): |
"""""" |
The main function used when ``yaml_to_database.py`` when installed as a cl tool |
"""""" |
# setup the command-line util settings |
su = tools( |
arguments=arguments, |
docString=__doc__, |
logLevel=""WARNING"", |
options_first=False, |
projectName=False |
) |
arguments, settings, log, dbConn = su.setup() |
# unpack remaining cl arguments using `exec` to setup the variable names |
# automatically |
for arg, val in arguments.iteritems(): |
if arg[0] == ""-"": |
varname = arg.replace(""-"", """") + ""Flag"" |
else: |
varname = arg.replace(""<"", """").replace("">"", """") |
if isinstance(val, str) or isinstance(val, unicode): |
exec(varname + "" = '%s'"" % (val,)) |
else: |
exec(varname + "" = %s"" % (val,)) |
if arg == ""--dbConn"": |
dbConn = val |
log.debug('%s = %s' % (varname, val,)) |
if os.path.isfile(pathToYaml): |
from fundamentals.mysql import yaml_to_database |
# PARSE YAML FILE CONTENTS AND ADD TO DATABASE |
yaml2db = yaml_to_database( |
log=log, |
settings=settings, |
dbConn=dbConn |
) |
yaml2db.add_yaml_file_content_to_database( |
filepath=pathToYaml, |
deleteFile=deleteFlag |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.