Exemplo n.º 1
0
    def process_config_file(self, f, install_dir, **kwargs):

        # The path where the weewx.conf configuration file will be installed
        install_path = os.path.join(install_dir, os.path.basename(f))
    
        new_config = merge_config_files(f, install_path, install_dir)
        # Get a temporary file:
        tmpfile = tempfile.NamedTemporaryFile("w", 1)
        
        # Write the new configuration file to it:
        new_config.write(tmpfile)
        
        # Save the old config file if it exists:
        if os.path.exists(install_path):
            backup_path = save_path(install_path)
            print "Saved old configuration file as %s" % backup_path
            
        # Now install the temporary file (holding the merged config data)
        # into the proper place:
        rv = install_data.copy_file(self, tmpfile.name, install_path, **kwargs)
        
        # Set the permission bits unless this is a dry run:
        if not self.dry_run:
            shutil.copymode(f, install_path)

        return rv
Exemplo n.º 2
0
 def copy_file(self, f, install_dir, **kwargs):
     # If this is the configuration file, then merge it instead
     # of copying it
     if f == 'weewx.conf':
         rv = self.process_config_file(f, install_dir, **kwargs)
     elif f in start_scripts:
         rv = self.massage_start_file(f, install_dir, **kwargs)
     else:
         rv = install_data.copy_file(self, f, install_dir, **kwargs)
     return rv
Exemplo n.º 3
0
    def copy_file(self, f, install_dir, **kwargs):
        rv = None

        # If this is the configuration file, then merge it instead
        # of copying it
        if f == 'weewx.conf':
            rv = self.massageWeewxConfigFile(f, install_dir, **kwargs)
        elif f in ('start_scripts/Debian/weewx', 'start_scripts/SuSE/weewx'):
            rv = self.massageStartFile(f, install_dir, **kwargs)
        else:
            rv = install_data.copy_file(self, f, install_dir, **kwargs)
        return rv
Exemplo n.º 4
0
 def massage_start_file(self, f, install_dir, **kwargs):
 
         outname = os.path.join(install_dir, os.path.basename(f))
         sre = re.compile(r"WEEWX_ROOT\s*=")
 
         with open(f, 'r') as infile:
             with tempfile.NamedTemporaryFile("w") as tmpfile:
                 for line in infile:
                     if sre.match(line):
                         tmpfile.writelines("WEEWX_ROOT=%s\n" % self.install_dir)
                     else:
                         tmpfile.writelines(line)
                 tmpfile.flush()
                 rv = install_data.copy_file(self, tmpfile.name, outname, **kwargs)
 
         # Set the permission bits unless this is a dry run:
         if not self.dry_run:
             shutil.copymode(f, outname)
 
         return rv
Exemplo n.º 5
0
            config_util.modify_config(config_dict, stn_info, DEBUG)
    
        # Time to write it out. Get a temporary file:
        with tempfile.NamedTemporaryFile("w") as tmpfile:
            # Write the finished configuration file to it:
            config_dict.write(tmpfile)
            tmpfile.flush()
            
            # Save the old config file if it exists:
            if not self.dry_run and os.path.exists(install_path):
                backup_path = weeutil.weeutil.move_with_timestamp(install_path)
                print "Saved old configuration file as %s" % backup_path
                
            # Now install the temporary file (holding the merged config data)
            # into the proper place:
            rv = install_data.copy_file(self, tmpfile.name, install_path, **kwargs)
        
        # Set the permission bits unless this is a dry run:
        if not self.dry_run:
            shutil.copymode(f, install_path)

        return rv

    def massage_start_file(self, f, install_dir, **kwargs):
    
            outname = os.path.join(install_dir, os.path.basename(f))
            sre = re.compile(r"WEEWX_ROOT\s*=")
    
            with open(f, 'r') as infile:
                with tempfile.NamedTemporaryFile("w") as tmpfile:
                    for line in infile:
