Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44842 > unrolled thread
| Started by | MMZ <programmer.toronto@gmail.com> |
|---|---|
| First post | 2013-05-06 12:01 -0700 |
| Last post | 2013-05-07 08:18 +0200 |
| Articles | 18 — 9 participants |
Back to article view | Back to comp.lang.python
python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 12:01 -0700
Re: python backup script Jerry Hill <malaclypse2@gmail.com> - 2013-05-06 15:11 -0400
Re: python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 12:20 -0700
Re: python backup script Matt Jones <matt.walker.jones@gmail.com> - 2013-05-06 14:46 -0500
Re: python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 13:37 -0700
Re: python backup script Matt Jones <matt.walker.jones@gmail.com> - 2013-05-06 16:08 -0500
Re: python backup script Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> - 2013-05-06 23:44 +0200
Re: python backup script Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> - 2013-05-06 23:48 +0200
Re: python backup script mina@socialassets.org - 2013-05-06 15:12 -0700
Re: python backup script John Gordon <gordon@panix.com> - 2013-05-06 22:15 +0000
Re: python backup script Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> - 2013-05-07 21:11 +0200
Re: python backup script MRAB <python@mrabarnett.plus.com> - 2013-05-06 23:28 +0100
Re: python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 15:15 -0700
Re: python backup script Chris Angelico <rosuav@gmail.com> - 2013-05-07 08:12 +1000
Re: python backup script MMZ <programmer.toronto@gmail.com> - 2013-05-06 15:40 -0700
Re: python backup script Chris Angelico <rosuav@gmail.com> - 2013-05-07 08:51 +1000
Re: python backup script MRAB <python@mrabarnett.plus.com> - 2013-05-06 23:52 +0100
Re: python backup script Peter Otten <__peter__@web.de> - 2013-05-07 08:18 +0200
| From | MMZ <programmer.toronto@gmail.com> |
|---|---|
| Date | 2013-05-06 12:01 -0700 |
| Subject | python backup script |
| Message-ID | <b586db98-78b2-40a6-9e1c-3d8b939657c8@googlegroups.com> |
I am trying to backup database on CentOS linux server,I'm getting error when running the following script. anyone can help?
#!/usr/bin/env python
import ConfigParser
import os
import time
config = ConfigParser.ConfigParser()
config.read("~/my.cnf")
username = config.get('client', 'mmz')
password = config.get('client', 'pass1')
hostname = config.get('client', 'localhost')
filestamp = time.strftime('%Y-%m-%d')
# Get a list of databases with :
Database_list_command="mysql -u %s -p%s -h %s --silent -N -e 'show databases'" % (username, password, hostname)
for database in os.popen(database_list_command).readlines():
database = database.strip()
if database == 'information_schema':
continue
if database == 'db_dev':
continue
filename = "/backups/mysql/%s-%s.sql" % (database, filestamp)
os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % (username, password, hostname, database, filename))
............Error..........
Traceback (most recent call last):
File "./backup.py", line 8, in ?
username = config.get('client', 'mmz')
File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
raise NoSectionError(section)
[toc] | [next] | [standalone]
| From | Jerry Hill <malaclypse2@gmail.com> |
|---|---|
| Date | 2013-05-06 15:11 -0400 |
| Message-ID | <mailman.1371.1367867496.3114.python-list@python.org> |
| In reply to | #44842 |
[Multipart message — attachments visible in raw view] — view raw
On Mon, May 6, 2013 at 3:01 PM, MMZ <programmer.toronto@gmail.com> wrote:
> I am trying to backup database on CentOS linux server,I'm getting error
> when running the following script. anyone can help?
>
> Traceback (most recent call last):
> File "./backup.py", line 8, in ?
> username = config.get('client', 'mmz')
> File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
> raise NoSectionError(section)
>
I've never used ConfigParser, but that
error message looks pretty simple to interpret. You've set up a
ConfigParser object, told it to read in ~/my.cnf, the asked for the value
of section 'client', option 'mmz'. The error indicates that your config
files doesn't have a section named 'client'.
What is the content of your ~/my.cnf file?
--
Jerry
[toc] | [prev] | [next] | [standalone]
| From | MMZ <programmer.toronto@gmail.com> |
|---|---|
| Date | 2013-05-06 12:20 -0700 |
| Message-ID | <51f5c8c4-b40b-4a1e-b72b-905caa62aaf6@googlegroups.com> |
| In reply to | #44843 |
On Monday, May 6, 2013 3:11:33 PM UTC-4, Jerry Hill wrote:
> On Mon, May 6, 2013 at 3:01 PM, MMZ <programme...@gmail.com> wrote:
>
>
>
> I am trying to backup database on CentOS linux server,I'm getting error when running the following script. anyone can help?
>
>
>
>
> Traceback (most recent call last):
>
> File "./backup.py", line 8, in ?
>
> username = config.get('client', 'mmz')
>
> File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
>
> raise NoSectionError(section)
>
>
>
> I've never used ConfigParser, but that
>
> error message looks pretty simple to interpret. You've set up a ConfigParser object, told it to read in ~/my.cnf, the asked for the value of section 'client', option 'mmz'. The error indicates that your config files doesn't have a section named 'client'.
>
>
>
> What is the content of your ~/my.cnf file?
>
> --
>
>
> Jerry
Thank you for helping Jerry. Actually I found this script for debian but I want to use it for CentOS server so I replaced /etc/mysql/debian.cnf with ~/my.cnf
the file content is:
Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
[toc] | [prev] | [next] | [standalone]
| From | Matt Jones <matt.walker.jones@gmail.com> |
|---|---|
| Date | 2013-05-06 14:46 -0500 |
| Message-ID | <mailman.1373.1367870074.3114.python-list@python.org> |
| In reply to | #44844 |
[Multipart message — attachments visible in raw view] — view raw
I've never used ConfigParser either, but shouldn't the "[client]" section
have the options "mmz", "pass1", or "localhost" somewhere? Do you need to
add them to that file?
*Matt Jones*
On Mon, May 6, 2013 at 2:20 PM, MMZ <programmer.toronto@gmail.com> wrote:
> On Monday, May 6, 2013 3:11:33 PM UTC-4, Jerry Hill wrote:
> > On Mon, May 6, 2013 at 3:01 PM, MMZ <programme...@gmail.com> wrote:
> >
> >
> >
> > I am trying to backup database on CentOS linux server,I'm getting error
> when running the following script. anyone can help?
> >
> >
> >
> >
> > Traceback (most recent call last):
> >
> > File "./backup.py", line 8, in ?
> >
> > username = config.get('client', 'mmz')
> >
> > File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
> >
> > raise NoSectionError(section)
> >
> >
> >
> > I've never used ConfigParser, but that
> >
> > error message looks pretty simple to interpret. You've set up a
> ConfigParser object, told it to read in ~/my.cnf, the asked for the value
> of section 'client', option 'mmz'. The error indicates that your config
> files doesn't have a section named 'client'.
> >
> >
> >
> > What is the content of your ~/my.cnf file?
> >
> > --
> >
> >
> > Jerry
>
> Thank you for helping Jerry. Actually I found this script for debian but I
> want to use it for CentOS server so I replaced /etc/mysql/debian.cnf with
> ~/my.cnf
> the file content is:
>
> Example MySQL config file for medium systems.
> #
> # This is for a system with little memory (32M - 64M) where MySQL plays
> # an important part, or systems up to 128M where MySQL is used together
> with
> # other programs (such as a web server)
> #
> # MySQL programs look for option files in a set of
> # locations which depend on the deployment platform.
> # You can copy this option file to one of those
> # locations. For information about these locations, see:
> # http://dev.mysql.com/doc/mysql/en/option-files.html
> #
> # In this file, you can use all long options that a program supports.
> # If you want to know which options a program supports, run the program
> # with the "--help" option.
>
> # The following options will be passed to all MySQL clients
> [client]
> #password = your_password
> port = 3306
> socket = /tmp/mysql.sock
>
> # Here follows entries for some specific programs
>
> # The MySQL server
> [mysqld]
> port = 3306
> socket = /tmp/mysql.sock
> skip-locking
> key_buffer_size = 16M
> max_allowed_packet = 1M
> table_open_cache = 64
> sort_buffer_size = 512K
> net_buffer_length = 8K
> read_buffer_size = 256K
> read_rnd_buffer_size = 512K
> myisam_sort_buffer_size = 8M
>
> # Don't listen on a TCP/IP port at all. This can be a security enhancement,
> # if all processes that need to connect to mysqld run on the same host.
> # All interaction with mysqld must be made via Unix sockets or named pipes.
> # Note that using this option without enabling named pipes on Windows
> # (via the "enable-named-pipe" option) will render mysqld useless!
> #
> #skip-networking
>
> # Replication Master Server (default)
> # binary logging is required for replication
> log-bin=mysql-bin
>
> # binary logging format - mixed recommended
> binlog_format=mixed
>
> # required unique id between 1 and 2^32 - 1
> # defaults to 1 if master-host is not set
> # but will not function as a master if omitted
> server-id = 1
> --
> http://mail.python.org/mailman/listinfo/python-list
>
[toc] | [prev] | [next] | [standalone]
| From | MMZ <programmer.toronto@gmail.com> |
|---|---|
| Date | 2013-05-06 13:37 -0700 |
| Message-ID | <489bad9e-4a96-4d51-98ea-ce59c2573e4f@googlegroups.com> |
| In reply to | #44846 |
Thanks Matt.
my.cnf is a readonly file and cannot be changed or modified but do you know of a file that stores similar information on CentOS?I think I'm not reading from a right file maybe.
On Monday, May 6, 2013 3:46:04 PM UTC-4, Matt Jones wrote:
> I've never used ConfigParser either, but shouldn't the "[client]" section have the options "mmz", "pass1", or "localhost" somewhere? Do you need to add them to that file?
>
>
>
>
> Matt Jones
>
>
>
> On Mon, May 6, 2013 at 2:20 PM, MMZ <programme...@gmail.com> wrote:
>
>
> On Monday, May 6, 2013 3:11:33 PM UTC-4, Jerry Hill wrote:
>
>
> > On Mon, May 6, 2013 at 3:01 PM, MMZ <programme...@gmail.com> wrote:
>
> >
>
> >
>
> >
>
> > I am trying to backup database on CentOS linux server,I'm getting error when running the following script. anyone can help?
>
> >
>
> >
>
> >
>
> >
>
>
> > Traceback (most recent call last):
>
> >
>
> > File "./backup.py", line 8, in ?
>
> >
>
> > username = config.get('client', 'mmz')
>
> >
>
> > File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
>
> >
>
> > raise NoSectionError(section)
>
> >
>
> >
>
> >
>
>
> > I've never used ConfigParser, but that
>
> >
>
> > error message looks pretty simple to interpret. You've set up a ConfigParser object, told it to read in ~/my.cnf, the asked for the value of section 'client', option 'mmz'. The error indicates that your config files doesn't have a section named 'client'.
>
>
>
> >
>
> >
>
> >
>
> > What is the content of your ~/my.cnf file?
>
> >
>
> > --
>
> >
>
> >
>
> > Jerry
>
>
>
> Thank you for helping Jerry. Actually I found this script for debian but I want to use it for CentOS server so I replaced /etc/mysql/debian.cnf with ~/my.cnf
>
> the file content is:
>
>
>
> Example MySQL config file for medium systems.
>
> #
>
> # This is for a system with little memory (32M - 64M) where MySQL plays
>
> # an important part, or systems up to 128M where MySQL is used together with
>
> # other programs (such as a web server)
>
> #
>
> # MySQL programs look for option files in a set of
>
> # locations which depend on the deployment platform.
>
> # You can copy this option file to one of those
>
> # locations. For information about these locations, see:
>
> # http://dev.mysql.com/doc/mysql/en/option-files.html
>
> #
>
> # In this file, you can use all long options that a program supports.
>
> # If you want to know which options a program supports, run the program
>
> # with the "--help" option.
>
>
>
> # The following options will be passed to all MySQL clients
>
> [client]
>
> #password = your_password
>
> port = 3306
>
> socket = /tmp/mysql.sock
>
>
>
> # Here follows entries for some specific programs
>
>
>
> # The MySQL server
>
> [mysqld]
>
> port = 3306
>
> socket = /tmp/mysql.sock
>
> skip-locking
>
> key_buffer_size = 16M
>
> max_allowed_packet = 1M
>
> table_open_cache = 64
>
> sort_buffer_size = 512K
>
> net_buffer_length = 8K
>
> read_buffer_size = 256K
>
> read_rnd_buffer_size = 512K
>
> myisam_sort_buffer_size = 8M
>
>
>
> # Don't listen on a TCP/IP port at all. This can be a security enhancement,
>
> # if all processes that need to connect to mysqld run on the same host.
>
> # All interaction with mysqld must be made via Unix sockets or named pipes.
>
> # Note that using this option without enabling named pipes on Windows
>
> # (via the "enable-named-pipe" option) will render mysqld useless!
>
> #
>
> #skip-networking
>
>
>
> # Replication Master Server (default)
>
> # binary logging is required for replication
>
> log-bin=mysql-bin
>
>
>
> # binary logging format - mixed recommended
>
> binlog_format=mixed
>
>
>
> # required unique id between 1 and 2^32 - 1
>
> # defaults to 1 if master-host is not set
>
> # but will not function as a master if omitted
>
> server-id = 1
>
> --
>
> http://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | Matt Jones <matt.walker.jones@gmail.com> |
|---|---|
| Date | 2013-05-06 16:08 -0500 |
| Message-ID | <mailman.1386.1367874530.3114.python-list@python.org> |
| In reply to | #44850 |
[Multipart message — attachments visible in raw view] — view raw
Why do you have to use that file? Why can't you copy its contents into a
new file in your working directory and make whatever changes necessary?
Example of the changes your code makes me think you want:
************************
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
mmz = bleh
pass1 = blah
localhost = bluargh
*Matt Jones*
On Mon, May 6, 2013 at 3:37 PM, MMZ <programmer.toronto@gmail.com> wrote:
> Thanks Matt.
> my.cnf is a readonly file and cannot be changed or modified but do you
> know of a file that stores similar information on CentOS?I think I'm not
> reading from a right file maybe.
>
> On Monday, May 6, 2013 3:46:04 PM UTC-4, Matt Jones wrote:
> > I've never used ConfigParser either, but shouldn't the "[client]"
> section have the options "mmz", "pass1", or "localhost" somewhere? Do you
> need to add them to that file?
> >
> >
> >
> >
> > Matt Jones
> >
> >
> >
> > On Mon, May 6, 2013 at 2:20 PM, MMZ <programme...@gmail.com> wrote:
> >
> >
> > On Monday, May 6, 2013 3:11:33 PM UTC-4, Jerry Hill wrote:
> >
> >
> > > On Mon, May 6, 2013 at 3:01 PM, MMZ <programme...@gmail.com> wrote:
> >
> > >
> >
> > >
> >
> > >
> >
> > > I am trying to backup database on CentOS linux server,I'm getting
> error when running the following script. anyone can help?
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> >
> > > Traceback (most recent call last):
> >
> > >
> >
> > > File "./backup.py", line 8, in ?
> >
> > >
> >
> > > username = config.get('client', 'mmz')
> >
> > >
> >
> > > File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
> >
> > >
> >
> > > raise NoSectionError(section)
> >
> > >
> >
> > >
> >
> > >
> >
> >
> > > I've never used ConfigParser, but that
> >
> > >
> >
> > > error message looks pretty simple to interpret. You've set up a
> ConfigParser object, told it to read in ~/my.cnf, the asked for the value
> of section 'client', option 'mmz'. The error indicates that your config
> files doesn't have a section named 'client'.
> >
> >
> >
> > >
> >
> > >
> >
> > >
> >
> > > What is the content of your ~/my.cnf file?
> >
> > >
> >
> > > --
> >
> > >
> >
> > >
> >
> > > Jerry
> >
> >
> >
> > Thank you for helping Jerry. Actually I found this script for debian but
> I want to use it for CentOS server so I replaced /etc/mysql/debian.cnf with
> ~/my.cnf
> >
> > the file content is:
> >
> >
> >
> > Example MySQL config file for medium systems.
> >
> > #
> >
> > # This is for a system with little memory (32M - 64M) where MySQL plays
> >
> > # an important part, or systems up to 128M where MySQL is used together
> with
> >
> > # other programs (such as a web server)
> >
> > #
> >
> > # MySQL programs look for option files in a set of
> >
> > # locations which depend on the deployment platform.
> >
> > # You can copy this option file to one of those
> >
> > # locations. For information about these locations, see:
> >
> > # http://dev.mysql.com/doc/mysql/en/option-files.html
> >
> > #
> >
> > # In this file, you can use all long options that a program supports.
> >
> > # If you want to know which options a program supports, run the program
> >
> > # with the "--help" option.
> >
> >
> >
> > # The following options will be passed to all MySQL clients
> >
> > [client]
> >
> > #password = your_password
> >
> > port = 3306
> >
> > socket = /tmp/mysql.sock
> >
> >
> >
> > # Here follows entries for some specific programs
> >
> >
> >
> > # The MySQL server
> >
> > [mysqld]
> >
> > port = 3306
> >
> > socket = /tmp/mysql.sock
> >
> > skip-locking
> >
> > key_buffer_size = 16M
> >
> > max_allowed_packet = 1M
> >
> > table_open_cache = 64
> >
> > sort_buffer_size = 512K
> >
> > net_buffer_length = 8K
> >
> > read_buffer_size = 256K
> >
> > read_rnd_buffer_size = 512K
> >
> > myisam_sort_buffer_size = 8M
> >
> >
> >
> > # Don't listen on a TCP/IP port at all. This can be a security
> enhancement,
> >
> > # if all processes that need to connect to mysqld run on the same host.
> >
> > # All interaction with mysqld must be made via Unix sockets or named
> pipes.
> >
> > # Note that using this option without enabling named pipes on Windows
> >
> > # (via the "enable-named-pipe" option) will render mysqld useless!
> >
> > #
> >
> > #skip-networking
> >
> >
> >
> > # Replication Master Server (default)
> >
> > # binary logging is required for replication
> >
> > log-bin=mysql-bin
> >
> >
> >
> > # binary logging format - mixed recommended
> >
> > binlog_format=mixed
> >
> >
> >
> > # required unique id between 1 and 2^32 - 1
> >
> > # defaults to 1 if master-host is not set
> >
> > # but will not function as a master if omitted
> >
> > server-id = 1
> >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
[toc] | [prev] | [next] | [standalone]
| From | Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> |
|---|---|
| Date | 2013-05-06 23:44 +0200 |
| Message-ID | <km987m$99c$1@tdi.cu.mi.it> |
| In reply to | #44842 |
MMZ wrote:
> config.read("~/my.cnf")
> username = config.get('client', 'mmz')
> password = config.get('client', 'pass1')
> hostname = config.get('client', 'localhost')
### A simple config file ###
[client]
user = mmz
password = pass1
host = localhost
### EOF ###
#!/usr/bin/env python
import ConfigParser
config = ConfigParser.ConfigParser()
config.read("~/configfile.cfg")
username = config.get('client', 'user')
password = config.get('client', 'password')
hostname = config.get('client', 'host')
[...]
> # Get a list of databases with :
> Database_list_command="mysql -u %s -p%s -h %s --silent -N -e 'show
databases'" % (username, password, hostname)
> for database in os.popen(database_list_command).readlines():
> database = database.strip()
> if database == 'information_schema':
> continue
> if database == 'db_dev':
> continue
> filename = "/backups/mysql/%s-%s.sql" % (database, filestamp)
> os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz"
% (username, password, hostname, database, filename))
command = subprocess.Popen(['mysql', '-u ' + username,
'-p' + password, '-h ' + hostname,
'--silent', '-N', "-e 'show databases'"],
shell=False,
stdout=subprocess.PIPE)
status = command.wait()
for line in command.stdout.readlines():
if line.strip() not in ['information_schema', 'db_dev']:
filename = "/backups/mysql/%s-%s.sql" % (database, filestamp)
cmd1 = subprocess.Popen(['mysqldump', '-u ' + username,
'-p' + password, '-h ' + hostname,
'-e', '--opt', '-c ' + database],
shell=False,
stdout=subprocess.PIPE)
cmd2 = subprocess.Popen(['gzip' '-c'],
shell=False,
stdout=filename)
Enrico
[toc] | [prev] | [next] | [standalone]
| From | Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> |
|---|---|
| Date | 2013-05-06 23:48 +0200 |
| Message-ID | <km98ft$99c$2@tdi.cu.mi.it> |
| In reply to | #44853 |
Enrico 'Henryx' Bianchi wrote:
> cmd2 = subprocess.Popen(['gzip' '-c'],
> shell=False,
> stdout=filename)
Doh, my fault:
cmd2 = subprocess.Popen(['gzip' '-c'],
shell=False,
stdout=filename
stdin=cmd1.stdout)
Enrico
[toc] | [prev] | [next] | [standalone]
| From | mina@socialassets.org |
|---|---|
| Date | 2013-05-06 15:12 -0700 |
| Message-ID | <36d2b7cf-2537-46a6-b984-9fce7ddd33ff@googlegroups.com> |
| In reply to | #44854 |
On Monday, May 6, 2013 5:48:44 PM UTC-4, Enrico 'Henryx' Bianchi wrote:
> Enrico 'Henryx' Bianchi wrote:
>
>
>
> > cmd2 = subprocess.Popen(['gzip' '-c'],
>
> > shell=False,
>
> > stdout=filename)
>
>
>
> Doh, my fault:
>
>
>
> cmd2 = subprocess.Popen(['gzip' '-c'],
>
> shell=False,
>
> stdout=filename
>
> stdin=cmd1.stdout)
>
>
>
> Enrico
Thank you Enrico. I've just tried your script and got this error:
stdin=cmd1.stdout)
^
SyntaxError: invalid syntax
any idea?
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2013-05-06 22:15 +0000 |
| Message-ID | <km9a2g$jc$1@reader1.panix.com> |
| In reply to | #44857 |
In <36d2b7cf-2537-46a6-b984-9fce7ddd33ff@googlegroups.com> mina@socialassets.org writes:
> > cmd2 = subprocess.Popen(['gzip' '-c'],
> >
> > shell=False,
> >
> > stdout=filename
> >
> > stdin=cmd1.stdout)
> Thank you Enrico. I've just tried your script and got this error:
> stdin=cmd1.stdout)
> ^
> SyntaxError: invalid syntax
Looks like you need a comma after 'stdout=filename'.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | Enrico 'Henryx' Bianchi <henryx_b@yahoo.it> |
|---|---|
| Date | 2013-05-07 21:11 +0200 |
| Message-ID | <kmbjks$r4k$1@tdi.cu.mi.it> |
| In reply to | #44859 |
John Gordon wrote: > Looks like you need a comma after 'stdout=filename'. Sigh, yesterday was a terrible day (yes, it lacks a comma)... Anyway, when it is possible, is recommended to use the drivers for communicate with databases, because subprocess (or os.*open*) is more expensive compared to (python needs to spawn an external process to execute the command) Enrico
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-05-06 23:28 +0100 |
| Message-ID | <mailman.1389.1367879285.3114.python-list@python.org> |
| In reply to | #44857 |
On 06/05/2013 23:12, mina@socialassets.org wrote: > On Monday, May 6, 2013 5:48:44 PM UTC-4, Enrico 'Henryx' Bianchi wrote: >> Enrico 'Henryx' Bianchi wrote: >> >> > cmd2 = subprocess.Popen(['gzip' '-c'], >> > shell=False, >> > stdout=filename) >> >> Doh, my fault: >> >> cmd2 = subprocess.Popen(['gzip' '-c'], >> shell=False, >> stdout=filename >> stdin=cmd1.stdout) >> >> Enrico > > Thank you Enrico. I've just tried your script and got this error: > stdin=cmd1.stdout) > ^ > SyntaxError: invalid syntax > > any idea? > Missing comma on the previous line.
[toc] | [prev] | [next] | [standalone]
| From | MMZ <programmer.toronto@gmail.com> |
|---|---|
| Date | 2013-05-06 15:15 -0700 |
| Message-ID | <2c1e5a9b-cd5a-4fbf-9a09-bf2e566b83f3@googlegroups.com> |
| In reply to | #44854 |
stdin=cmd1.stdout)
^
SyntaxError: invalid syntax
On Monday, May 6, 2013 5:48:44 PM UTC-4, Enrico 'Henryx' Bianchi wrote:
> Enrico 'Henryx' Bianchi wrote:
>
>
>
> > cmd2 = subprocess.Popen(['gzip' '-c'],
>
> > shell=False,
>
> > stdout=filename)
>
>
>
> Doh, my fault:
>
>
>
> cmd2 = subprocess.Popen(['gzip' '-c'],
>
> shell=False,
>
> stdout=filename
>
> stdin=cmd1.stdout)
>
>
>
> Enrico
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-07 08:12 +1000 |
| Message-ID | <mailman.1388.1367878356.3114.python-list@python.org> |
| In reply to | #44842 |
On Tue, May 7, 2013 at 5:01 AM, MMZ <programmer.toronto@gmail.com> wrote:
> username = config.get('client', 'mmz')
> password = config.get('client', 'pass1')
> hostname = config.get('client', 'localhost')
Are 'mmz', 'pass1', and 'localhost' the actual values you want for
username, password, and hostname? If so, don't pass them through
config.get() at all - just use them directly. In fact, I'd be inclined
to just stuff them straight into the Database_list_command literal;
that way, it's clear how they're used, and the fact that you aren't
escaping them in any way isn't going to be a problem (tip: an
apostrophe in your password would currently break your script).
It's also worth noting that the ~/ notation is a shell feature. You
may or may not be able to use it in config.read().
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | MMZ <programmer.toronto@gmail.com> |
|---|---|
| Date | 2013-05-06 15:40 -0700 |
| Message-ID | <f71a2143-a379-4c0c-9bdb-1a8b2cb15d79@googlegroups.com> |
| In reply to | #44856 |
On Monday, May 6, 2013 6:12:28 PM UTC-4, Chris Angelico wrote:
> On Tue, May 7, 2013 at 5:01 AM, MMZ <programmer.toronto@gmail.com> wrote:
>
> > username = config.get('client', 'mmz')
>
> > password = config.get('client', 'pass1')
>
> > hostname = config.get('client', 'localhost')
>
>
>
> Are 'mmz', 'pass1', and 'localhost' the actual values you want for
>
> username, password, and hostname? If so, don't pass them through
>
> config.get() at all - just use them directly. In fact, I'd be inclined
>
> to just stuff them straight into the Database_list_command literal;
>
> that way, it's clear how they're used, and the fact that you aren't
>
> escaping them in any way isn't going to be a problem (tip: an
>
> apostrophe in your password would currently break your script).
>
>
>
> It's also worth noting that the ~/ notation is a shell feature. You
>
> may or may not be able to use it in config.read().
>
>
>
> ChrisA
Thanks Chris. you are right.
So I used them directly and removed configParser. The new error is:
Traceback (most recent call last):
File "./bbk.py", line 11, in ?
for database in os.popen(database_list_command).readlines():
NameError: name 'database_list_command' is not defined
any idea?
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-07 08:51 +1000 |
| Message-ID | <mailman.1390.1367880718.3114.python-list@python.org> |
| In reply to | #44861 |
On Tue, May 7, 2013 at 8:40 AM, MMZ <programmer.toronto@gmail.com> wrote: > Thanks Chris. you are right. > So I used them directly and removed configParser. The new error is: > > Traceback (most recent call last): > File "./bbk.py", line 11, in ? > for database in os.popen(database_list_command).readlines(): > NameError: name 'database_list_command' is not defined Python names are case-sensitive. If you create it with a capital D, you can't reference it with a lower-case d. For consistency with the rest of your code, I'd advise lowercasing it. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-05-06 23:52 +0100 |
| Message-ID | <mailman.1391.1367880770.3114.python-list@python.org> |
| In reply to | #44861 |
On 06/05/2013 23:40, MMZ wrote:
> On Monday, May 6, 2013 6:12:28 PM UTC-4, Chris Angelico wrote:
>> On Tue, May 7, 2013 at 5:01 AM, MMZ <programmer.toronto@gmail.com> wrote:
>>
>> > username = config.get('client', 'mmz')
>>
>> > password = config.get('client', 'pass1')
>>
>> > hostname = config.get('client', 'localhost')
>>
>>
>>
>> Are 'mmz', 'pass1', and 'localhost' the actual values you want for
>>
>> username, password, and hostname? If so, don't pass them through
>>
>> config.get() at all - just use them directly. In fact, I'd be inclined
>>
>> to just stuff them straight into the Database_list_command literal;
>>
>> that way, it's clear how they're used, and the fact that you aren't
>>
>> escaping them in any way isn't going to be a problem (tip: an
>>
>> apostrophe in your password would currently break your script).
>>
>>
>>
>> It's also worth noting that the ~/ notation is a shell feature. You
>>
>> may or may not be able to use it in config.read().
>>
>>
>>
>> ChrisA
>
> Thanks Chris. you are right.
> So I used them directly and removed configParser. The new error is:
>
> Traceback (most recent call last):
> File "./bbk.py", line 11, in ?
> for database in os.popen(database_list_command).readlines():
> NameError: name 'database_list_command' is not defined
>
> any idea?
>
Check the spelling (remember that the name is case-sensitive).
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2013-05-07 08:18 +0200 |
| Message-ID | <mailman.1396.1367907512.3114.python-list@python.org> |
| In reply to | #44842 |
Chris Angelico wrote:
> It's also worth noting that the ~/ notation is a shell feature. You
> may or may not be able to use it in config.read().
The latter. Combined with
"""
read(self, filenames) method of ConfigParser.ConfigParser instance
Read and parse a filename or a list of filenames.
Files that cannot be opened are silently ignored; this is
...
"""
you'll get no configuration at all. You have to apply
os.path.expanduser()
to get a valid path.
$ cd
$ touch tmp.config
$ cd /
$ python
Python 2.7.2+ (default, Jul 20 2012, 22:15:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ConfigParser import ConfigParser
>>> p = ConfigParser()
>>> p.read("~/tmp.config")
[]
>>> import os
>>> p.read(os.path.expanduser("~/tmp.config"))
['/home/peter/tmp.config']
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web