def _quit(self): utils.log_line("Exiting Slider normally.", datetime.datetime.now()) # don't quit if we're not actually running as a separate process.. heh. if self._is_separate_process: gtk.main_quit() else: self.window.destroy()
def consolidate(self): utils.log_line("Running boxidate.Boxidator.consolidate()", datetime.datetime.now()) #put us in the right folder to start off with, just in case... os.chdir(self.MAIN_INBOX) # Disabled for now # self.move_contents_to_main_inbox(self.FS_INBOXES, self.MAIN_INBOX) # print "Contents of external filesystem inboxes moved." notelist = self.build_note_list(self.MAIN_INBOX) agg_xml = self.build_aggregate_note(notelist) self._back_up_SH() new_sh_xml = self.build_SH_replacement_xml(agg_xml) #FIXME: still required? time.sleep(2) msg = "".join(("Boxidate is adding this to your Start Here note:\n", new_sh_xml, "\n\n\n")) utils.log_line(msg, datetime.datetime.now(), '/home/jensck/fity-data/boxidate.log') self.set_SH_xml(new_sh_xml) self.delete_notes(notelist) # handle the stuff on Sidearm main_slider_inbox = gio.File(self.FITY_SLIDER_INBOX) main_inbox = gio.File(self.MAIN_INBOX) sidearm_sftp_inbox = gio.File(uri=self.SIDEARM_SFTP_INBOX_URI) try: # sidearm_sftp_inbox.find_enclosing_mount() sidearm_sftp_inbox.mount_enclosing_volume(gio.MountOperation(), self.import_inbox_async_cb, user_data=(sidearm_sftp_inbox, main_slider_inbox, main_inbox)) except gio.Error as error: print("Error while trying to mount sftp inbox: " + str(error))
def consolidate(self): for child in self._this_inbox.get_children(): try: utils.log_line("Moving file {0} to inbox...".format(child.path), datetime.datetime.now()) inbox = self.SLIDER_INBOX if child.ext == ".pkl" else self.MAIN_INBOX child.move(inbox.get_child(child.basename)) except gio_fml.MoveError as m_err: utils.log_line(str(m_err), datetime.datetime.now())
def consolidate(self): cb_user_data = {'cb': self.consolidate} if self._mount_volume(user_data=cb_user_data): try: super(MountableInbox, self).consolidate() except (gio.Error, ConsolidateInboxError) as error: msg = "Unable to consolidate from {0} - message: {1}".format( self._this_inbox, error) utils.log_line(msg, datetime.datetime.now()) self._unmount_volume()
def place_recurring_tasks(self): utils.log_line("Running place_recurring_tasks()", datetime.datetime.now()) self._load_data(defs.RECURRENCE_DATA) data = self._recur_data today = datetime.date.today() if self._recur_data['last_run'] < today: self._place_daily_tasks(today, data) self._place_monthly_tasks(today, data) self._place_weekly_tasks(today, data) self._recur_data['last_run'] = today self._save_data(defs.RECURRENCE_DATA)
def _create_inbox_note(self, note_dict, parent_dir): if note_dict['summary'] is None: utils.log_line("Blank summary line in REST inbox...") else: file_name = "{0}_{1}-{2}".format( note_dict['summary'][:50].replace(os.sep, ''), time.time(), "note.pkl") file_path = os.path.join(parent_dir, file_name) with open(file_path, 'wb') as pickle_file: pickle.dump(note_dict, pickle_file, pickle.HIGHEST_PROTOCOL)
def consolidate(self): notelist = self.build_note_list(self.MAIN_INBOX) agg_xml = self.build_aggregate_note(notelist) self._back_up_SH() new_sh_xml = self.build_SH_replacement_xml(agg_xml) msg = "".join(("Boxidate is adding this to your Start Here note:\n", new_sh_xml, "\n\n\n")) utils.log_line(msg, datetime.datetime.now(), '/home/jensck/fity-data/boxidate.log') self.set_SH_xml(new_sh_xml) self.delete_notes(notelist)
def _unmount_volume(self, *args): # FIXME: do I care about the fact that I'm not paying any additional # attention to unmounts? if not args: mounty = self._this_inbox._gfile.find_enclosing_mount() mounty.unmount(self._unmount_volume) else: try: args[0].unmount_finish(args[1]) except gio.Error as err: msg = "Unable to UNmount: {0}. Error: {1}".format(self._this_inbox, err) utils.log_line(msg, datetime.datetime.now())
def kill_stale_backups(self, dry_run=False): pattern = os.path.join(defs.BACKUPS_PATH, 'fluidity*.pkl*') kill_list = sorted(glob.glob(pattern)) the_book_of_life = [] for policy in self.backup_policies: the_book_of_life += self._find_saved_indexes(kill_list, **policy) the_book_of_life.sort() doomed = self._delete_doomed_files(kill_list, the_book_of_life, dry_run) elderly = [d for d in sorted(doomed) if self._is_senior_citizen(d)] message = "Damned {0} backups to the void; {1} were senior citizens." utils.log_line(message.format(len(doomed), len(elderly)), datetime.datetime.now())
def activate_due_queued(self): utils.log_line("Running activate_due_queued()", datetime.datetime.now()) for p in self.prjs: prj = self.prjs[p] if prj.status == "queued": # FIXME: if the status is queued, we should /always/ have a # queue date. What's the fallback? if prj.queue_date: if datetime.date.today() >= prj.queue_date: self.change_project_status(prj, "active") for na in self.queued_singletons: if na.queue_date <= datetime.date.today(): self.prjs['singletons'].next_actions.append(na) self.queued_singletons.remove(na)
def complete_processing(self, obj): #FIXME: wtf is this doing in here? this is GUI shit! if isinstance(obj, inbox_items.InboxStuff): selected_row = self._tree.get_selected_row_number() self._tree.remove(obj) self._tree.append(self._row_processed_stuff, obj) if isinstance(obj, inbox_items.InboxNote): self.dm.delete_stuff_note(obj) elif isinstance(obj, inbox_items.InboxFile): try: obj.trash() except gio.Error as error: msg = ("Can't trash file (called from InboxManager." "complete_processing): {0} -- error: {1}") utils.log_line(msg.format(obj.summary, error)) self._tree.refresh() self._tree.select_paths((selected_row, 0)) gobject.idle_add(self._tree.grab_focus)
def delete_prj(self, prj): utils.log_line("Deleting project: " + str(prj), datetime.datetime.now()) # trash the folders first self._file_toady.trash_project_folder(prj.summary, prj.status) # then ditch the project notes prj_ = prj ProjectNote(prj=prj_).delete() #this is /almost certainly/ The Hard Way... for a in self.aofs.keys(): matches = [] # Welcome to my entry in the "Obfuscated Python" contest! for p in xrange(len(self.aofs[a]['projects'])): if self.aofs[a]['projects'][p] == prj.key_name: matches.append({'aof': a, 'p_index': p}) for i in matches: del(self.aofs[i['aof']]['projects'][i['p_index']]) del(self.prjs[prj.key_name]) self.save_data()
def delete_prj(self, prj): utils.log_line("Deleting project: " + str(prj), datetime.datetime.now()) # trash the folders first self._file_toady.trash_project_folder(prj.summary, prj.status) # then ditch the project notes prj_ = prj ProjectNote(prj=prj_).delete() #this is /almost certainly/ The Hard Way... for a in self.aofs.keys(): matches = [] # Welcome to my entry in the "Obfuscated Python" contest! for p in xrange(len(self.aofs[a]['projects'])): if self.aofs[a]['projects'][p] == prj.key_name: matches.append({'aof': a, 'p_index': p}) for i in matches: del (self.aofs[i['aof']]['projects'][i['p_index']]) del (self.prjs[prj.key_name]) self.save_data()
def __init__(self, separate_process=False): """Initialize this Slider. Args: separate_process: If True, gtk.main_quit() will be called when the window closes. """ utils.log_line("Starting Slider", datetime.datetime.now()) self._is_separate_process = separate_process self._b = gtk.Builder() self._b.add_from_file(os.path.join(defs.APP_DATA_PATH, 'slider.ui')) self._b.connect_signals(self) self.data_lumbergh = DataManager() self._magical = MagicMachine(self.data_lumbergh) self._magic_checked = False self._map_fields_to_instance_names() self._init_ui()
def _mount_volume(self, obj=None, async_result=None, user_data=None): """Tricky crap to get around having to do proper async I/O. ;-P""" if async_result is None: # i.e.: we're not being called as a callback try: self._this_inbox.find_enclosing_mount() return True except gio.Error: # location not mounted; let's try fixing that. self._this_inbox.mount_enclosing_volume( callback=self._mount_volume, user_data=user_data) return False else: try: obj.mount_enclosing_volume_finish(async_result) except (gio.Error, glib.GError) as err: msg = "unable to mount: {0}. Error: {1}".format(self._this_inbox, err) utils.log_line(msg, datetime.datetime.now()) msg = "Unable to mount the requested volume: " + msg raise ConsolidateInboxError(msg) user_data['cb']()