!111: tests: aircox.management
			#114
		
		
	@ -103,10 +103,8 @@ class MoveTask(Task):
 | 
				
			|||||||
    log_msg = "Sound file moved: {event.src_path} -> {event.dest_path}"
 | 
					    log_msg = "Sound file moved: {event.src_path} -> {event.dest_path}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __call__(self, event, **kw):
 | 
					    def __call__(self, event, **kw):
 | 
				
			||||||
        print("event", event.src_path, event.dest_path, Sound.objects.all())
 | 
					 | 
				
			||||||
        sound = Sound.objects.filter(file=event.src_path).first()
 | 
					        sound = Sound.objects.filter(file=event.src_path).first()
 | 
				
			||||||
        if sound:
 | 
					        if sound:
 | 
				
			||||||
            print("got sound", event.src_path)
 | 
					 | 
				
			||||||
            kw["sound"] = sound
 | 
					            kw["sound"] = sound
 | 
				
			||||||
            kw["path"] = event.src_path
 | 
					            kw["path"] = event.src_path
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
 | 
				
			|||||||
@ -73,19 +73,18 @@ class SoundStats:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def __init__(self, path, sample_length=None):
 | 
					    def __init__(self, path, sample_length=None):
 | 
				
			||||||
        self.path = path
 | 
					        self.path = path
 | 
				
			||||||
        self.sample_length = (
 | 
					        if sample_length is not None:
 | 
				
			||||||
            sample_length if sample_length is not None else self.sample_length
 | 
					            self.sample_length = sample_length
 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_file_stats(self):
 | 
					    def get_file_stats(self):
 | 
				
			||||||
        return self.stats and self.stats[0]
 | 
					        return self.stats and self.stats[0] or None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def analyse(self):
 | 
					    def analyse(self):
 | 
				
			||||||
        logger.debug("complete file analysis")
 | 
					        logger.debug("complete file analysis")
 | 
				
			||||||
        self.stats = [SoxStats(self.path)]
 | 
					        self.stats = [SoxStats(self.path)]
 | 
				
			||||||
        position = 0
 | 
					        position = 0
 | 
				
			||||||
        length = self.stats[0].get("length")
 | 
					        length = self.stats[0].get("length")
 | 
				
			||||||
 | 
					        print(self.stats, "-----")
 | 
				
			||||||
        if not self.sample_length:
 | 
					        if not self.sample_length:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -109,23 +108,23 @@ class SoundStats:
 | 
				
			|||||||
        self.resume()
 | 
					        self.resume()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def resume(self):
 | 
					    def resume(self):
 | 
				
			||||||
        def view(array):
 | 
					 | 
				
			||||||
            return [
 | 
					 | 
				
			||||||
                "file"
 | 
					 | 
				
			||||||
                if index == 0
 | 
					 | 
				
			||||||
                else "sample {} (at {} seconds)".format(
 | 
					 | 
				
			||||||
                    index, (index - 1) * self.sample_length
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
                for index in array
 | 
					 | 
				
			||||||
            ]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if self.good:
 | 
					        if self.good:
 | 
				
			||||||
            logger.debug(
 | 
					            logger.debug(
 | 
				
			||||||
                self.path + " -> good: \033[92m%s\033[0m",
 | 
					                self.path + " -> good: \033[92m%s\033[0m",
 | 
				
			||||||
                ", ".join(view(self.good)),
 | 
					                ", ".join(self._view(self.good)),
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        if self.bad:
 | 
					        if self.bad:
 | 
				
			||||||
            logger.debug(
 | 
					            logger.debug(
 | 
				
			||||||
                self.path + " -> bad: \033[91m%s\033[0m",
 | 
					                self.path + " -> bad: \033[91m%s\033[0m",
 | 
				
			||||||
                ", ".join(view(self.bad)),
 | 
					                ", ".join(self._view(self.bad)),
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def _view(self, array):
 | 
				
			||||||
 | 
					        return [
 | 
				
			||||||
 | 
					            "file"
 | 
				
			||||||
 | 
					            if index == 0
 | 
				
			||||||
 | 
					            else "sample {} (at {} seconds)".format(
 | 
				
			||||||
 | 
					                index, (index - 1) * self.sample_length
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            for index in array
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
				
			|||||||
@ -245,7 +245,6 @@ class Interface:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def __call__(self, *args, **kwargs):
 | 
					    def __call__(self, *args, **kwargs):
 | 
				
			||||||
        target = self._imeta.target
 | 
					        target = self._imeta.target
 | 
				
			||||||
        print("is it class?", self, target, inspect.isclass(target))
 | 
					 | 
				
			||||||
        if inspect.isclass(target):
 | 
					        if inspect.isclass(target):
 | 
				
			||||||
            target = target(*args, **kwargs)
 | 
					            target = target(*args, **kwargs)
 | 
				
			||||||
            return type(self)(
 | 
					            return type(self)(
 | 
				
			||||||
 | 
				
			|||||||
@ -55,7 +55,20 @@ def sox_stats(sox_interfaces):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@pytest.fixture
 | 
					@pytest.fixture
 | 
				
			||||||
def stats():
 | 
					def stats():
 | 
				
			||||||
    return sound_stats.SoundStats()
 | 
					    return sound_stats.SoundStats("/tmp/audio.wav", sample_length=10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@pytest.fixture
 | 
				
			||||||
 | 
					def stats_interfaces(stats):
 | 
				
			||||||
 | 
					    def iw(path, **kw):
 | 
				
			||||||
 | 
					        kw["path"] = path
 | 
				
			||||||
 | 
					        kw.setdefault("length", stats.sample_length * 2)
 | 
				
			||||||
 | 
					        return kw
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SxS = sound_stats.SoxStats
 | 
				
			||||||
 | 
					    sound_stats.SoxStats = iw
 | 
				
			||||||
 | 
					    yield iw
 | 
				
			||||||
 | 
					    sound_stats.SoxStats = SxS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestSoxStats:
 | 
					class TestSoxStats:
 | 
				
			||||||
@ -73,20 +86,38 @@ class TestSoxStats:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestSoundStats:
 | 
					class TestSoundStats:
 | 
				
			||||||
    def test___init__(self):
 | 
					    def test_get_file_stats(self, stats):
 | 
				
			||||||
        pass
 | 
					        file_stats = {"a": 134}
 | 
				
			||||||
 | 
					        stats.stats = [file_stats]
 | 
				
			||||||
 | 
					        assert stats.get_file_stats() is file_stats
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_get_file_stats(self):
 | 
					    def test_get_file_stats_none(self, stats):
 | 
				
			||||||
        pass
 | 
					        stats.stats = []
 | 
				
			||||||
 | 
					        assert stats.get_file_stats() is None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_analyze(self):
 | 
					    def test_analyse(self, stats, stats_interfaces):
 | 
				
			||||||
        pass
 | 
					        stats.analyse()
 | 
				
			||||||
 | 
					        assert stats.stats == [
 | 
				
			||||||
 | 
					            {"path": stats.path, "length": stats.sample_length * 2},
 | 
				
			||||||
 | 
					            {"path": stats.path, "at": 0, "length": stats.sample_length},
 | 
				
			||||||
 | 
					            {"path": stats.path, "at": 10, "length": stats.sample_length},
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_analyze_no_sample_length(self):
 | 
					    def test_analyse_no_sample_length(self, stats, stats_interfaces):
 | 
				
			||||||
        pass
 | 
					        stats.sample_length = 0
 | 
				
			||||||
 | 
					        stats.analyse()
 | 
				
			||||||
 | 
					        assert stats.stats == [{"length": 0, "path": stats.path}]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_check(self):
 | 
					    def test_check(self, stats):
 | 
				
			||||||
        pass
 | 
					        good = [{"val": i} for i in range(0, 11)]
 | 
				
			||||||
 | 
					        bad = [{"val": i} for i in range(-10, 0)] + [
 | 
				
			||||||
 | 
					            {"val": i} for i in range(11, 20)
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        stats.stats = good + bad
 | 
				
			||||||
 | 
					        calls = {}
 | 
				
			||||||
 | 
					        stats.resume = lambda *_: calls.setdefault("resume", True)
 | 
				
			||||||
 | 
					        stats.check("val", 0, 10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_resume(self):
 | 
					        assert calls == {"resume": True}
 | 
				
			||||||
        pass
 | 
					        assert all(i < len(good) for i in stats.good)
 | 
				
			||||||
 | 
					        assert all(i >= len(good) for i in stats.bad)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										19
									
								
								notes.md
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								notes.md
									
									
									
									
									
								
							@ -73,18 +73,9 @@ cms:
 | 
				
			|||||||
    - player support diffusions with multiple archive files
 | 
					    - player support diffusions with multiple archive files
 | 
				
			||||||
    - comments -> remove/edit by the author
 | 
					    - comments -> remove/edit by the author
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Timezone shit:
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Instance's TODO
 | 
					# For the next version:
 | 
				
			||||||
- menu_top .sections:
 | 
					## Refactorisation
 | 
				
			||||||
    - display inline block
 | 
					Move:
 | 
				
			||||||
    - search on the right
 | 
					- into `aircox_streamer`: `Log`, `Port`
 | 
				
			||||||
- lists > items style
 | 
					- into `aircox_cms`: `Page`, `NavItem`, `Category`, `StaticPage`, etc.
 | 
				
			||||||
- logo: url
 | 
					 | 
				
			||||||
- comments / more info (perhaps using the thing like the player)
 | 
					 | 
				
			||||||
- footer url to aircox's repo + admin
 | 
					 | 
				
			||||||
- styling cal (a.today colored)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- init of post related models
 | 
					 | 
				
			||||||
    -> date is not formatted
 | 
					 | 
				
			||||||
    -> missing image?
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user