Permalink
Browse files

Merge branch 'processor_for_simple_android_app' into develop

  • Loading branch information...
2 parents efcdb52 + ba8dd2d commit 1f1d5cc00f0d9eaf5c6f02a6c2501dc676f0eeda @jensck committed Jan 17, 2013
Showing with 73 additions and 10 deletions.
  1. +55 −2 fluidity/boxidate.py
  2. +6 −1 fluidity/defs.py
  3. +12 −7 fluidity/slider.py
View
@@ -14,6 +14,7 @@
import datetime
import json
import os
+import pathlib
import pickle
import shutil
import string # IGNORE:W0402 # the string module is not deprecated!
@@ -32,6 +33,7 @@
from fluidity import defs
from fluidity import dbus_misc
from fluidity import gio_fml
+from fluidity import slider
INBOXES = ()
@@ -54,7 +56,15 @@ def consolidate():
else:
inboxes.append(MountableInbox(ibx))
- inboxes.extend((RESTInbox(), TomboyInbox()))
+ inboxes.extend((
+ # CONFIG FOR WHICH INBOXES GET USED AND WHICH DON'T
+ # terrible place for it, but this is the kind of thing
+ # that's going away when I finally get around to
+ # refactoring all this
+# RESTInbox(),
+ DropboxInbox(),
+ TomboyInbox(), # this should probably always be the last one.
+ ))
for i in inboxes:
i.consolidate()
@@ -234,7 +244,9 @@ def build_aggregate_note(self, notelist):
el = len(self.TB_CONTENT_START)
for n in notelist:
n = os.path.join(self.MAIN_INBOX, n)
- c = open(n, 'r').read()
+ opened = open(n, 'r')
+ c = opened.read()
+ opened.close()
c_begin = c.find(self.TB_CONTENT_START) + el
c_end = c.find(self.TB_CONTENT_END)
aggregate += c[c_begin:c_end] + self.PADDING
@@ -324,6 +336,37 @@ def _horrible_hack_to_get_NV_inbox(self):
return personal_content
+class DropboxInbox(Inbox):
+
+ NOTE_GLOB = 'inbox_note*.protobytes'
+
+ def consolidate(self):
+ for note_path in defs.DROPBOX_INBOX_PATH.glob(DropboxInbox.NOTE_GLOB):
+ self._process_android_inbox_note(note_path)
+ # now handle the remaining files.
+ for path in defs.DROPBOX_INBOX_PATH.glob('*'):
+ # leave dotfiles alone, for stuff like dropsync
+ if not str(path).startswith('.'):
+ self._process_android_inbox_note(note_path)
+
+ def _process_regular_file(self, path):
+ print("Processing regular file:", path)
+ shutil.move(str(path), defs.INBOX_FOLDER)
+
+ def _process_android_inbox_note(self, note_path):
+ print("Processing note:", note_path)
+ abs_path = str(note_path.absolute())
+ with open(abs_path, 'r') as notefile:
+ note_text = notefile.read()
+
+ # the android inbox app takes no 'details' info yet.
+ slider.create_inbox_note(note_text, "")
+
+ # we're done with the file, ditch it.
+ gf = gio.File(abs_path)
+ gf.trash()
+
+
class BoxidatorOld(object):
"""Consolidate my inboxes, including content from an external Tomboy note."""
@@ -573,3 +616,13 @@ def _convert_xml(element):
# # sftp.put(to_upload, remote_path + basename)
# # sftp.close()
#===================================================================================
+
+
+def main():
+ di = DropboxInbox()
+ di.consolidate()
+
+
+if __name__ == '__main__':
+ main()
+
View
@@ -93,6 +93,7 @@ def _get_read_review_path():
### PATHS ###
HOME_DIR = os.path.expanduser("~")
+HOME_PATH = pathlib.Path(HOME_DIR)
APP_DATA_PATH = _find_app_data_path()
USER_DATA_PATH = BaseDirectory.save_data_path("fluidity")
LOG_FILE_PATH = os.path.join(USER_DATA_PATH, 'fluidity_debug.log')
@@ -103,7 +104,11 @@ def _get_read_review_path():
BACKUPS_PATH = os.path.join(USER_DATA_PATH, "backups")
ARCHIVED_SINGLETONS_FNAME = 'archived_singletons{0}.pkl'
-HACK_HACK_HACK_DROPBOX_PATH = pathlib.Path(HOME_DIR, "Dropbox", "Fluidity")
+DROPBOX_PATH = pathlib.Path(HOME_PATH, 'Dropbox')
+DROPBOX_INBOX_PATH = pathlib.Path(DROPBOX_PATH, 'Inbox')
+
+
+HACK_HACK_HACK_DROPBOX_PATH = pathlib.Path(DROPBOX_PATH, "Fluidity")
# PROJECT SUPPORT FILE PATHS
READ_REVIEW_PATH = _get_read_review_path()
View
@@ -35,6 +35,16 @@
from fluidity.managers import DataManager
+def create_inbox_note(summary, details):
+ """Create an inbox note with the usual path and format."""
+ note = {'summary': summary, 'details': details}
+ file_name = (note['summary'][:50].replace(os.sep, '') +
+ str(time.time()) + "-note.pkl")
+ file_path = os.path.join(defs.NOTE_SLIDER_FOLDER, file_name)
+ with open(file_path, 'wb') as pickle_file:
+ pickle.dump(note, pickle_file, pickle.HIGHEST_PROTOCOL)
+
+
class Slider(object):
def __init__(self, separate_process=False):
@@ -78,13 +88,8 @@ def _autocomplete_context(self, widget):
widget.set_text(context)
def _create_inbox_note(self):
- note = {'summary': self.summary_w.get_text(),
- 'details': self.note_details_w.get_buffer().props.text}
- file_name = (note['summary'][:50].replace(os.sep, '') +
- str(time.time()) + "-note.pkl")
- file_path = os.path.join(defs.NOTE_SLIDER_FOLDER, file_name)
- with open(file_path, 'wb') as pickle_file:
- pickle.dump(note, pickle_file, pickle.HIGHEST_PROTOCOL)
+ create_inbox_note(self.summary_w.get_text(),
+ self.note_details_w.get_buffer().props.text)
self._quit()
def _create_incoming_na(self, na):

0 comments on commit 1f1d5cc

Please sign in to comment.