예제 #1
0
def main():
    locale.setlocale(locale.LC_ALL, "")
    config = Config("./data/config.json")
    company = get_data_from_json("./data/company.json")

    config.set("payment_paypal", "PayPal address: " + company["paypal"])
    with codecs.open("template/bank-details.html", "r", encoding="utf-8") as html_doc:
        config.set("payment_wire", html_doc.read())

    template = InvoiceTemplate(config.get("html_template_path"), company)
    if template.is_invalid():
        return

    invoice_list = InvoiceList(config.get("database_path"))
    invoice_list.parse_csv(config)
    htmls = map(
        template.get_invoices_as_html, invoice_list.db, itertools.repeat(config)
    )
    filenames = (invoice.get_filename() for invoice in invoice_list.db)

    db_file_path = config.get("database_path")
    assert os.path.isfile(db_file_path)
    db_file_name = os.path.splitext(os.path.basename(db_file_path))[0]
    dir_out = os.path.join(config.get("output_path"), db_file_name)
    set_up_output_directory(dir_out)
    save_html_files(dir_out, htmls, filenames)
    render(dir_out, as_png=False)
예제 #2
0
파일: sc.py 프로젝트: oh8/inpanel
    def timezone(self, inifile, timezone=None):
        """Get or set system timezone.

        Pass None to parameter config (as default) to get timezone,
        or pass timezone full name like 'Asia/Shanghai' to set timezone.
        """
        tzpath = '/etc/localtime'
        zonepath = '/usr/share/zoneinfo'

        config = Config(inifile)
        if not config.has_section('time'):
            config.add_section('time')

        if timezone == None:
            # firstly read from config file
            timezone = ''
            if config.has_option('time', 'timezone'):
                timezone = config.get('time', 'timezone')
            if timezone:
                return timezone

            # or else check the system config file
            dist = ServerInfo.dist()
            if dist['name'] in ('centos', 'redhat'):
                clockinfo = raw_loadconfig('/etc/sysconfig/clock')
                if clockinfo and 'ZONE' in clockinfo:
                    timezone = clockinfo['ZONE']
                    return timezone
            else:
                pass

            # or else find the file match /etc/localtime
            with open(tzpath) as f:
                tzdata = f.read()
            regions = ServerSet.timezone_regions()
            for region in regions:
                regionpath = os.path.join(zonepath, region)
                for zonefile in os.listdir(regionpath):
                    if not os.path.isfile(os.path.join(regionpath, zonefile)):
                        continue
                    with open(os.path.join(regionpath, zonefile)) as f:
                        if f.read() == tzdata:  # got it!
                            return '%s/%s' % (region, zonefile)
        else:
            # check and set the timezone
            timezonefile = os.path.join(zonepath, timezone)
            if not os.path.exists(timezonefile):
                return False
            try:
                shutil.copyfile(timezonefile, tzpath)
            except:
                return False

            # write timezone setting to config file
            return config.set('time', 'timezone', timezone)
예제 #3
0
loginlock:       set the login lock. value: on or off
accesskey:       access key for remote access, must be empty
                 or a 64-bytes string with base64 encoded.
accesskeyenable: set the remote access switch. value: on or off
''' % sys.argv[0])
        sys.exit()

    data_path = os.path.join(os.path.dirname(__file__), 'data')
    config = Config(data_path + '/config.ini')

    option, value = sys.argv[1:]
    if option == 'ip':
        if value != '*' and not is_valid_ip(value):
            print 'Error: %s is not a valid IP address' % value
            sys.exit(-1)
        config.set('server', 'ip', value)
    elif option == 'port':
        port = int(value)
        if not port > 0 and port < 65535:
            print 'Error: port number should between 0 and 65535'
            sys.exit(-1)
        config.set('server', 'port', value)
    elif option == 'username':
        config.set('auth', 'username', value)
    elif option == 'password':
        key = randstr()
        md5 = hashlib.md5(value).hexdigest()
        pwd = hmac.new(key, md5).hexdigest()
        config.set('auth', 'password', '%s:%s' % (pwd, key))
    elif option == 'loginlock':
        if value not in ('on', 'off'):