Exemplo n.º 6
0
 def copy_file (self, filename, dirname):
   (out, _) = install_data.copy_file(self, filename, dirname)
   # match for man pages
   if re.search(r'/man/man\d/.+\.\d$', out):
     return (out+".gz", _)
   return (out, _)
Exemplo n.º 7
0
    def process_config_file(self, f, install_dir, **kwargs):
        global stn_info

        # Open up and parse the distribution config file:
        try:
            dist_config_dict = configobj.ConfigObj(f, interpolation=False, file_error=True, encoding='utf-8')
        except IOError as e:
            sys.exit(str(e))
        except SyntaxError as e:
            sys.exit("Syntax error in distribution configuration file '%s': %s"
                     % (f, e))

        # The path where the weewx.conf configuration file will be installed
        install_path = os.path.join(install_dir, os.path.basename(f))

        # Do we have an old config file?
        if os.path.isfile(install_path):
            # Yes. Read it
            config_path, config_dict = weecfg.read_config(install_path, None, interpolation=False)
            if DEBUG:
                print("Old configuration file found at", config_path)

            # Update the old configuration file to the current version,
            # then merge it into the distribution file
            weecfg.update_and_merge(config_dict, dist_config_dict)
        else:
            # No old config file. Use the distribution file, then, if we can,
            # prompt the user for station specific info
            config_dict = dist_config_dict
            if not self.no_prompt:
                # Prompt the user for the station information:
                stn_info = weecfg.prompt_for_info()
                driver = weecfg.prompt_for_driver(stn_info.get('driver'))
                stn_info['driver'] = driver
                stn_info.update(weecfg.prompt_for_driver_settings(driver, config_dict))
                if DEBUG:
                    print("Station info =", stn_info)
            weecfg.modify_config(config_dict, stn_info, DEBUG)

        # Set the WEEWX_ROOT
        config_dict['WEEWX_ROOT'] = os.path.normpath(install_dir)

        # NB: use mkstemp instead of NamedTemporaryFile because we need to
        # do the delete (windows gets mad otherwise) and there is no delete
        # parameter in NamedTemporaryFile in python 2.5.

        # Time to write it out. Get a temporary file:
        tmpfd, tmpfn = tempfile.mkstemp()
        try:
            # We don't need the file descriptor
            os.close(tmpfd)
            # Set the filename we will write to
            config_dict.filename = tmpfn
            # Write the config file
            config_dict.write()

            # Save the old config file if it exists:
            if not self.dry_run and os.path.exists(install_path):
                backup_path = weeutil.weeutil.move_with_timestamp(install_path)
                print("Saved old configuration file as %s" % backup_path)
            if not self.dry_run:
                # Now install the temporary file (holding the merged config data)
                # into the proper place:
                rv = install_data.copy_file(self, tmpfn, install_path, **kwargs)
        finally:
            # Get rid of the temporary file
            os.unlink(tmpfn)

        # Set the permission bits unless this is a dry run:
        if not self.dry_run:
            shutil.copymode(f, install_path)

        return rv
Exemplo n.º 8
0
Arquivo: setup.py Projeto: xueweiz/sos
 def copy_file(self, filename, dirname):
     (out, _) = install_data.copy_file(self, filename, dirname)
     # match for man pages
     if re.search(r'/man/man\d/.+\.\d$', out):
         return (out + ".gz", _)
     return (out, _)
Exemplo n.º 9
0
        weecfg.reorder_to_ref(config_dict)
    
        # Time to write it out. Get a temporary file:
        with tempfile.NamedTemporaryFile("w") as tmpfile:
            # Write the finished configuration file to it:
            config_dict.write(tmpfile)
            tmpfile.flush()
            
            # Save the old config file if it exists:
            if not self.dry_run and os.path.exists(install_path):
                backup_path = weeutil.weeutil.move_with_timestamp(install_path)
                print "Saved old configuration file as %s" % backup_path
                
            # Now install the temporary file (holding the merged config data)
            # into the proper place:
            rv = install_data.copy_file(self, tmpfile.name, install_path, **kwargs)
        
        # Set the permission bits unless this is a dry run:
        if not self.dry_run:
            shutil.copymode(f, install_path)

        return rv

    def massage_start_file(self, f, install_dir, **kwargs):
    
            outname = os.path.join(install_dir, os.path.basename(f))
            sre = re.compile(r"WEEWX_ROOT\s*=")
    
            with open(f, 'r') as infile:
                with tempfile.NamedTemporaryFile("w") as tmpfile:
                    for line in infile:
