text stringlengths 0 828 |
|---|
backup_file(filename) |
full_path = self.__generate_file(filename) |
with codecs.open(full_path, 'r', encoding=""utf-8"") as f: |
new_content = self.inject_content(f.read(), content) |
with codecs.open(full_path, 'w+', encoding=""utf-8"") as f: |
f.write(new_content)" |
1466,"def __generate_file(self, file_path): |
"""""" |
Generate the file at the file_path desired. Creates any needed |
directories on the way. returns the absolute path of the file. |
"""""" |
file_path = os.path.expanduser(file_path) |
if not os.path.exists(os.path.dirname(file_path)): |
self.logger.debug(""Directories missing! Creating directories for %s..."" % file_path) |
os.makedirs(os.path.dirname(file_path)) |
if not os.path.exists(file_path): |
open(file_path, ""w+"").close() |
return file_path" |
1467,"def in_noninjected_file(self, file_path, content): |
"""""" Checks if a string exists in the file, sans the injected """""" |
if os.path.exists(file_path): |
file_content = codecs.open(file_path, encoding=""utf-8"").read() |
file_content = self.wrapper_match.sub(u"""", file_content) |
else: |
file_content = """" |
return file_content.find(content) != -1" |
1468,"def inject_content(self, content, inject_string): |
"""""" |
Inject inject_string into a text buffer, wrapped with |
#{{ wrapper }} comments if condition lambda is not |
satisfied or is None. Remove old instances of injects if they |
exist. |
"""""" |
inject_string = _unicode(inject_string) |
content = self.wrapper_match.sub("""", _unicode(content)) |
if self.override_match: |
sprinter_overrides = self.override_match.search(content) |
if sprinter_overrides: |
content = self.override_match.sub("""", content) |
sprinter_overrides = sprinter_overrides.groups()[0] |
else: |
sprinter_overrides = """" |
content += """""" |
%s |
%s |
%s |
"""""" % (self.wrapper, inject_string.rstrip(), self.wrapper) |
if self.override_match: |
content += sprinter_overrides.rstrip() + ""\n"" |
return content" |
1469,"def clear_content(self, content): |
"""""" |
Clear the injected content from the content buffer, and return the results |
"""""" |
content = _unicode(content) |
return self.wrapper_match.sub("""", content)" |
1470,"def get_all_orders_ungrouped(self): |
"""""" |
Uses a generator to return all orders within. :py:class:`MarketOrder` |
objects are yielded directly, instead of being grouped in |
:py:class:`MarketItemsInRegionList` instances. |
.. note:: This is a generator! |
:rtype: generator |
:returns: Generates a list of :py:class:`MarketOrder` instances. |
"""""" |
for olist in self._orders.values(): |
for order in olist.orders: |
yield order" |
1471,"def add_order(self, order): |
"""""" |
Adds a MarketOrder instance to the list of market orders contained |
within this order list. Does some behind-the-scenes magic to get it |
all ready for serialization. |
:param MarketOrder order: The order to add to this order list. |
"""""" |
# This key is used to group the orders based on region. |
key = '%s_%s' % (order.region_id, order.type_id) |
if not self._orders.has_key(key): |
# We don't have any orders for this yet. Prep the region+item |
# combo by instantiating a new MarketItemsInRegionList for |
# the MarketOrders. |
self.set_empty_region( |
order.region_id, |
order.type_id, |
order.generated_at |
) |
# The MarketOrder gets stuffed into the MarketItemsInRegionList for this |
# item+region combo. |
self._orders[key].add_order(order)" |
1472,"def set_empty_region(self, region_id, type_id, generated_at, |
error_if_orders_present=True): |
"""""" |
Prepares for the given region+item combo by instantiating a |
:py:class:`MarketItemsInRegionList` instance, which will track |
region ID, type ID, and generated time. This is mostly used for |
the JSON deserialization process in case there are no orders for |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.