Play源码深入之一:从play命令开始

Play的命令是借助python脚本,这从下载的play包就能明显看出来:一是其中有一个python包,里面是一个play自带的python环境,还有是play.bat文件:

@echo off
"%~dp0python\python.exe" "%~dp0play" %*

使用python运行play文件,而play文件里就是python代码。也就是我们平时用的play命令全作用于其中。用python来操作java项目管理是比较好的方法,我参与的两个大项目都是如此。

我们一起来看看python是如何操控java滴。 play文件中引入了commandLoader/application/utils等文件,他们位于/framework/pym下:

from play.cmdloader import CommandLoader
from play.application import PlayApplication
from play.utils import *

首先看看commandLoader,其主要作用是加载command文件下所有模块、命令等。 

在command文件夹中包含了在命令行中使用的所有命令,如:eclipse.py中,就是包含了eclipsify与ec,后者是前者的简化。对play项目进行了导入优化。其他如intellij.py/netbeans.py/ant.py三个文件都如此。

import os, os.path
import shutil
import time

from play.utils import *

COMMANDS = ['eclipsify', 'ec']

HELP = {
'eclipsify': 'Create all Eclipse configuration files'
}

def execute(**kargs):
...

这里重要是daemon.py与base.py。 daemon.py中含有start/stop/restart三个关于应用开关的命令。在自己的项目中我们也可以借鉴他的实现方法。

COMMANDS = ['start', 'stop', 'restart', 'pid', 'out']

HELP = {
'start': 'Start the application in the background',
'stop': 'Stop the running application',
'restart': 'Restart the running application',
'pid': 'Show the PID of the running application',
'out': 'Follow logs/system.out file'
}

base.py中含有 run/new/clean/test等命令。

COMMANDS = ['run', 'new', 'clean', 'test', 'autotest', 'auto-test', 'id', 'new,run', 'clean,run', 'modules']

HELP = {
'id': "Define the framework ID",
'new': "Create a new application",
'clean': "Delete temporary files (including the bytecode cache)",
'run': "Run the application in the current shell",
'test': "Run the application in test mode in the current shell",
'auto-test': "Automatically run all application tests",
'modules': "Display the computed modules list"
}

utils.py中是能用辅助模块,从名称就可以看出来。像获取java版本、play版本、将项目打包成war等。 appliction.py是应用辅助模块,包括对应用文件、模块的检查、添加jar包等方法。其中也包含python操作java的java_cmd方法。 

一个play start demo 流程: cmd输入 -> play文件中 -> daemon.py -> appliction.py -> java

转载于:https://my.oschina.net/markho/blog/498291

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值