text
stringlengths
0
828
subcommand = self.argv[1]
except IndexError:
#If the subcommand name cannot be found, set it to help
subcommand = 'help'
#If the subcommand is help, print the usage of the parser, and available command names
if subcommand == 'help':
if len(args) <= 2:
parser.print_help()
sys.stdout.write(self.help_text + '\n')
else:
#Otherwise, run the given command
self.fetch_command(subcommand).run_from_argv(self.argv)"
1252,"def help_text(self):
""""""
Formats and prints the help text from the command list
""""""
help_text = '\n'.join(sorted(get_commands().keys()))
help_text = ""\nCommands:\n"" + help_text
return help_text"
1253,"def missing(self, field, last=True):
'''
Numeric fields support specific handling for missing fields in a doc.
The missing value can be _last, _first, or a custom value
(that will be used for missing docs as the sort value).
missing('price')
> {""price"" : {""missing"": ""_last"" } }
missing('price',False)
> {""price"" : {""missing"": ""_first""} }
'''
if last:
self.append({field: {'missing': '_last'}})
else:
self.append({field: {'missing': '_first'}})
return self"
1254,"def ensure_table(self, cls):
""""""Ensure table's existence - as per the gludb spec.""""""
cur = self._conn().cursor()
table_name = cls.get_table_name()
index_names = cls.index_names() or []
cols = ['id text primary key', 'value text']
for name in index_names:
cols.append(name + ' text')
cur.execute('create table if not exists %s (%s)' % (
table_name,
','.join(cols)
))
for name in index_names:
cur.execute('create index if not exists %s on %s(%s)' % (
table_name + '_' + name + '_idx',
table_name,
name
))
self._conn().commit()
cur.close()"
1255,"def find_by_index(self, cls, index_name, value):
""""""Find all rows matching index query - as per the gludb spec.""""""
cur = self._conn().cursor()
query = 'select id,value from %s where %s = ?' % (
cls.get_table_name(),
index_name
)
found = []
for row in cur.execute(query, (value,)):
id, data = row[0], row[1]
obj = cls.from_data(data)
assert id == obj.id
found.append(obj)
cur.close()
return found"
1256,"def delete(self, obj):
""""""Required functionality.""""""
del_id = obj.get_id()
if not del_id:
return
cur = self._conn().cursor()
tabname = obj.__class__.get_table_name()
query = 'delete from %s where id = ?' % tabname
cur.execute(query, (del_id,))
self._conn().commit()
cur.close()"
1257,"def register(self):
"""""" Registers a new device with the name entity_id. This device has permissions for services like subscribe,
publish and access historical data.
""""""