Bonjour tout le monde,

J'ai une question très facile à soumettre (du moins je pense).

Je dispose d'un script qui va chercher des variables\constantes dans un fichier et j'aimerais mettre celles-ci au début de mon script et ne plus utiliser le fichier. Voici le code pour aller les chercher. Voyez vous comment je peux le modifier SVP (j'ai 0 compétences en python)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
    if args.config_filename:
        for section in config.sections():
            if section == 'General':
                logFile = config.get(section, 'log_file')
                backupLocation = config.get(section, 'backup_location')
 
            elif config.get(section, 'type') == 'Content':
                status = config.get(section, 'status')
                if status.lower() != 'enabled':
                    logging.info('Skipping disabled section:{0}'.format(section))
                    continue
                content = SEMContent()
                content.name = config.get(section, 'name')
                content.pattern = re.compile(config.get(section, 'file_pattern'))
                content.dest = config.get(section, 'dest_dir')
                content.provider = SEMContentProvider(config.get(section, 'url'))
                content.processed = config.get(section, 'processed_file')
                content.owner_user = config.get(section, 'owner_user')
                content.owner_group = config.get(section, 'owner_group')
                unzip = config.get(section, 'unzip')
                if unzip.lower() == 'yes':
                    content.decompress = True
                else:
                    content.decompress = False
                if config.has_option(section, 'date_format'):
                    content.date_format = config.get(section, 'date_format')
                else:
                    content.date_format = None
 
                contentList.append(content)
            else:
                logging.error('Unknown section:{0} found in config file:{1}'.format(section, configFile))
Mon fichier de paratères est de ce type :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
    ##############################
    # Sample Configuration File: #
    ##############################;
 [General]
 log_file = /var/log/KTR.log
 backup_location = /opt/ktr/auk/aun_backup
  ##############################
[Content ktr_context]
name = ktr Context
type = Content
file_pattern = ^Context_Update_\w+_(\d{4}.\d{4}_\d{6}).zip$
dest_dir = /opt/jsj/manager/config/server/
url = http://X.X.X/..
....
    #################################
[Content cnt_content]
name = Connector Content
type = Content
En fait j'aimerais garder les objets 'section' et 'content' pour rien avoir à changer dans le script. Voyez vous comment faire ceci SVP ?

D'avance, merci et bon après midi.