text stringlengths 0 828 |
|---|
if sys.platform.startswith('darwin'): |
subprocess.Popen(('open', filepath)) |
elif os.name == 'nt': |
os.startfile(filepath) |
elif os.name == 'posix': |
subprocess.Popen(('xdg-open', filepath))" |
1454,"def destination_heuristic(data): |
"""""" |
A heuristic to get the folder with all other files from bib, using majority |
vote. |
"""""" |
counter = collections.Counter() |
for entry in data: |
file_field = entry['fields'].get('file') |
if not file_field: |
continue |
path = os.path.dirname(file_field) |
counter[path] += 1 |
if not counter: # No paths found |
raise click.ClickException( |
'Path finding heuristics failed: no paths in the database' |
) |
# Find the paths that appears most often |
sorted_paths = sorted(counter, reverse=True) |
groupby = itertools.groupby(sorted_paths, key=len) |
_, group = next(groupby) |
# We know that there's at least one candidate. Make sure it's |
# the only one |
candidate = next(group) |
try: |
next(group) |
except StopIteration: |
return candidate |
else: |
raise click.ClickException( |
'Path finding heuristics failed: ' |
'there are multiple equally valid paths in the database' |
)" |
1455,"def remove_entry(data, entry): |
''' |
Remove an entry in place. |
''' |
file_field = entry['fields'].get('file') |
if file_field: |
try: |
os.remove(file_field) |
except IOError: |
click.echo('This entry\'s file was missing') |
data.remove(entry)" |
1456,"def string_to_basename(s): |
''' |
Converts to lowercase, removes non-alpha characters, |
and converts spaces to hyphens. |
''' |
s = s.strip().lower() |
s = re.sub(r'[^\w\s-]', '', s) |
return re.sub(r'[\s-]+', '-', s)" |
1457,"def editor(*args, **kwargs): |
''' |
Wrapper for `click.edit` that raises an error when None is returned. |
''' |
result = click.edit(*args, **kwargs) |
if result is None: |
msg = 'Editor exited without saving, command aborted' |
raise click.ClickException(msg) |
return result" |
1458,"def terms(self, facet_name, field, size=10, order=None, all_terms=False, exclude=[], regex='', regex_flags=''): |
''' |
Allow to specify field facets that return the N most frequent terms. |
Ordering: Allow to control the ordering of the terms facets, to be ordered by count, term, reverse_count or reverse_term. The default is count. |
All Terms: Allow to get all the terms in the terms facet, ones that do not match a hit, will have a count of 0. Note, this should not be used with fields that have many terms. |
Excluding Terms: It is possible to specify a set of terms that should be excluded from the terms facet request result. |
Regex Patterns: The terms API allows to define regex expression that will control which terms will be included in the faceted list. |
''' |
self[facet_name] = dict(terms=dict(field=field, size=size)) |
if order: |
self[facet_name][terms]['order'] = order |
if all_terms: |
self[facet_name][terms]['all_terms'] = True |
if exclude: |
self[facet_name][terms]['exclude'] = exclude |
if regex: |
self[facet_name][terms]['regex'] = regex |
if regex_flags: |
self[facet_name][terms]['regex_flags'] = regex_flags |
return self" |
1459,"def range(self, facet_name, field, ranges=[]): |
''' |
Range facet allow to specify a set of ranges and get both the number of docs (count) that fall within each range, and aggregated data either based on the field, or using another field. |
http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html |
> ElasticFacet().range('range1', 'field_name', [ slice(50), slice(20,70), slice(50,-1) ]) |
{ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.