Skip to content

Commit 1099ef9

Browse files
committed
Commands can run in any subdirectory of the app
1 parent f941d8e commit 1099ef9

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

dev_server/dev_server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313
import yaml
1414
from optparse import OptionParser
1515

16-
app_root = os.getcwd()
16+
from sae.util import search_file_bottom_up
17+
18+
app_root = search_file_bottom_up('config.yaml')
19+
if app_root is None:
20+
print >> sys.stderr, \
21+
'Error: Not an app directory(or any of the parent directories)'
22+
sys.exit(1)
23+
if app_root != os.getcwd(): os.chdir(app_root)
1724

1825
def setup_sae_environ(conf):
1926
# Add dummy pylibmc module

dev_server/sae/util.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,18 @@ def protect_secret(d):
1313
for k, v in d.items():
1414
if 'KEY' in k:
1515
half_secret(d, k)
16+
17+
import os.path
18+
19+
def search_file_bottom_up(name):
20+
curdir = os.getcwd()
21+
22+
while True:
23+
path = os.path.join(curdir, name)
24+
if os.path.isfile(path):
25+
return curdir
26+
_curdir = os.path.dirname(curdir)
27+
if _curdir == curdir:
28+
return None
29+
curdir = _curdir
30+

dev_server/saecloud

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import hashlib
1515
import urllib
1616
import urllib2
1717

18+
from sae.util import search_file_bottom_up
19+
1820
UPLOAD_SERVER = 'http://upload.sae.sina.com.cn'
1921
DEPLOY_SERVER = 'http://deploy.sae.sina.com.cn'
2022
SVN_SERVER = 'https://svn.sinaapp.com/'
@@ -54,6 +56,13 @@ def deploy(args):
5456
opts = _get_svn_opts(args)
5557
cache = LOCAL_CACHE_DIR
5658

59+
if source is None:
60+
source = search_file_bottom_up('config.yaml')
61+
if source is None:
62+
print >>sys.stderr, \
63+
'Error: Not an app directory(or any of the parent directories)'
64+
return
65+
5766
conf_file = os.path.join(source, 'config.yaml')
5867
try:
5968
conf = yaml.load(open(conf_file))
@@ -313,7 +322,10 @@ def upload_data(args):
313322
uploadfile2(f, (appname, accesskey, secretkey), domain)
314323

315324
def install(args):
316-
dest = os.path.join(os.getcwd(), 'site-packages')
325+
# If we are in an app directory, try to install the package in the
326+
# standard directory.
327+
parent_dir = search_file_bottom_up('config.yaml') or os.getcwd()
328+
dest = os.path.join(parent_dir, 'site-packages')
317329

318330
if not os.path.exists(dest):
319331
os.mkdir(dest)
@@ -379,7 +391,7 @@ def main():
379391

380392
p = subparsers.add_parser('deploy', parents=[credentials],
381393
help='deploy source directory to SAE')
382-
p.add_argument('dir', nargs='?', default='.',
394+
p.add_argument('dir', nargs='?', default=None,
383395
help='the source code directory to deploy, default to current dir')
384396
p.set_defaults(func=deploy)
385397

0 commit comments

Comments
 (0)