示例#1
0
文件: runner.py 项目: phlax/l10n.xtle
def init_settings(settings_filepath,
                  template_filename,
                  db="sqlite",
                  db_name="dbs/xtle.db",
                  db_user="",
                  db_password="",
                  db_host="",
                  db_port=""):
    """Initializes a sample settings file for new installations.

    :param settings_filepath: The target file path where the initial settings
        will be written to.
    :param template_filename: Template file used to initialize settings from.
    :param db: Database engine to use
        (default=sqlite, choices=[mysql, postgresql]).
    :param db_name: Database name (default: xtledb) or path to database file
        if using sqlite (default: dbs/xtle.db)
    :param db_user: Name of the database user. Not used with sqlite.
    :param db_password: Password for the database user. Not used with sqlite.
    :param db_host: Database host. Defaults to localhost. Not used with sqlite.
    :param db_port: Database port. Defaults to backend default. Not used with
        sqlite.
    """
    from base64 import b64encode

    dirname = os.path.dirname(settings_filepath)
    if dirname and not os.path.exists(dirname):
        os.makedirs(dirname)

    if db == "sqlite":
        db_name = "working_path('%s')" % (db_name or "dbs/xtle.db")
        db_user = db_password = db_host = db_port = "''"
    else:
        db_name = "'%s'" % (db_name or "xtledb")
        db_user = "******" % (db_user or "xtle")
        db_password = "******" % db_password
        db_host = "'%s'" % db_host
        db_port = "'%s'" % db_port

    db_module = {
        'sqlite': 'sqlite3',
        'mysql': 'mysql',
        'postgresql': 'postgresql',
    }[db]

    context = {
        "default_key":
        ("'%s'" % b64encode(os.urandom(KEY_LENGTH)).decode("utf-8")),
        "db_engine": "'django.db.backends.%s'" % db_module,
        "db_name": db_name,
        "db_user": db_user,
        "db_password": db_password,
        "db_host": db_host,
        "db_port": db_port,
    }

    with open(settings_filepath, 'w') as settings:
        with open(template_filename) as template:
            settings.write(
                (template.read().decode("utf8") % context).encode("utf8"))
示例#2
0
def init_settings(settings_filepath, template_filename,
                  db="sqlite", db_name="dbs/pootle.db", db_user="",
                  db_password="", db_host="", db_port=""):
    """Initializes a sample settings file for new installations.

    :param settings_filepath: The target file path where the initial settings
        will be written to.
    :param template_filename: Template file used to initialize settings from.
    :param db: Database engine to use
        (default=sqlite, choices=[mysql, postgresql]).
    :param db_name: Database name (default: pootledb) or path to database file
        if using sqlite (default: dbs/pootle.db)
    :param db_user: Name of the database user. Not used with sqlite.
    :param db_password: Password for the database user. Not used with sqlite.
    :param db_host: Database host. Defaults to localhost. Not used with sqlite.
    :param db_port: Database port. Defaults to backend default. Not used with
        sqlite.
    """
    from base64 import b64encode

    dirname = os.path.dirname(settings_filepath)
    if dirname and not os.path.exists(dirname):
        os.makedirs(dirname)

    if db == "sqlite":
        db_name = "working_path('%s')" % (db_name or "dbs/pootle.db")
        db_user = db_password = db_host = db_port = "''"
    else:
        db_name = "'%s'" % (db_name or "pootledb")
        db_user = "******" % (db_user or "pootle")
        db_password = "******" % db_password
        db_host = "'%s'" % db_host
        db_port = "'%s'" % db_port

    db_module = {
        'sqlite': 'sqlite3',
        'mysql': 'mysql',
        'postgresql': 'postgresql',
    }[db]

    context = {
        "default_key": ("'%s'"
                        % b64encode(os.urandom(KEY_LENGTH)).decode("utf-8")),
        "db_engine": "'django.db.backends.%s'" % db_module,
        "db_name": db_name,
        "db_user": db_user,
        "db_password": db_password,
        "db_host": db_host,
        "db_port": db_port,
    }

    with open(settings_filepath, 'w') as settings:
        with open(template_filename) as template:
            settings.write(
                (template.read().decode("utf8") % context).encode("utf8"))
