def test_smartSyncDelAndShuffle(self): cfg.logger.info("Running test_smartSyncDelAndShuffle") shuffle(self.plPath) currentDir = getLocalSongs(self.plPath) #deletes a third (rounded down) of the songs in the playlist toDelete = [] for _ in range(int(len(currentDir) / 3)): randSong = random.choice(currentDir) while randSong in toDelete: #ensures we dont try to delete the same song twice randSong = random.choice(currentDir) toDelete.append(randSong) for song in toDelete: os.remove(f'{self.plPath}/{song}') smartSync(self.plPath) with shelve.open(f"{self.plPath}/{cfg.metaDataName}", 'c', writeback=True) as metaData: passed = metaDataMatches(metaData, self.plPath) self.assertTrue(passed)
def test_smartSyncNoEdit(self): cfg.logger.info("Running test_smartSyncNoEdit") smartSync(self.plPath) with shelve.open(f"{self.plPath}/{cfg.metaDataName}", 'c', writeback=True) as metaData: passed = metaDataMatches(metaData, self.plPath) self.assertTrue(passed)
def test_smartSyncShuffle(self): '''Simulates remote reordering by shuffling local''' cfg.logger.info("Running test_smartSyncShuffle") shuffle(self.plPath) smartSync(self.plPath) with shelve.open(f"{self.plPath}/{cfg.metaDataName}", 'c', writeback=True) as metaData: passed = metaDataMatches(metaData, self.plPath) self.assertTrue(passed)
def test_smartSyncMove(self): cfg.logger.info("Running test_smartSyncSwap") with shelve.open(f"{self.plPath}/{cfg.metaDataName}", 'c', writeback=True) as metaData: numIds = len(metaData['ids']) move(self.plPath, 0, int(numIds / 2)) smartSync(self.plPath) with shelve.open(f"{self.plPath}/{cfg.metaDataName}", 'c', writeback=True) as metaData: passed = metaDataMatches(metaData, self.plPath) self.assertTrue(passed)
def cli(): ''' Runs command line application, talking in args and running commands ''' args = parseArgs() setupLogger(args) cwd = getCwd(args) #peek command runs without PLAYLIST posistional argument if args.peek: url = args.peek[0] if len(args.peek) < 2: peek(url) sys.exit() fmt = args.peek[1] peek(url, fmt) sys.exit() # if no playlist was provided all further functions cannot run if args.PLAYLIST: plPath = f"{cwd}/{args.PLAYLIST}" else: if not args.local_dir: #only option which can run without playlist cfg.logger.error("Playlist Name Required") sys.exit() if args.new_playlist: newPlaylist(plPath, args.new_playlist) sys.exit() if not playlistExists(plPath): sys.exit() #viewing playlist if args.print: showPlaylist(plPath) if args.view_metadata: compareMetaData(plPath) #playlist managing try: #smart syncing if args.smart_sync: smartSync(plPath) #appending elif args.append_new: appendNew(plPath) #manual adding elif args.manual_add: if not args.manual_add[1].isdigit(): cfg.logger.error("Index must be positive Integer") else: manualAdd(plPath, args.manual_add[0], int(args.manual_add[1])) #moving/swaping songs elif args.move: move(plPath, args.move[0], args.move[1]) elif args.move_range: moveRange(plPath, args.move_range[0], args.move_range[1], args.move_range[2]) elif args.swap: swap(plPath, args.swap[0], args.swap[1]) # TODO uncomment out --push-order once google completes oauth verification process #elif args.push_order: # pushLocalOrder(plPath) #fixing metadata corruption in event of crash except Exception as e: cfg.logger.exception(e) correctStateCorruption(plPath) cfg.logger.info("State Recovered") except: #sys.exit calls correctStateCorruption(plPath) cfg.logger.info("State Recovered")