Exemplo n.º 10
0
    def massageWeewxConfigFile(self, f, install_dir, **kwargs):
        """Merges any old config file into the new one, and sets WEEWX_ROOT
        
        If an old configuration file exists, it will merge the contents
        into the new file. It also sets variable ['Station']['WEEWX_ROOT']
        to reflect the installation directory"""
        
        # The path name of the weewx.conf configuration file:
        config_path = os.path.join(install_dir, os.path.basename(f))
        
        # Create a ConfigObj using the new contents:
        new_config = configobj.ConfigObj(f)
        new_config.indent_type = '    '
        new_version_number = VERSION.split('.')
        
        # Sometimes I forget to turn the debug flag off:
        new_config['debug'] = 0
        
        # And forget that while mine starts in October, 
        # most people's rain year starts in January!
        new_config['Station']['rain_year_start'] = 1

        # Check to see if there is an existing config file.
        # If so, merge its contents with the new one
        if os.path.exists(config_path):
            old_config = configobj.ConfigObj(config_path)
            old_version = old_config.get('version')
            # If the version number does not appear at all, then
            # assume a very old version:
            if not old_version: old_version = '1.0.0'
            old_version_number = old_version.split('.')

            # If the user has a version >= 1.7, then merge in the old
            # config file.
            if old_version_number[0:2] >= ['1','7']:
                # Any user changes in old_config will overwrite values in new_config
                # with this merge
                new_config.merge(old_config)
                        
        # Make sure WEEWX_ROOT reflects the choice made in setup.cfg:
        new_config['Station']['WEEWX_ROOT'] = self.install_dir
        # Add the version:
        new_config['version'] = VERSION

        # Options heating_base and cooling_base have moved.
        new_config['Station'].pop('heating_base', None)
        new_config['Station'].pop('cooling_base', None)

        # Wunderground has been put under section ['RESTful']:
        new_config.pop('Wunderground', None)

        # Option max_drift has been moved from section VantagePro
        new_config['VantagePro'].pop('max_drift', None)

        # Service StdCatchUp is no longer used. Filter it from the list:
        new_config['Engines']['WxEngine']['service_list'] =\
            filter(lambda svc_name : svc_name != 'weewx.wxengine.StdCatchUp', 
                new_config['Engines']['WxEngine']['service_list'])

        # Service StdWunderground has changed its name to StdRESTful:
        new_config['Engines']['WxEngine']['service_list'] =\
            [svc.replace('StdWunderground', 'StdRESTful') for svc in\
             new_config['Engines']['WxEngine']['service_list']]

        # Get a temporary file:
        tmpfile = tempfile.NamedTemporaryFile("w", 1)
        
        # Write the new configuration file to it:
        new_config.write(tmpfile)
        
        # Back up the old config file if it exists:
        if os.path.exists(config_path):
            backup_path = backup(config_path)
            print "Backed up old configuration file as %s" % backup_path
            
        # Now install the temporary file (holding the merged config data)
        # into the proper place:
        rv = install_data.copy_file(self, tmpfile.name, config_path, **kwargs)
        
        # Set the permission bits unless this is a dry run:
        if not self.dry_run:
            shutil.copymode(f, config_path)

        return rv
Exemplo n.º 11
0
 def copy_file(self, src, dst, *args, **kwargs):
     # XXX: rename target on the fly. ugly, but works
     if os.path.basename(src) == "pycairo.h" and sys.version_info[0] == 3:
         dst = os.path.join(dst, "py3cairo.h")
     return du_install_data.copy_file(self, src, dst, *args, **kwargs)