示例#3
0
def generate_settings(filename):
	settings = xmlet.ElementTree()

	root = xmlet.Element("settings")
	settings._setroot(root)
	basic = xmlet.SubElement(root, "basicsettings")
	# 路口参数
	crossing = xmlet.SubElement(basic, "crossing")
	xmlet.SubElement(crossing, "serial").text = Crossing.objects.all()[0].serial
	xmlet.SubElement(crossing, "code").text = Crossing.objects.all()[0].code
	xmlet.SubElement(crossing, "name").text = Crossing.objects.all()[0].name
	xmlet.SubElement(crossing, "kilometer").text = Crossing.objects.all()[0].kilometer
	xmlet.SubElement(crossing, "meter").text = Crossing.objects.all()[0].meter
	xmlet.SubElement(crossing, "operator").text = Crossing.objects.all()[0].operator
	xmlet.SubElement(crossing, "name_format").text = Crossing.objects.all()[0].name_format
	xmlet.SubElement(crossing, "image_size").text = Crossing.objects.all()[0].image_size
	xmlet.SubElement(crossing, "image_quality").text = Crossing.objects.all()[0].image_quality
	# 测速参数
	speed = xmlet.SubElement(basic, "speed")
	xmlet.SubElement(speed, "speed_limit").text = MeasureSpeed.objects.all()[0].speed_limit
	xmlet.SubElement(speed, "speed_starting").text = MeasureSpeed.objects.all()[0].speed_starting
	xmlet.SubElement(speed, "speed_delta").text = MeasureSpeed.objects.all()[0].speed_delta
	xmlet.SubElement(speed, "lane_same").text = MeasureSpeed.objects.all()[0].lane_same
	xmlet.SubElement(speed, "enable_direction1").text = MeasureSpeed.objects.all()[0].enable_direction1
	xmlet.SubElement(speed, "direction1").text = MeasureSpeed.objects.all()[0].direction1
	xmlet.SubElement(speed, "d1_lane1_delta").text = MeasureSpeed.objects.all()[0].d1_lane1_delta
	xmlet.SubElement(speed, "d1_lane2_delta").text = MeasureSpeed.objects.all()[0].d1_lane2_delta
	xmlet.SubElement(speed, "d1_lane3_delta").text = MeasureSpeed.objects.all()[0].d1_lane3_delta
	xmlet.SubElement(speed, "d1_lane4_delta").text = MeasureSpeed.objects.all()[0].d1_lane4_delta
	xmlet.SubElement(speed, "enable_direction2").text = MeasureSpeed.objects.all()[0].enable_direction2
	xmlet.SubElement(speed, "direction2").text = MeasureSpeed.objects.all()[0].direction2
	xmlet.SubElement(speed, "d2_lane1_delta").text = MeasureSpeed.objects.all()[0].d2_lane1_delta
	xmlet.SubElement(speed, "d2_lane2_delta").text = MeasureSpeed.objects.all()[0].d2_lane2_delta
	xmlet.SubElement(speed, "d2_lane3_delta").text = MeasureSpeed.objects.all()[0].d2_lane3_delta
	xmlet.SubElement(speed, "d2_lane4_delta").text = MeasureSpeed.objects.all()[0].d2_lane4_delta
	# FTP参数
	ftp = xmlet.SubElement(basic, "ftp")
	xmlet.SubElement(ftp, "enable_ftp").text = FTPSetting.objects.all()[0].enable_ftp
	xmlet.SubElement(ftp, "remote").text = FTPSetting.objects.all()[0].remote
	xmlet.SubElement(ftp, "port").text = FTPSetting.objects.all()[0].port
	xmlet.SubElement(ftp, "enable_time").text = FTPSetting.objects.all()[0].enable_time
	xmlet.SubElement(ftp, "time_start").text = FTPSetting.objects.all()[0].time_start
	xmlet.SubElement(ftp, "time_finished").text = FTPSetting.objects.all()[0].time_finished
	xmlet.SubElement(ftp, "username").text = FTPSetting.objects.all()[0].username
	xmlet.SubElement(ftp, "password").text = FTPSetting.objects.all()[0].password
	# 服务器上传参数
	upload = xmlet.SubElement(basic, "upload")
	xmlet.SubElement(upload, "enable_upload").text = ServerUpload.objects.all()[0].enable_upload
	xmlet.SubElement(upload, "serverip").text = ServerUpload.objects.all()[0].serverip
	xmlet.SubElement(upload, "serverport").text = ServerUpload.objects.all()[0].serverport
	# 清理参数
	clear = xmlet.SubElement(basic, "clear")
	xmlet.SubElement(clear, "elapse").text = ClearSetting.objects.all()[0].elapse
	xmlet.SubElement(clear, "enable_usb").text = ClearSetting.objects.all()[0].enable_usb

	system = xmlet.SubElement(root, "syssettings")
	# 网络参数
	networking = xmlet.SubElement(system, "networking")
	xmlet.SubElement(networking, "ipaddress").text = Networking.objects.all()[0].ipaddress
	xmlet.SubElement(networking, "netmask").text = Networking.objects.all()[0].netmask
	xmlet.SubElement(networking, "gateway").text = Networking.objects.all()[0].gateway
	xmlet.SubElement(networking, "dns").text = Networking.objects.all()[0].dns
	# 日期和时间
	datetime = xmlet.SubElement(system, "datetime")
	xmlet.SubElement(datetime, "date").text = Datetime.objects.all()[0].date
	xmlet.SubElement(datetime, "time").text = Datetime.objects.all()[0].time
	xmlet.SubElement(datetime, "enable_sync").text = Datetime.objects.all()[0].enable_sync
	xmlet.SubElement(datetime, "time_server").text = Datetime.objects.all()[0].time_server
	# 用户登录
	login = xmlet.SubElement(system, "login")
	xmlet.SubElement(login, "username").text = Login.objects.all()[0].username
	xmlet.SubElement(login, "password").text = Login.objects.all()[0].password

	xmlet.dump(xml_indent(root))
	settings.write(filename, "utf-8")
示例#4
0
def update_settings(name):
    with open('settings.py', 'r') as base_settings:
        content = base_settings.read().replace('%%%project_name%%%', name)
        with open(os.path.join(name, SOURCE_DIRECTORY_NAME, name, 'settings.py'), 'w') as settings:
            settings.write(content)
示例#5
0
def update_settings(name):
    with open('settings.py', 'r') as base_settings:
        content = base_settings.read().replace('%%%project_name%%%', name)
        with open(os.path.join(name, SOURCE_DIRECTORY_NAME, name, 'settings.py'), 'w') as settings:
            settings.write(content)