| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # |
|---|
| 4 | # Copyright (C) 2005-2006 Insecure.Com LLC. |
|---|
| 5 | # Copyright (C) 2007-2008 Adriano Monteiro Marques |
|---|
| 6 | # |
|---|
| 7 | # Author: Adriano Monteiro Marques <adriano@umitproject.org> |
|---|
| 8 | # |
|---|
| 9 | # This program is free software; you can redistribute it and/or modify |
|---|
| 10 | # it under the terms of the GNU General Public License as published by |
|---|
| 11 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | # (at your option) any later version. |
|---|
| 13 | # |
|---|
| 14 | # This program is distributed in the hope that it will be useful, |
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | # GNU General Public License for more details. |
|---|
| 18 | # |
|---|
| 19 | # You should have received a copy of the GNU General Public License |
|---|
| 20 | # along with this program; if not, write to the Free Software |
|---|
| 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 22 | |
|---|
| 23 | from os.path import exists, dirname |
|---|
| 24 | from os import access, R_OK |
|---|
| 25 | from tempfile import mktemp |
|---|
| 26 | |
|---|
| 27 | from umitCore.Paths import Path |
|---|
| 28 | from umitCore.UmitLogging import log |
|---|
| 29 | |
|---|
| 30 | def get_config_file(filename, original_content): |
|---|
| 31 | config_file = mktemp() |
|---|
| 32 | |
|---|
| 33 | try: |
|---|
| 34 | c = Path.__getattr__(filename) |
|---|
| 35 | if exists(c) and access(c, R_OK): |
|---|
| 36 | config_file = c |
|---|
| 37 | else: |
|---|
| 38 | raise Exception() |
|---|
| 39 | except: |
|---|
| 40 | # Using temporary file |
|---|
| 41 | cfile = open(config_file, "w") |
|---|
| 42 | cfile.write(original_content) |
|---|
| 43 | cfile.close() |
|---|
| 44 | |
|---|
| 45 | log.debug(">>> Get config file %s: %s" % (filename, config_file)) |
|---|
| 46 | return config_file |
|---|