Exemple #1
0
 def _restore(self, args, credential):
     """
        Execute All restore operations
     """
     LOG.critical("Connect to Gmail server.")
     # Create a gmvault releaving read_only_access
     restorer = gmvault.GMVaulter(args['db-dir'], args['host'], args['port'], \
                                    args['email'], credential, read_only_access = False)
     
     #full sync is the first one
     if args.get('type', '') == 'full':
         
         #call restore
         labels = [args['label']] if args['label'] else []
         restorer.restore(extra_labels = labels, restart = args['restart'])
         
     elif args.get('type', '') == 'quick':
         
         #take the last two to 3 months depending on the current date
         
         # today - 2 months
         today = datetime.date.today()
         begin = today - datetime.timedelta(2*365/12)
         
         starting_dir = gmvault_utils.get_ym_from_datetime(begin)
         
         #call restore
         labels = [args['label']] if args['label'] else []
         restorer.restore(pivot_dir = starting_dir, extra_labels = labels, restart = args['restart'])
     
     else:
         raise ValueError("Unknown synchronisation mode %s. Please use full (default), quick.")
     
     #print error report
     LOG.critical(restorer.get_error_report()) 
Exemple #2
0
 def _sync(cls, args, credential):
     """
        Execute All synchronisation operations
     """
     LOG.critical("Connect to Gmail server.\n")
     
     # handle credential in all levels
     syncer = gmvault.GMVaulter(args['db-dir'], args['host'], args['port'], \
                                    args['email'], credential, read_only_access = True, use_encryption = args['encrypt'])
     
     
     
     #full sync is the first one
     if args.get('type', '') == 'full':
     
         #choose full sync. Ignore the request
         syncer.sync({ 'type': 'imap', 'req': 'ALL' } , compress_on_disk = args['compression'], \
                     db_cleaning = args['db-cleaning'], ownership_checking = args['ownership_control'], restart = args['restart'], \
                     emails_only = args['emails_only'], chats_only = args['chats_only'])
         
     elif args.get('type', '') == 'quick':
         
         #sync only the last x days (taken in defaults) in order to be quick (cleaning is import here because recent days might move again
         
         # today - 2 months
         today = datetime.date.today()
         begin = today - datetime.timedelta(gmvault_utils.get_conf_defaults().getint("Sync", "quick_days", 8))
         
         LOG.critical("Quick sync mode. Check for new emails since %s." % (begin.strftime('%d-%b-%Y')))
         
         # today + 1 day
         end   = today + datetime.timedelta(1)
         
         syncer.sync( { 'type': 'imap', 'req': syncer.get_imap_request_btw_2_dates(begin, end) }, \
                        compress_on_disk = args['compression'], \
                        db_cleaning = args['db-cleaning'], \
                        ownership_checking = args['ownership_control'], restart = args['restart'], \
                        emails_only = args['emails_only'], chats_only = args['chats_only'])
         
     elif args.get('type', '') == 'custom':
         
         # pass an imap request. Assume that the user know what to do here
         LOG.critical("Perform custom synchronisation with %s request: %s.\n" % (args['request']['type'], args['request']['req']))
         
         #LOG.critical("Deactivate chats syncing and database cleaning when performing a custom synchronisation.\n" )
         #deactivate everything
         #args['emails_only'] = True
         #args['chats_only']  = False
         #args['db-cleaning'] = False
         
         syncer.sync(args['request'], compress_on_disk = args['compression'], db_cleaning = args['db-cleaning'], \
                     ownership_checking = args['ownership_control'], restart = args['restart'], \
                     emails_only = args['emails_only'], chats_only = args['chats_only'])
     else:
         raise ValueError("Unknown synchronisation mode %s. Please use full (default), quick or custom.")
     
     
     #print error report
     LOG.critical(syncer.get_error_report())
Exemple #3
0
 def _check_db(cls, args, credential):
     """
        Check DB
     """
     LOG.critical("Connect to Gmail server.\n")
     
     # handle credential in all levels
     checker = gmvault.GMVaulter(args['db-dir'], args['host'], args['port'], \
                                args['email'], credential, read_only_access = True)
     
     checker.check_clean_db(db_cleaning = True)
Exemple #4
0
 def _sync(self, args, credential):
     """
        Execute All synchronisation operations
     """
     
     LOG.critical("Connect to Gmail server.")
     
     # handle credential in all levels
     syncer = gmvault.GMVaulter(args['db-dir'], args['host'], args['port'], \
                                    args['email'], credential, read_only_access = True, use_encryption = args['encrypt'])
     
     
     
     #full sync is the first one
     if args.get('type', '') == 'full':
     
         #choose full sync. Ignore the request
         syncer.sync({ 'type': 'imap', 'req': 'ALL' } , compress_on_disk = True, \
                     db_cleaning = args['db-cleaning'], ownership_checking = args['ownership_control'])
         
     elif args.get('type', '') == 'quick':
         
         #sync only the last 2 months in order to be quick (cleaning is import here because recent days might move again
         
         # today - 2 months
         today = datetime.date.today()
         begin = today - datetime.timedelta(2*365/12)
         
         # today + 1 day
         end   = today + datetime.timedelta(1)
         
         syncer.sync( { 'type': 'imap', 'req': syncer.get_imap_request_btw_2_dates(begin, end) }, \
                        compress_on_disk = True, \
                        db_cleaning = args['db-cleaning'], \
                        ownership_checking = args['ownership_control'])
         
     elif args.get('type', '') == 'custom':
         
         # pass an imap request. Assume that the user know what to do here
         LOG.critical("Perform custom synchronisation with request: %s" % (args['request']['req']))
         
         syncer.sync(args['request'], compress_on_disk = True, db_cleaning = args['db-cleaning'], \
                     ownership_checking = args['ownership_control'])
     else:
         raise ValueError("Unknown synchronisation mode %s. Please use full (default), quick or custom.")
     
     
     #print error report
     LOG.critical(syncer.get_error_report())
    def run(self, args, credential):
        """
           Run the grep with the given args 
        """
        on_error = True
        die_with_usage = True

        try:

            # hanlde credential in all levels
            syncer = gmvault.GMVaulter(args['db-dir'], args['host'], args['port'], \
                                       args['email'], credential)

            syncer.sync(args['request'],
                        compress_on_disk=True,
                        db_cleaning=args['db-cleaning'])

            on_error = False

        except KeyboardInterrupt, _:
            LOG.critical("CRTL^C. Stop all operations.")
            on_error = False