~time-drive-devel/time-drive/time-drive.sync

« back to all changes in this revision

Viewing changes to sync/local.py

  • Committer: Rob Oakes
  • Date: 2012-11-27 22:41:26 UTC
  • Revision ID: rob.oakes@oak-tree.us-20121127224126-pnofhrbj0vad4yzx
Added support for the deletion of remote files when they aren't present on the local disk. Worked to cleanup the downloadFile method so that it is better able to manage edge cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
## Database Methods ##
21
21
 
 
22
 
22
23
def createDataConnection(db_path):
23
24
        '''Create a connection to the database and opens a session. Returns
24
25
                both the underlying database engine and the session.'''
35
36
 
36
37
        return engine, session
37
38
 
 
39
 
38
40
def createDataTables(engine_):
39
41
        '''Check that the desired table exist'''
40
42
        Base.metadata.create_all(engine_)
41
43
 
 
44
 
42
45
def getLocalFileRecord(file_localpath, db_session):
43
46
        '''Query the local database and return the first non-deleted file'''
44
47
        dbfile_ = db_session.query(SyncFile).filter_by(
48
51
                .first()
49
52
        return dbfile_
50
53
 
 
54
 
51
55
def getLocalFolderRecord(folder_localpath, db_session):
52
56
        '''Query the local database and return the first non-deleted folder record'''
53
57
        dbfolder_ = db_session.query(SyncFile).filter_by(
54
58
                full_path=folder_localpath) \
55
59
                .filter((SyncFile.file_deleted != True) 
56
 
                        | (SyncFile.file_deleted == None))\
 
60
                        | (SyncFile.file_deleted == None)) \
57
61
                .filter(SyncFile.directory == True) \
58
62
                .first()
59
63
        return dbfolder_
60
64
 
61
65
 
 
66
def getDatabaseFolderContents(folder_localpath, db_session):
 
67
        '''Query the local database and return a list of all non-deleted records'''
 
68
        dbfolder_contents = db_session.query(SyncFile).filter_by(
 
69
                parent_directory=folder_localpath) \
 
70
                .filter((SyncFile.file_deleted != True) \
 
71
                        | (SyncFile.file_deleted == None)) \
 
72
                .all()
 
73
        return dbfolder_contents
 
74
 
 
75
 
62
76
## Database Classes ##
63
77
 
 
78
 
64
79
class SyncFile(Base):
65
80
        '''Data related to local files to be included in the sync/backup'''
66
81
        __tablename__ = 'syncfiles'