Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60396

Re: Excute script only from another file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'scripts': 0.03; 'subject:file': 0.07; 'sys': 0.07; 'executable': 0.09; 'executed': 0.09; 'subject:script': 0.09; 'argument,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'garg': 0.16; 'sys.exit(1)': 0.16; 'wrote:': 0.18; 'command': 0.22; 'import': 0.22; 'mon,': 0.24; 'script': 0.25; 'pass': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'rest': 0.29; 'message-id:@mail.gmail.com': 0.30; '25,': 0.31; 'follows': 0.31; 'run': 0.32; 'another': 0.32; 'linux': 0.33; 'subject:from': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'like,': 0.36; 'should': 0.36; 'two': 0.37; 'nov': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'special': 0.74; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=kAF7gH+V8PDjnUDnMk9RITvilUNbkr7pUmETiFLmtSM=; b=kufzkpxSek/ASeJc6IRdKv0qZiwmPDREbR10rD2O68d1Qy+7oBuZOIZpIierlUW+Pf SgrbxKZarCWhpjloaYIElq6kaRKw3ancB0WEdWymAgb7C585PUNzMpUzPQHldSO39mt5 qW4khIpdGCJuNp6Thaj+EMw1PwUlfNNua3SN5OwwF1HH+CZCabqb0MndbVUP1lG1QBsL YF8BnC8qD7SMqFNhHVeBJ/Nt3CvJY2UR40q1zyVqxte6gfzpEFaEdLknghncTR2D+kMe wdQ9GsoRngsVKUTuV1wh02J/NnQ4BJdoL/a1YBuHdiC0rQZQeRvfgkvScqOjj50u7bD8 vaog==
MIME-Version 1.0
X-Received by 10.66.150.41 with SMTP id uf9mr25415759pab.108.1385349339032; Sun, 24 Nov 2013 19:15:39 -0800 (PST)
In-Reply-To <989ee1b9-141a-4cb3-a9a2-f1527c0d0db3@googlegroups.com>
References <989ee1b9-141a-4cb3-a9a2-f1527c0d0db3@googlegroups.com>
Date Mon, 25 Nov 2013 14:15:38 +1100
Subject Re: Excute script only from another file
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3156.1385349348.18130.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385349348 news.xs4all.nl 15970 [2001:888:2000:d::a6]:42515
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60396

Show key headers only | View raw


On Mon, Nov 25, 2013 at 12:55 PM, Himanshu Garg <hgarg.india@gmail.com> wrote:
> 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", "script2.py"]).
>
> Then this is should call script2 but I should not be able to directly call script2 as $python script2.py

Easy! Just have your subprocess.call pass a special argument, which
you then look for in script2:

subprocess.call(["python", "script2.py","confirm"])

# script2.py
import sys
if "confirm" not in sys.argv:
    print("This script should not be run directly.")
    sys.exit(1)

# rest of script2.py follows

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Excute script only from another file Himanshu Garg <hgarg.india@gmail.com> - 2013-11-24 17:55 -0800
  Re: Excute script only from another file Chris Angelico <rosuav@gmail.com> - 2013-11-25 14:15 +1100
  Re: Excute script only from another file Dave Angel <davea@davea.name> - 2013-11-24 22:20 -0500
    Re: Excute script only from another file Larry Hudson <orgnut@yahoo.com> - 2013-11-26 00:10 -0800
  Re: Excute script only from another file Michael Torrie <torriem@gmail.com> - 2013-11-24 19:58 -0700
  Re: Excute script only from another file Peter Otten <__peter__@web.de> - 2013-11-25 09:12 +0100
  Re: Excute script only from another file Himanshu Garg <hgarg.india@gmail.com> - 2013-11-25 02:52 -0800
    Re: Excute script only from another file Dave Angel <davea@davea.name> - 2013-11-25 07:16 -0500
    Re: Excute script only from another file Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-25 18:28 -0800
      Re: Excute script only from another file Chris Angelico <rosuav@gmail.com> - 2013-11-26 13:41 +1100
        Re: Excute script only from another file Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-25 19:45 -0800
      Re: Excute script only from another file Steven D'Aprano <steve@pearwood.info> - 2013-11-26 03:09 +0000
      Re: Excute script only from another file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-26 12:25 -0500
      Re: Excute script only from another file Chris Angelico <rosuav@gmail.com> - 2013-11-27 10:09 +1100
        Re: Excute script only from another file Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-26 17:56 -0800
          Re: Excute script only from another file Chris Angelico <rosuav@gmail.com> - 2013-11-27 13:39 +1100

csiph-web