Re: Excute script only from another file

2013-11-25 Thread Himanshu Garg
I was also thinking to add a sys argument when invoking script and check it. My motive is "I will give scripts to somebody else and he should not run the script directly without running the parent script". -- https://mail.python.org/mailman/listinfo/python-list

Excute script only from another file

2013-11-24 Thread Himanshu Garg
I want that a script should only be executed when it is called from another script and should not be directly executable through linux command line. Like, I have two scripts "scrip1.py" and "script2.py" and there is a line in "script1.py" to call "script2.py" as subprocess.call(["python", "scri

Re: Help me to print to screen as well as log

2013-11-23 Thread Himanshu Garg
I have simply opened file in append mode in linux. script 1 : file = open("output.log", "a") file.write() file.flush() script 2: file = open("output.log", "a") file.write() file.flush() It writes properly to the file. -- https://mail.python.org/mailman/listinfo/python-list

Re: Help me to print to screen as well as log

2013-11-23 Thread Himanshu Garg
How can I write to the same file from two different scripts opened at same time? -- https://mail.python.org/mailman/listinfo/python-list

Re: Showing Progress Bar

2013-11-23 Thread Himanshu Garg
Thanks a lot Frank! Its superb. I got what I wanted. Thanks Again! -- https://mail.python.org/mailman/listinfo/python-list

Re: Showing Progress Bar

2013-11-23 Thread Himanshu Garg
for i in range(10): sys.stdout.write(".") sys.stdout.flush() time.sleep(1) sys.stdout.write("\n") shutil.copytree("pack", "/lxc/pack") But Here, the loop will first print the progress dots and then it will copy the directory. But I want that these two tasks should r

Showing Progress Bar

2013-11-23 Thread Himanshu Garg
I want to show simple dots while my program copies the files. I have found the code like: for i in range(10): print '.', time.sleep(1) But this will execute ten times as it is predefined and the task to copy will execute after or before this loop based on the location I have placed my

Help me to print to screen as well as log

2013-11-22 Thread Himanshu Garg
I want that print "hello" should appear on screen as well as get saved in a log file. How can I accomplish this? -- https://mail.python.org/mailman/listinfo/python-list

Re: Cannot connect to Mysql database

2013-11-18 Thread Himanshu Garg
I did: import MySQLdb as mdb from MySQLdb import * from MySQLdb.constants import * and now it works. Thanks! again -- https://mail.python.org/mailman/listinfo/python-list

Cannot connect to Mysql database

2013-11-18 Thread Himanshu Garg
I have written the script as: import os import MySQLdb as mdb os.chroot("/lxc/rootfs") os.chdir("/") con = mdb.connect(host="192.168.1.7", user="root", passwd="password") print "opened" con.close() But when I execute, I get the following error: "File "/usr/lib/python2.7/dist-packages/MySQLdb/__

Best approach to edit linux configuration file

2013-11-15 Thread Himanshu Garg
I have to setup the DNS server. For this I have to edit the configuration files. For this I have to search if the lines(block of text) already exist in the file and if not, I have to add them to the file. So, I want to know what is the best way to accomplish this. -- https://mail.python.org/m

Re: chroot to install packages

2013-11-14 Thread Himanshu Garg
> os.chdir("/") immediately afterwards. In any case, it's worth a try. > ChrisA Very thanks. the trick worked. -- https://mail.python.org/mailman/listinfo/python-list

Re: chroot to install packages

2013-11-14 Thread Himanshu Garg
I have done it but having a problem. I have written a script os.chroot("/lxc/test_container/rootfs") subprocess.call(["apt-key", "add", "/root/package.key"]) subprocess.call(["apt-get", "update"]) os._exit(0) Now, this script is working properly, entering the chroot jail and adding the apt key

Re: chroot to install packages

2013-11-13 Thread Himanshu Garg
On Thursday, November 14, 2013 5:10:20 AM UTC+5:30, Chris Angelico wrote: > On Thu, Nov 14, 2013 at 1:31 AM, Himanshu Garg wrote: > > > I am writing a python script to run chroot command to chroot to a linux > > distro and then run commands. How can I do this, as af

chroot to install packages

2013-11-13 Thread Himanshu Garg
I am writing a python script to run chroot command to chroot to a linux distro and then run commands. How can I do this, as after chrooting, the script runs the commands relative to the outside not inside the chrooted env? -- https://mail.python.org/mailman/listinfo/python-list