def main(nzb_files, options): if not nzb_files: parser.print_help() return settings = config.read_config(options.config_file) if not settings: print '%s has no settings!' % options.config_file return if options.debug: settings['debug'] = options.debug print settings if options.pattern: settings['skip_regex'] = options.pattern settings['invert'] = True elif options.par2: settings['skip_regex'] = ['\.par2'] settings['invert'] = True nzbs = [nzb for nzb in helper.get_nzb_file(nzb_files)] for nzb in nzbs: nzb_name = os.path.split(nzb)[1] new_dir = helper.get_download_path(settings.get('download_dir'), nzb_name) settings['download_path'] = new_dir if not os.path.exists(new_dir): if settings.get('debug'): print 'made new dir %s ' % new_dir os.mkdir(new_dir) if settings.get('debug'): print settings['download_path'] download.start(nzb, settings)
def test_get_nzb_file(self): cwd = os.getcwd() nzb_dir = 'files/nzb' settings_dir = 'files/settings' # Test a single file. self.assertEqual([helper.get_nzb_file(os.path.join(cwd, nzb_dir, 'broken.nzb'))], [os.path.join(cwd, nzb_dir, nzb) for nzb in ['broken.nzb']]) # Test a directory. self.assertEqual(helper.get_nzb_file(os.path.join(cwd, nzb_dir)), [os.path.join(cwd, nzb_dir, nzb) for nzb in ['broken.nzb', 'gpl.nzb', 'gutenberg.nzb']]) # Test a zip file. self.assertEqual(helper.get_nzb_file(os.path.join(cwd, nzb_dir, 'nzbs.zip')), [os.path.join(cwd, nzb_dir, nzb) for nzb in ['gpl.nzb', 'gutenberg.nzb']]) # OptionParser's args come in a list, so emulate that. self.assertEqual(helper.get_nzb_file([os.path.join(cwd, nzb_dir, 'nzbs.zip')]), [os.path.join(cwd, nzb_dir, nzb) for nzb in ['gpl.nzb', 'gutenberg.nzb']]) self.assertEqual(helper.get_nzb_file(os.path.join(cwd, settings_dir)), [])