示例#1
0
 def run_export_invitations(self, args, output):  # pragma: no cover
     from ekklesia.data import special_openwith
     with special_openwith(output, 'w') as f:
         self.export_invitations(f,
                                 encrypt=args.encrypt,
                                 sign=args.sign,
                                 allfields=args.all)
示例#2
0
 def run_reset_invitations(self, args):  # pragma: no cover
     from ekklesia.data import special_openwith
     if args.dryrun: self.info('simulating reset')
     with special_openwith(args.file, 'r') as f:
         self.reset_invitations(f,
                                code=args.invite,
                                uuids=args.uuid,
                                dryrun=args.dryrun)
示例#3
0
 def run_import_invitations(self, args, input):  # pragma: no cover
     from ekklesia.data import special_openwith
     if args.dryrun: self.info('simulating import')
     with special_openwith(input, 'r') as f:
         self.import_invitations(f,
                                 decrypt=args.decrypt,
                                 verify=args.verify,
                                 dryrun=args.dryrun,
                                 allfields=args.all,
                                 sync=args.sync)
示例#4
0
 def run(self, args=None):  # pragma: no cover
     from ekklesia.data import special_openwith, dummy_context
     from ekklesia.backends import session_context
     from sqlalchemy import create_engine
     args, parser = self.init_run('invitations',
                                  'invitation script for members', args)
     self.load_config(args.config)
     self.init_gnupg()
     if args.command == 'push' and args.daemon:
         daemon = self.prepare_daemon(args.pid)
     else:
         daemon = dummy_context()
     with daemon, session_context(self):
         engine = create_engine(self.database, echo=False)
         if args.command == 'init':
             if args.drop:
                 self.info('dropping tables')
                 self.open_db(engine,
                              mode='dropall' if args.all else 'drop')
             self.open_db(engine, mode='create')
             self.info('database intialized')
             if args.initial:
                 with special_openwith(args.initial[0], 'r') as f:
                     self.import_invitations(f, allfields=True)
             return
         self.open_db(engine, mode='open')
         if args.command == 'import':
             self.run_import_invitations(args, args.file)
         elif args.command == 'export':
             self.run_export_invitations(args, args.file)
         elif args.command == 'sync':
             self.run_sync_invitations(args)
         elif args.command == 'push':
             self.run_push_invitations(args)
         elif args.command == 'reset':
             self.run_reset_invitations(args)
         elif args.command == 'send':
             if args.dryrun: self.info('simulating send')
             self.send_invitations(dryrun=args.dryrun, verify=args.verify)
示例#5
0
 def run(self, args=None):  # pragma: no cover
     from ekklesia.data import special_openwith, special_open
     args, engine, parser = self.init_run(
         'members', 'synchronization of member databases', args)
     try:
         if args.command == 'init':
             self.open_db(engine, mode='create')
             self.info('database intialized')
             if args.initial:
                 with special_openwith(args.initial, 'r') as f:
                     self.import_members(f, allfields=True)
             return
         elif args.command == 'drop':
             self.info('deleting database')
             self.open_db(engine, mode='drop')
             return
         self.open_db(engine, mode='open')
     finally:
         if self.session: self.session.close()
     try:
         if args.command == 'import':
             if args.dryrun: self.info('simulating import')
             maxargs = 1 if self.department_spec == 'implicit' else 2
             assert len(
                 args.input) <= maxargs, "invalid number of input arguments"
             input = [special_open(file, 'r') for file in args.input]
             if len(input) == 1: input.append(None)
             self.import_members(memberfile=input[0],
                                 depfile=input[1],
                                 decrypt=args.decrypt,
                                 verify=args.verify,
                                 dryrun=args.dryrun,
                                 allfields=args.all)
         elif args.command == 'export':
             assert len(
                 args.output
             ) == 2 if args.all else 1, "invalid number of output arguments"
             output = [special_open(file, 'w') for file in args.output]
             if args.encrypt:
                 assert self.gpg, "GnuPG not available"
                 encrypt = self.email_receiver if args.all else self.gpgconfig[
                     'sender']  #self
             else:
                 encrypt = None
             self.export_members(output,
                                 encrypt=encrypt,
                                 sign=args.sign,
                                 allfields=args.all)
         elif args.command == 'sync':
             assert not self.member_api.sign or self.gpgconfig[
                 'sender'], 'sender for signing missing'
             if args.output:
                 assert len(
                     args.output
                 ) == 2 + self.export_emails, "invalid number of output arguments"
             if args.dryrun: self.info('simulating sync')
             try:
                 if 'location' in self.member_import: self.load_geolut()
                 input = special_open(args.input,
                                      'r') if args.input else None
                 if args.output:
                     output = [
                         special_open(file, 'w') for file in args.output
                     ]
                 else:
                     output = None
                 if self.export_invite and args.mails:
                     invitations = special_open(args.mails, 'w')
                 else:
                     invitations = None
                 self.sync_members(download=args.download,
                                   upload=args.upload,
                                   input=input,
                                   output=output,
                                   dryrun=args.dryrun,
                                   invitations=invitations)
             finally:
                 if 'location' in self.member_import: self.save_geolut()
     except:
         self.exception('')
     finally:
         self.session.close()
示例#6
0
 def run(self, args=None):  # pragma: no cover
     from ekklesia.data import special_openwith, special_open
     args, engine, parser = self.init_run('invitations',
                                          'invitation script for members',
                                          args)
     try:
         if args.command == 'init':
             self.open_db(engine, mode='create')
             self.info('database intialized')
             if args.initial:
                 with special_openwith(args.initial, 'r') as f:
                     self.import_invitations(f, allfields=True)
             return
         elif args.command == 'drop':
             self.info('deleting database')
             self.open_db(engine, mode='drop')
             return
         self.open_db(engine, mode='open')
         if args.command == 'import':
             if args.dryrun: self.info('simulating import')
             with special_openwith(args.file, 'r') as f:
                 self.import_invitations(f,
                                         decrypt=args.decrypt,
                                         verify=args.verify,
                                         dryrun=args.dryrun,
                                         allfields=args.all)
         elif args.command == 'export':
             with special_openwith(args.file, 'w') as f:
                 if args.encrypt:
                     args.encrypt = self.gpgconfig['sender']  # to self
                 self.export_invitations(f,
                                         encrypt=args.encrypt,
                                         sign=args.sign,
                                         allfields=args.all)
         elif args.command == 'sync':
             assert not self.invite_api.sign or self.gpgconfig[
                 'sender'], 'sender for signing missing'
             if args.output:
                 assert len(
                     args.output) == 1, "only one output file expected"
             if args.dryrun: self.info('simulating sync')
             input = special_open(args.input, 'r') if args.input else None
             output = special_open(args.output[0],
                                   'w') if args.output else None
             self.sync_invitations(download=args.download,
                                   upload=args.upload,
                                   input=input,
                                   output=output,
                                   dryrun=args.dryrun)
         elif args.command == 'reset':
             if args.dryrun: self.info('simulating reset')
             with special_openwith(args.file, 'r') as f:
                 self.reset_invitations(f,
                                        code=args.invite,
                                        uuids=args.uuid,
                                        dryrun=args.dryrun)
         elif args.command == 'send':
             if args.dryrun: self.info('simulating send')
             self.send_invitations(dryrun=args.dryrun)
     except:
         self.exception('')
     finally:
         self.session.close()