Skip to content

Commit 6fa99a7

Browse files
committed
增加配置文件功能
1 parent e0d4727 commit 6fa99a7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

netkiller/docker.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# -*- coding: utf-8 -*-
2+
#========================================
3+
4+
# Home: https://www.netkiller.cn
5+
# Callsign: BG7NYT
6+
#========================================
27
import os, sys
38
import copy
49
import json
@@ -401,6 +406,7 @@ class Composes(Common):
401406
compose = {}
402407
daemon = False
403408
basedir = "."
409+
files = {}
404410

405411
def __init__(self, name):
406412
super().__init__()
@@ -413,6 +419,7 @@ def __init__(self, name):
413419
self.environ = None
414420
self.projectName = None
415421
self.envFile = None
422+
self.files = {}
416423

417424
def env(self, default):
418425
# if not self.environ :
@@ -448,6 +455,10 @@ def volumes(self, obj):
448455
self.compose["volumes"] = copy.deepcopy(obj.volumes)
449456
return self
450457

458+
def file(self, filename, text):
459+
self.files[filename]=text
460+
return self
461+
451462
def debug(self):
452463
jsonformat = json.dumps(
453464
self.compose, sort_keys=True, indent=4, separators=(",", ":")
@@ -461,6 +472,20 @@ def filename(self):
461472
return self.basedir + "/" + self.name + "/" + "compose.yaml"
462473

463474
def save(self, filename=None):
475+
476+
for filepath, content in self.files.items():
477+
dirname = os.path.dirname(filepath)
478+
try:
479+
if not os.path.isdir(dirname):
480+
os.makedirs(dirname)
481+
self.logger.info("Create directory %s" % dirname)
482+
with open(filepath, "w") as file:
483+
file.writelines(content)
484+
self.logger.info("Create file %s" % filepath)
485+
486+
except Exception as e:
487+
self.logger.error(f"Create file {filepath} {repr(e)}")
488+
464489
if not filename:
465490
filename = self.filename()
466491

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name="netkiller-devops",
12-
version="0.7.5",
12+
version="0.7.6",
1313
author="Neo Chen",
1414
author_email="[email protected]",
1515
description="DevOps of useful deployment and automation",

0 commit comments

Comments
 (0)