Feat: packaging (#127)
- Add configuration files for packaging - Precommit now uses ruff Co-authored-by: bkfox <thomas bkfox net> Reviewed-on: #127
This commit is contained in:
		@ -62,9 +62,7 @@ class Monitor:
 | 
			
		||||
 | 
			
		||||
    def get_logs_queryset(self):
 | 
			
		||||
        """Return queryset to assign as `self.logs`"""
 | 
			
		||||
        return self.station.log_set.select_related(
 | 
			
		||||
            "diffusion", "sound", "track"
 | 
			
		||||
        ).order_by("-pk")
 | 
			
		||||
        return self.station.log_set.select_related("diffusion", "sound", "track").order_by("-pk")
 | 
			
		||||
 | 
			
		||||
    def init_last_sound_logs(self):
 | 
			
		||||
        """Retrieve last logs and initialize `last_sound_logs`"""
 | 
			
		||||
@ -136,12 +134,7 @@ class Monitor:
 | 
			
		||||
        diff = None
 | 
			
		||||
        sound = Sound.objects.path(air_uri).first()
 | 
			
		||||
        if sound and sound.episode_id is not None:
 | 
			
		||||
            diff = (
 | 
			
		||||
                Diffusion.objects.episode(id=sound.episode_id)
 | 
			
		||||
                .on_air()
 | 
			
		||||
                .now(air_time)
 | 
			
		||||
                .first()
 | 
			
		||||
            )
 | 
			
		||||
            diff = Diffusion.objects.episode(id=sound.episode_id).on_air().now(air_time).first()
 | 
			
		||||
 | 
			
		||||
        # log sound on air
 | 
			
		||||
        return self.log(
 | 
			
		||||
@ -158,9 +151,7 @@ class Monitor:
 | 
			
		||||
        if log.diffusion:
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        tracks = Track.objects.filter(
 | 
			
		||||
            sound_id=log.sound_id, timestamp__isnull=False
 | 
			
		||||
        ).order_by("timestamp")
 | 
			
		||||
        tracks = Track.objects.filter(sound_id=log.sound_id, timestamp__isnull=False).order_by("timestamp")
 | 
			
		||||
        if not tracks.exists():
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
@ -217,11 +208,7 @@ class Monitor:
 | 
			
		||||
 | 
			
		||||
        dealer = self.streamer.dealer
 | 
			
		||||
        # start
 | 
			
		||||
        if (
 | 
			
		||||
            not dealer.queue
 | 
			
		||||
            and dealer.rid is None
 | 
			
		||||
            or dealer.remaining < self.delay.total_seconds()
 | 
			
		||||
        ):
 | 
			
		||||
        if not dealer.queue and dealer.rid is None or dealer.remaining < self.delay.total_seconds():
 | 
			
		||||
            self.start_diff(dealer, diff)
 | 
			
		||||
        # cancel
 | 
			
		||||
        elif diff.start < now - self.cancel_timeout:
 | 
			
		||||
 | 
			
		||||
@ -47,9 +47,7 @@ class Streamer:
 | 
			
		||||
 | 
			
		||||
        self.id = self.station.slug.replace("-", "_")
 | 
			
		||||
        self.path = os.path.join(station.path, "station.liq")
 | 
			
		||||
        self.connector = connector or Connector(
 | 
			
		||||
            os.path.join(station.path, "station.sock")
 | 
			
		||||
        )
 | 
			
		||||
        self.connector = connector or Connector(os.path.join(station.path, "station.sock"))
 | 
			
		||||
        self.init_sources()
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
@ -91,9 +89,7 @@ class Streamer:
 | 
			
		||||
    def init_sources(self):
 | 
			
		||||
        streams = self.station.program_set.filter(stream__isnull=False)
 | 
			
		||||
        self.dealer = QueueSource(self, "dealer")
 | 
			
		||||
        self.sources = [self.dealer] + [
 | 
			
		||||
            PlaylistSource(self, program=program) for program in streams
 | 
			
		||||
        ]
 | 
			
		||||
        self.sources = [self.dealer] + [PlaylistSource(self, program=program) for program in streams]
 | 
			
		||||
 | 
			
		||||
    def make_config(self):
 | 
			
		||||
        """Make configuration files and directory (and sync sources)"""
 | 
			
		||||
@ -128,12 +124,7 @@ class Streamer:
 | 
			
		||||
        self.source = next(
 | 
			
		||||
            iter(
 | 
			
		||||
                sorted(
 | 
			
		||||
                    (
 | 
			
		||||
                        source
 | 
			
		||||
                        for source in self.sources
 | 
			
		||||
                        if source.request_status == "playing"
 | 
			
		||||
                        and source.air_time
 | 
			
		||||
                    ),
 | 
			
		||||
                    (source for source in self.sources if source.request_status == "playing" and source.air_time),
 | 
			
		||||
                    key=lambda o: o.air_time,
 | 
			
		||||
                    reverse=True,
 | 
			
		||||
                )
 | 
			
		||||
@ -149,11 +140,7 @@ class Streamer:
 | 
			
		||||
        if not os.path.exists(self.socket_path):
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        conns = [
 | 
			
		||||
            conn
 | 
			
		||||
            for conn in psutil.net_connections(kind="unix")
 | 
			
		||||
            if conn.laddr == self.socket_path
 | 
			
		||||
        ]
 | 
			
		||||
        conns = [conn for conn in psutil.net_connections(kind="unix") if conn.laddr == self.socket_path]
 | 
			
		||||
        for conn in conns:
 | 
			
		||||
            if conn.pid is not None:
 | 
			
		||||
                os.kill(conn.pid, signal.SIGKILL)
 | 
			
		||||
 | 
			
		||||
@ -23,9 +23,7 @@ class Streamers:
 | 
			
		||||
    def reset(self, stations=Station.objects.active()):
 | 
			
		||||
        # FIXME: cf. TODO in aircox.controllers about model updates
 | 
			
		||||
        stations = stations.all()
 | 
			
		||||
        self.streamers = {
 | 
			
		||||
            station.pk: self.streamer_class(station) for station in stations
 | 
			
		||||
        }
 | 
			
		||||
        self.streamers = {station.pk: self.streamer_class(station) for station in stations}
 | 
			
		||||
 | 
			
		||||
    def fetch(self):
 | 
			
		||||
        """Call streamers fetch if timed-out."""
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user