Commits

Ed Brannin committed 13b1063

Now tracking mtime of Backup files, so we can tell which is newest/oldest

Comments (0)

Files changed (4)

app_sizer/backup_import.py

 Finds the Mobile Backups, and helps locate the right Springboard plist.
 """
 
+import datetime
 import os
 import pprint
 from path import path
 
 from .utils import first_existing_home_subdir
 
+# TODO: Make all DateTime-related calculations in UTC
+
 def backups_path():
     """
     Find this system's iOS Backup folders.
             except Exception:
                 pass
 
+def get_backup_mtime(name="aeacdfd9fadbbe56548a40e02b7685d324050e54", backup_dir=None):
+    if backup_dir is None:
+        backup_dir = backup_path()
+    path = os.path.join(backup_dir, name)
+    if os.path.isfile(path):
+        return datetime.datetime.fromtimestamp(os.path.getmtime(path))
+    else:
+        print "No such file: {}".format(path)
+        return 0
+
 def read_springboard_plist(name="aeacdfd9fadbbe56548a40e02b7685d324050e54", backup_dir=None):
     if backup_dir is None:
         backup_dir = backup_path()
         this_device_name = device_name(path) or "None"
         # print "Device name is: {}".format(this_device_name.encode('utf-8'))
         plist = read_springboard_plist(backup_dir=path)
+        mtime = get_backup_mtime(backup_dir=path)
         apps = apps_in(plist)
         if len(apps) == 0:
             print "Skipping {}".format(path)
         backup.path = path
         backup.name = this_device_name
         backup.plist = plist
+        backup.mtime = mtime
         # We don't need to do any special housekeeping for existing apps;
         # sqlalchemy handles that for us.
 

app_sizer/chart/models.py

     # Springboard plist
     plist = db.Column(db.PickleType)
     plist_json = db.Column(db.Text, default=jsonify_plist, onupdate=jsonify_plist)
+    mtime = db.Column(db.DateTime)
+
     @classmethod
     def get_by_path(cls, path):
         return db.session.query(Backup).filter(Backup.path == path).first()

migrations/env.py

 from sqlalchemy import engine_from_config, pool
 from logging.config import fileConfig
 
+import app_sizer
+
 # this is the Alembic Config object, which provides
 # access to the values within the .ini file in use.
 config = context.config
 # for 'autogenerate' support
 # from myapp import mymodel
 # target_metadata = mymodel.Base.metadata
-target_metadata = None
+target_metadata = app_sizer.database.db.Model
 
 # other values from the config, defined by the needs of env.py,
 # can be acquired:

migrations/versions/43ab57ed5d00_add_backup_mtime.py

+"""Add backups.mtime
+
+Revision ID: 43ab57ed5d00
+Revises: 10601b604f88
+Create Date: 2014-06-18 00:15:04.167024
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '43ab57ed5d00'
+down_revision = '10601b604f88'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    op.add_column('backups', sa.Column('mtime', sa.DateTime(), nullable=True))
+
+
+def downgrade():
+    op.drop_column('backups', 'mtime')