mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-05 04:34:10 +00:00
use filepath
This commit is contained in:
parent
bab77eded8
commit
0af033beb7
@ -2,10 +2,10 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
from os.path import exists, join
|
|
||||||
|
|
||||||
from twisted.python import usage
|
from twisted.python import usage
|
||||||
#from allmydata.node import read_config
|
from twisted.python.filepath import FilePath
|
||||||
|
|
||||||
from allmydata.client import read_config
|
from allmydata.client import read_config
|
||||||
from allmydata.grid_manager import (
|
from allmydata.grid_manager import (
|
||||||
parse_grid_manager_certificate,
|
parse_grid_manager_certificate,
|
||||||
@ -16,6 +16,7 @@ from allmydata.util.encodingutil import argv_to_abspath
|
|||||||
from allmydata.util import fileutil
|
from allmydata.util import fileutil
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GenerateKeypairOptions(BaseOptions):
|
class GenerateKeypairOptions(BaseOptions):
|
||||||
|
|
||||||
def getUsage(self, width=None):
|
def getUsage(self, width=None):
|
||||||
@ -80,7 +81,7 @@ class AddGridManagerCertOptions(BaseOptions):
|
|||||||
)
|
)
|
||||||
if self['filename'] == '-':
|
if self['filename'] == '-':
|
||||||
print("reading certificate from stdin", file=self.parent.parent.stderr)
|
print("reading certificate from stdin", file=self.parent.parent.stderr)
|
||||||
data = sys.stdin.read()
|
data = self.parent.parent.stdin.read()
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
raise usage.UsageError(
|
raise usage.UsageError(
|
||||||
"Reading certificate from stdin failed"
|
"Reading certificate from stdin failed"
|
||||||
@ -124,11 +125,11 @@ def add_grid_manager_cert(options):
|
|||||||
config = read_config(nd, "portnum")
|
config = read_config(nd, "portnum")
|
||||||
config_path = join(nd, "tahoe.cfg")
|
config_path = join(nd, "tahoe.cfg")
|
||||||
cert_fname = "{}.cert".format(options['name'])
|
cert_fname = "{}.cert".format(options['name'])
|
||||||
cert_path = config.get_config_path(cert_fname)
|
cert_path = FilePath(config.get_config_path(cert_fname))
|
||||||
cert_bytes = json.dumps(options.certificate_data, indent=4) + '\n'
|
cert_bytes = json.dumps(options.certificate_data, indent=4) + '\n'
|
||||||
cert_name = options['name']
|
cert_name = options['name']
|
||||||
|
|
||||||
if exists(cert_path):
|
if cert_path.exists():
|
||||||
msg = "Already have certificate for '{}' (at {})".format(
|
msg = "Already have certificate for '{}' (at {})".format(
|
||||||
options['name'],
|
options['name'],
|
||||||
cert_path,
|
cert_path,
|
||||||
@ -140,11 +141,8 @@ def add_grid_manager_cert(options):
|
|||||||
config.set_config("grid_manager_certificates", cert_name, cert_fname)
|
config.set_config("grid_manager_certificates", cert_name, cert_fname)
|
||||||
|
|
||||||
# write all the data out
|
# write all the data out
|
||||||
|
with cert_path.open("wb") as f:
|
||||||
fileutil.write(cert_path, cert_bytes)
|
f.wrwite(cert_bytes)
|
||||||
with open(config_path, "w") as f:
|
|
||||||
# XXX probably want a _Config.write_tahoe_cfg() or something?
|
|
||||||
config.config.write(f)
|
|
||||||
|
|
||||||
cert_count = len(config.enumerate_section("grid_manager_certificates"))
|
cert_count = len(config.enumerate_section("grid_manager_certificates"))
|
||||||
print("There are now {} certificates".format(cert_count), file=options.parent.parent.stderr)
|
print("There are now {} certificates".format(cert_count), file=options.parent.parent.stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user