~lottanzb/lottanzb/xdg-location

« back to all changes in this revision

Viewing changes to lottanzb/hellaconfig.py

  • Committer: Severin Heiniger
  • Date: 2009-03-20 00:15:16 UTC
  • mfrom: (630.1.7 main)
  • Revision ID: severinheiniger@gmail.com-20090320001516-d07d98ajhgq4412g
Synced with main.

Show diffs side-by-side

added added

removed removed

Lines of Context:
490
490
    def __init__(self, config_file, read_only=False):
491
491
        GObject.__init__(self)
492
492
        
493
 
        # GObject properties of type 'object' can't have default values.
494
 
        self.keep_file_types = ["nfo", "txt"]
495
 
        self.other_nzb_file_types = []
496
 
        self.not_required_file_types = [
497
 
            "log", "m3u", "nfo", "nzb", "sfv", "txt"
498
 
        ]
 
493
        self._initialize_object_properties()
499
494
        
500
495
        self.special_keys = ["servers", "music_types", "dirty"]
501
496
        
502
 
        self.servers = []
503
 
        self.music_types = []
504
 
        
505
497
        self.loading = False
506
498
        self.read_only = read_only
507
499
        self.config_file = config_file
546
538
        except:
547
539
            self.__dict__[key] = value
548
540
    
 
541
    def _initialize_object_properties(self):
 
542
        """
 
543
        Assigns meaningful initial values to properties of type 'object'.
 
544
        
 
545
        GObject properties of type 'object' can't have default values.
 
546
        """
 
547
        
 
548
        self.keep_file_types = ["nfo", "txt"]
 
549
        self.other_nzb_file_types = []
 
550
        self.not_required_file_types = [
 
551
            "log", "m3u", "nfo", "nzb", "sfv", "txt"
 
552
        ]
 
553
        
 
554
        self.servers = []
 
555
        self.music_types = []
 
556
    
549
557
    def get_property(self, key):
550
558
        """
551
559
        There are some HellaNZB configuration values which can be either
630
638
            log.debug(_("The HellaNZB preferences were successfully written "
631
639
                "into the file %s." % self.config_file))
632
640
    
 
641
    def reset(self):
 
642
        """
 
643
        Changes all options back to their default values and removes all
 
644
        servers and music types from the configuration.
 
645
        """
 
646
        
 
647
        for key in self.keys():
 
648
            self[key] = self.get_property_default_value(key)
 
649
        
 
650
        self._initialize_object_properties()
 
651
    
633
652
    # TODO: Better method name
634
653
    def getConfigStr(self):
635
654
        output = "# -*- coding: utf-8 -*-\n"
705
724
    @staticmethod
706
725
    def locate():
707
726
        """
708
 
        Locate a existing HellaNZB configuration file on the user's system.
 
727
        Locate existing HellaNZB configuration files on the user's system.
709
728
        """
710
729
        
711
 
        places = [
712
 
            getcwd(),
713
 
            join(getcwd(), "etc"),
714
 
            _PREFIX_DIR,
715
 
            "/etc",
716
 
            "/etc/hellanzb"
717
 
        ]
 
730
        places = [getcwd(), join(getcwd(), "etc"), "/etc"]
718
731
        
719
732
        for place in places:
720
 
            file = join(place, "hellanzb.conf")
 
733
            config_file = join(place, "hellanzb.conf")
721
734
            
722
 
            if isfile(file):
723
 
                return file
 
735
            if isfile(config_file):
 
736
                return config_file
724
737
    
725
738
    class LoadingError(Exception):
726
739
        def __init__(self, message, config_file):