def handle(self, *args, **options): ensure_root() for name in options['name']: try: instance = TransInstance.objects.get(name=name) except TransInstance.DoesNotExist: raise CommandError('TransInstance "%s" does not exist' % name) if instance.torrent_count > 0: # Don't allow instances with torrents to be deleted for now. Would be more complicated, destructive and # less likely for users to want to do so anyway. self.stdout.write(self.style.WARNING(u'Will not delete "%s", as it contains torrents' % instance.name)) return print u'Deleting TransInstance %s...' % instance.name self.stdout.write(self.style.NOTICE('This will remove the daemon, all related files, and the user.')) confirm() manager = TransInstanceManager(instance) manager.remove() instance.delete() # BaseCommand.style.SUCCESS was only added in Django 1.9 if hasattr(self.style, 'SUCCESS'): self.stdout.write(self.style.SUCCESS(u'Successfully deleted "%s"' % instance.name)) else: self.stdout.write(self.style.WARNING(u'Successfully deleted "%s"' % instance.name))
def handle(self, *args, **options): ensure_root() if len(args) != 1: print u'Pass only the zone name.' return zone = args[0] try: replica_set = models.ReplicaSet.objects.get(zone=zone) except models.ReplicaSet.DoesNotExist: print u'There is no replica set with the name {0}. I will create one.'.format(args[0]) confirm() replica_set = models.ReplicaSet( zone=zone, name='master', ) replica_set.save() old_instances = replica_set.transinstance_set.order_by('-port').all() if len(old_instances): old_instance = old_instances[0] else: old_instance = models.TransInstance( replica_set=replica_set, name=u'{0}00'.format(replica_set.zone), host='127.0.0.1', port=9090, peer_port=51412, username='******', password=settings.TRANSMISSION_PASSWORD, ) new_instance = models.TransInstance( replica_set=old_instance.replica_set, name=u'{0}{1:02}'.format(old_instance.name[:-2], int(old_instance.name[-2:]) + 1), host=old_instance.host, port=old_instance.port + 1, peer_port=old_instance.peer_port + 1, username=old_instance.username, password=settings.TRANSMISSION_PASSWORD, ) print new_instance.full_description() print u'Is this OK?' confirm() with transaction.atomic(): instance_manager = TransInstanceManager(new_instance) instance_manager.sync() new_instance.save() print 'Starting daemon...' instance_manager.start_daemon() print u'Instance synced and saved.'
def handle(self, *args, **options): apply_options(options) ensure_root() if len(args) != 1: print u'Pass only the zone name.' return 1 zone = args[0] ensure_replica_sets_exist() replica_set = models.ReplicaSet.objects.get(zone=zone) old_instances = replica_set.transinstance_set.order_by('-port').all() if len(old_instances): old_instance = old_instances[0] else: if replica_set.zone == models.ReplicaSet.ZONE_WHAT: zero_port = 9090 zero_peer_port = 21412 elif replica_set.zone == models.ReplicaSet.ZONE_BIBLIOTIK: zero_port = 10090 zero_peer_port = 22412 elif replica_set.zone == models.ReplicaSet.ZONE_MYANONAMOUSE: zero_port = 11090 zero_peer_port = 23412 else: raise Exception('Unknown zone') old_instance = models.TransInstance( replica_set=replica_set, name=u'{0}00'.format(replica_set.zone .replace('.cd', '') .replace('.org', '') .replace('.net', '') .replace('.me', '') .replace('.ch', '')), host='127.0.0.1', port=zero_port, peer_port=zero_peer_port, username='******', password=settings.TRANSMISSION_PASSWORD, ) new_instance = models.TransInstance( replica_set=old_instance.replica_set, name=u'{0}{1:02}'.format(old_instance.name[:-2], int(old_instance.name[-2:]) + 1), host=old_instance.host, port=old_instance.port + 1, peer_port=old_instance.peer_port + 1, username=old_instance.username, password=settings.TRANSMISSION_PASSWORD, ) print new_instance.full_description() print u'Is this OK?' confirm() with transaction.atomic(): instance_manager = TransInstanceManager(new_instance) instance_manager.sync() new_instance.save() print 'Starting daemon...' instance_manager.start_daemon() print u'Instance synced and saved.'
def handle(self, *args, **options): ensure_root() for name in options['name']: try: instance = TransInstance.objects.get(name=name) except TransInstance.DoesNotExist: raise CommandError('TransInstance "%s" does not exist' % name) if instance.torrent_count > 0: # Don't allow instances with torrents to be deleted for now. Would be more complicated, destructive and # less likely for users to want to do so anyway. self.stdout.write( self.style.WARNING( u'Will not delete "%s", as it contains torrents' % instance.name)) return print u'Deleting TransInstance %s...' % instance.name self.stdout.write( self.style.NOTICE( 'This will remove the daemon, all related files, and the user.' )) confirm() manager = TransInstanceManager(instance) manager.remove() instance.delete() # BaseCommand.style.SUCCESS was only added in Django 1.9 if hasattr(self.style, 'SUCCESS'): self.stdout.write( self.style.SUCCESS(u'Successfully deleted "%s"' % instance.name)) else: self.stdout.write( self.style.WARNING(u'Successfully deleted "%s"' % instance.name))
def handle(self, *args, **options): if os.geteuid() != 0: raise CommandError('You have to call this program as root.') for instance in models.TransInstance.objects.order_by('name'): manager = TransInstanceManager(instance) manager.start_daemon()