python 用Python编写的简单shell脚本来创建sbt目录结构。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 用Python编写的简单shell脚本来创建sbt目录结构。相关的知识,希望对你有一定的参考价值。

#! /usr/bin/python

import os
import os.path
import re
import sys

from subprocess import Popen, PIPE


# Compose all data.

project = "MyProject" if len(sys.argv) < 2 else sys.argv[1]

p = Popen(['scala', '-version'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
message = p.communicate()[1]

pattern = r'.+?(\d{1,}\.\d{1,}\.\d{1,}).+'
version = re.findall(pattern, message)[0]

info = { 'project': project, 'version': version }

# Create directory structure.

os.mkdir(project)

src = os.path.join(project, 'src')
main = os.path.join(src, 'main')
test = os.path.join(src, 'test')

os.mkdir(src)
os.mkdir(main)
os.mkdir(test)

folders = ['java', 'resources', 'scala']

for path in [os.path.join(main, folder) for folder in folders]:
    os.mkdir(path)

for path in [os.path.join(test, folder) for folder in folders]:
    os.mkdir(path)

# Add build.sbt file.

buildInfo = """\
name := "%(project)s"

version := "0.0.1-SNAPSHOT"

scalaVersion := "%(version)s"

""" % (info)

with open(os.path.join(project, 'build.sbt'), 'w') as f:
    f.write(buildInfo)

以上是关于python 用Python编写的简单shell脚本来创建sbt目录结构。的主要内容,如果未能解决你的问题,请参考以下文章

用shell写一个守护进程脚本

shell脚本

用 Webhook+Python+Shell 编写一套 Unix 类系统监控工具

用shell写一个猜价格脚本?

建立java与python的接口,让java能调用python脚本。请问可以用啥方式?

如何用手机编程Python?