Skip to content

Instantly share code, notes, and snippets.

@shyba
Created October 6, 2014 15:32
Show Gist options
  • Save shyba/c700b7f012f65de53294 to your computer and use it in GitHub Desktop.
Save shyba/c700b7f012f65de53294 to your computer and use it in GitHub Desktop.
Pixelated Dev - Resets all tags and clear the index for testing purposes.
import os
from flask import Flask
from pixelated.adapter.pixelated_mail_sender import PixelatedMailSender
from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes
import pixelated.reactor_manager as reactor_manager
import pixelated.bitmask_libraries.session as LeapSession
from pixelated.adapter.mail_service import MailService
from pixelated.adapter.pixelated_mail import PixelatedMail
from pixelated.adapter.soledad_querier import SoledadQuerier
def reset_tags():
default_config_path = os.path.join(os.environ['HOME'], '.pixelated')
app = Flask(__name__, static_url_path='', static_folder=None)
app.config.from_pyfile(default_config_path)
reactor_manager.start_reactor(logging=True)
leap_session = LeapSession.open(app.config['LEAP_USERNAME'], app.config['LEAP_PASSWORD'],
app.config['LEAP_SERVER_NAME'])
SoledadQuerier.get_instance(soledad=leap_session.account._soledad)
PixelatedMail.from_email_address = leap_session.account_email()
pixelated_mailboxes = PixelatedMailBoxes(leap_session.account)
pixelated_mail_sender = PixelatedMailSender(leap_session.account_email())
global mail_service
mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender)
mails = mail_service.mails({'tags':{}})
mail_count = len(mails)
print 'Found %s mails' % mail_count
for mail in mails:
mail.update_tags(set())
mail.save()
tag_index = mail_service.tag_service.tag_index
for tag in mail_service.all_tags():
tag_index.remove(tag.name)
tag_index._close_db()
print 'All tags removed! :D'
print 'Wait for sync, then destroy reactor.'
# reactor_manager.stop_reactor_on_exit()
reset_tags()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment