def setUp(self): super().setUp() self.tmp_directory = self.mktmpdir() self.configpath = os.path.join(self.tmp_directory, 'test.ini') shutil.copy(os.path.join('test', 'data', 'test.ini'), self.configpath) self.addCleanup(os.remove, self.configpath) self.config = Config.from_file(None, self.configpath) self.addCleanup(self.cleanup_config_obj) self.config.application["version"] = "testing" logging.disable(logging.ERROR) Option.registry = {} ListOption('profiles', self.PROFILES_KEY, []) Option('profiles', self.SETTINGS_KEY, {}) # Get valid profile option settings for testing option_settings = list(UserProfileGroups.get_all_settings_list()) self.test_setting_0 = option_settings[0] self.test_setting_1 = option_settings[1] self.test_setting_2 = option_settings[2] self.test_setting_3 = option_settings[3] TextOption("setting", self.test_setting_0, "abc") BoolOption("setting", self.test_setting_1, True) IntOption("setting", self.test_setting_2, 42) TextOption("setting", self.test_setting_3, "xyz")
def setUp(self): super().setUp() self.tmp_directory = mkdtemp() self.configpath = os.path.join(self.tmp_directory, 'test.ini') self.config = Config.from_file(None, self.configpath) self.config.application["version"] = "testing" logging.disable(logging.ERROR) Option.registry = {}
def setUp(self): super().setUp() self.tmp_directory = self.mktmpdir() self.configpath = os.path.join(self.tmp_directory, 'test.ini') shutil.copy(os.path.join('test', 'data', 'test.ini'), self.configpath) self.addCleanup(os.remove, self.configpath) self.config = Config.from_file(None, self.configpath) self.addCleanup(self.cleanup_config_obj) self.config.application["version"] = "testing" logging.disable(logging.ERROR) Option.registry = {}
def __init__(self, args, localedir, autoupdate, debug=False): QtGui.QApplication.__init__(self, args) self.__class__.__instance = self self._args = args self._autoupdate = autoupdate self.config = Config() if sys.platform == "win32": userdir = os.environ.get("APPDATA", "~\\Application Data") else: userdir = os.environ.get("XDG_CONFIG_HOME", "~/.config") self.userdir = os.path.join(os.path.expanduser(userdir), "MusicBrainz", "Picard") # Initialize threading and allocate threads self.thread_pool = thread.ThreadPool(self) self.load_queue = queue.Queue() self.save_queue = queue.Queue() self.analyze_queue = queue.Queue() self.other_queue = queue.Queue() threads = self.thread_pool.threads threads.append(thread.Thread(self.thread_pool, self.load_queue)) threads.append(thread.Thread(self.thread_pool, self.load_queue)) threads.append(thread.Thread(self.thread_pool, self.save_queue)) threads.append(thread.Thread(self.thread_pool, self.other_queue)) threads.append(thread.Thread(self.thread_pool, self.other_queue)) threads.append(thread.Thread(self.thread_pool, self.analyze_queue)) self.thread_pool.start() self.stopping = False # Setup logging if debug or "PICARD_DEBUG" in os.environ: self.log = log.DebugLog() else: self.log = log.Log() self.log.debug("Starting Picard %s from %r", picard.__version__, os.path.abspath(__file__)) # TODO remove this before the final release if sys.platform == "win32": olduserdir = "~\\Local Settings\\Application Data\\MusicBrainz Picard" else: olduserdir = "~/.picard" olduserdir = os.path.expanduser(olduserdir) if os.path.isdir(olduserdir): self.log.info("Moving %s to %s", olduserdir, self.userdir) try: shutil.move(olduserdir, self.userdir) except: pass QtCore.QObject.tagger = self QtCore.QObject.config = self.config QtCore.QObject.log = self.log check_io_encoding() self.setup_gettext(localedir) self.xmlws = XmlWebService() # Initialize fingerprinting self._ofa = musicdns.OFA() self._ofa.init() self._acoustid = acoustid.AcoustIDClient() self._acoustid.init() # Load plugins self.pluginmanager = PluginManager() self.user_plugin_dir = os.path.join(self.userdir, "plugins") if not os.path.exists(self.user_plugin_dir): os.makedirs(self.user_plugin_dir) self.pluginmanager.load_plugindir(self.user_plugin_dir) if hasattr(sys, "frozen"): self.pluginmanager.load_plugindir( os.path.join(os.path.dirname(sys.argv[0]), "plugins")) else: self.pluginmanager.load_plugindir( os.path.join(os.path.dirname(__file__), "plugins")) self.puidmanager = PUIDManager() self.acoustidmanager = AcoustIDManager() self.browser_integration = BrowserIntegration() self.files = {} self.clusters = ClusterList() self.albums = {} self.mbid_redirects = {} self.unmatched_files = UnmatchedFiles() self.nats = None self.window = MainWindow() def remove_va_file_naming_format(merge=True): if merge: self.config.setting["file_naming_format"] = \ "$if($eq(%compilation%,1),\n$noop(Various Artist albums)\n"+\ "%s,\n$noop(Single Artist Albums)\n%s)" %\ (self.config.setting["va_file_naming_format"].toString(), self.config.setting["file_naming_format"]) self.config.setting.remove("va_file_naming_format") self.config.setting.remove("use_va_format") if "va_file_naming_format" in self.config.setting\ and "use_va_format" in self.config.setting: if self.config.setting["use_va_format"].toBool(): remove_va_file_naming_format() self.window.show_va_removal_notice() elif self.config.setting["va_file_naming_format"].toString() !=\ r"$if2(%albumartist%,%artist%)/%album%/$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2) %artist% - %title%": if self.window.confirm_va_removal(): remove_va_file_naming_format(merge=False) else: remove_va_file_naming_format() else: # default format, disabled remove_va_file_naming_format(merge=False)
def __init__(self, args, localedir, autoupdate, debug=False): QtGui.QApplication.__init__(self, args) self.__class__.__instance = self self._args = args self._autoupdate = autoupdate self.config = Config() if sys.platform == "win32": userdir = os.environ.get("APPDATA", "~\\Application Data") else: userdir = os.environ.get("XDG_CONFIG_HOME", "~/.config") self.userdir = os.path.join(os.path.expanduser(userdir), "MusicBrainz", "Picard") # Initialize threading and allocate threads self.thread_pool = thread.ThreadPool(self) self.load_queue = queue.Queue() self.save_queue = queue.Queue() self.analyze_queue = queue.Queue() self.other_queue = queue.Queue() threads = self.thread_pool.threads threads.append(thread.Thread(self.thread_pool, self.load_queue)) threads.append(thread.Thread(self.thread_pool, self.load_queue)) threads.append(thread.Thread(self.thread_pool, self.save_queue)) threads.append(thread.Thread(self.thread_pool, self.other_queue)) threads.append(thread.Thread(self.thread_pool, self.other_queue)) threads.append(thread.Thread(self.thread_pool, self.analyze_queue)) self.thread_pool.start() self.stopping = False # Setup logging if debug or "PICARD_DEBUG" in os.environ: self.log = log.DebugLog() else: self.log = log.Log() self.log.debug("Starting Picard %s from %r", picard.__version__, os.path.abspath(__file__)) # TODO remove this before the final release if sys.platform == "win32": olduserdir = "~\\Local Settings\\Application Data\\MusicBrainz Picard" else: olduserdir = "~/.picard" olduserdir = os.path.expanduser(olduserdir) if os.path.isdir(olduserdir): self.log.info("Moving %s to %s", olduserdir, self.userdir) try: shutil.move(olduserdir, self.userdir) except: pass QtCore.QObject.tagger = self QtCore.QObject.config = self.config QtCore.QObject.log = self.log self.setup_gettext(localedir) self.xmlws = XmlWebService() # Initialize fingerprinting self._ofa = musicdns.OFA() self._ofa.init() self._acoustid = acoustid.AcoustIDClient() self._acoustid.init() # Load plugins self.pluginmanager = PluginManager() self.user_plugin_dir = os.path.join(self.userdir, "plugins") if not os.path.exists(self.user_plugin_dir): os.makedirs(self.user_plugin_dir) self.pluginmanager.load_plugindir(self.user_plugin_dir) if hasattr(sys, "frozen"): self.pluginmanager.load_plugindir(os.path.join(os.path.dirname(sys.argv[0]), "plugins")) else: self.pluginmanager.load_plugindir(os.path.join(os.path.dirname(__file__), "plugins")) self.puidmanager = PUIDManager() self.acoustidmanager = AcoustIDManager() self.browser_integration = BrowserIntegration() self.files = {} self.clusters = ClusterList() self.albums = {} self.mbid_redirects = {} self.unmatched_files = UnmatchedFiles() self.window = MainWindow() self.nats = None