コード例 #1
0
ファイル: test_handlers.py プロジェクト: kennym/itools
 def setUp(self):
     database = RWDatabase(100, 100)
     self.database = database
     self.root = database.get_handler('.')
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('I am Toto\n')
     finally:
         file.close()
コード例 #2
0
 def setUp(self):
     database = RWDatabase(100, 100)
     self.database = database
     self.root = database.get_handler('.')
     file = lfs.make_file('tests/toto.txt')
     try:
         file.write('I am Toto\n')
     finally:
         file.close()
コード例 #3
0
ファイル: pdfwriter.py プロジェクト: jbq/pancito
    def gencontract(self, user, contract):
        c = self.conn.cursor()

        c.execute("SELECT coalesce(sum(amount), 0) FROM extra_payment WHERE contract_id = ? AND user_id = ?", (contract['id'], user['id']))
        extraAmount = c.fetchone()[0]

        c.execute("SELECT sum(quantity) AS quantity, * FROM bakeorder INNER JOIN bake ON bake.rowid = bakeid INNER JOIN product ON product.id = productid WHERE contract_id = ? AND userid = ? GROUP BY productid", (contract['id'], user['id']))
        orders = c.fetchall()
        if len(orders) == 0:
            raise Exception("No order for %s, skipping" % user['name'])

        # Adapt contract for display
        for field in ('startdate', 'enddate'):
            contract[field] = contract[field].strftime("%d %B %Y")

        info = Struct(**user)
        info.update(**contract)
        info.placeName = contract['place']['name']
        info.date = date.today().strftime("%d %B %Y")
        c.execute("SELECT count(*) FROM bake WHERE contract_id = ?", (contract['id'],))
        info.bakeCount = c.fetchone()[0]

        # FIXME
        orderdisplays = []
        orderAmount = 0
        for order in orders:
            orderdisplays.append("%s %s" % (order['quantity'], order['name']))
            orderAmount += order['quantity'] * order['itemprice']
        info.order = " et ".join(orderdisplays)
        info.balance = pancito.displayAmount(orderAmount - extraAmount)
        syslog.syslog(syslog.LOG_DEBUG, "Contract info: %s" % repr(info.__dict__))

        rw_database = RWDatabase(fs=lfs)
        handler = rw_database.get_handler(os.path.join(pancito.datadir, 'model.odt'))
        document = stl_to_odt(handler, info)
        handler = ODTFile(string=document)
        tmpfile = tempfile.mktemp(".odt")
        tmpdir = tempfile.mkdtemp("", "pdfwriter")
        rw_database.set_handler(tmpfile, handler)
        rw_database.save_changes()

        if not os.path.exists("/usr/bin/libreoffice"):
            raise Exception("Cannot find libreoffice")

        if not os.path.exists("/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"):
            raise Exception("Arial font not found, please install ttf-mscorefonts-installer")

        cmd = ["/usr/bin/libreoffice", "--headless", "--invisible", "--convert-to", "pdf", "--outdir", tmpdir, tmpfile]
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        sc = p.wait()
        if sc != 0:
            raise Exception("Command returned status %s: %s.\nOutput:\n%s\nError:\n%s" % (sc, cmd, p.stdout.read(), p.stderr.read()))

        os.unlink(tmpfile)
        self.createAdhesion(user['id'], contract['id'], orderAmount)
        return os.path.join(tmpdir, os.path.basename(tmpfile).replace('.odt', '.pdf'))
コード例 #4
0
ファイル: clients.py プロジェクト: staverne/itools

class Clients(CSVFile):

    columns = ['client_id', 'name', 'email', 'registration_date']

    schema = {
        'client_id': Integer,
        'name': Unicode,
        'email': String,
        'registration_date': Date
    }


if __name__ == '__main__':
    rw_database = RWDatabase()
    clients = rw_database.get_handler("clients.csv", Clients)

    # Access a column by its name
    row = clients.get_row(0)

    # Now 'update_row' expects the values to be of the good type
    clients.update_row(0, registration_date=date(2004, 11, 10))

    # So is for the 'add_row' method
    clients.add_row(
        [250, u'J. David Ibanez', '*****@*****.**',
         date(2007, 1, 1)])

    print clients.to_str()
コード例 #5
0
ファイル: test_handlers.py プロジェクト: kennym/itools
    def test_quote_value(self):
        # Init data
        value = "HELLO, \"WORLD\"!"
        self._init_test(value)

        # Write data
        config = rw_database.get_handler(self.config_path, ConfigFile)
        try:
            config.set_value("test", value)
        except SyntaxError, e:
            self.fail(e)
        config.save_state()

        # Read data
        config2 = rw_database.get_handler(self.config_path, ConfigFile)
        try:
            config2_value = config2.get_value("test")
        except SyntaxError, e:
            self.fail(e)
        finally:
            lfs.remove(self.config_path)

        # Test data
        self.assertEqual(config2_value, value)



    def test_wrapped_quote_value(self):
        # Init data
        value = "\"HELLO, WORLD!\""
コード例 #6
0
ファイル: clients.py プロジェクト: Nabellaleen/itools
from itools.handlers import RWDatabase
from itools.datatypes import Integer, Unicode, String, Date


class Clients(CSVFile):

    columns = ['client_id', 'name', 'email', 'registration_date']

    schema = {
        'client_id': Integer,
        'name': Unicode,
        'email': String,
        'registration_date': Date}


if __name__ == '__main__':
    rw_database = RWDatabase()
    clients = rw_database.get_handler("clients.csv", Clients)

    # Access a column by its name
    row = clients.get_row(0)

    # Now 'update_row' expects the values to be of the good type
    clients.update_row(0, registration_date=date(2004, 11, 10))

    # So is for the 'add_row' method
    clients.add_row(
        [250, u'J. David Ibanez', '*****@*****.**', date(2007, 1, 1)])

    print clients.to_str()
コード例 #7
0
    def test_quote_value(self):
        # Init data
        value = "HELLO, \"WORLD\"!"
        self._init_test(value)

        # Write data
        config = rw_database.get_handler(self.config_path, ConfigFile)
        try:
            config.set_value("test", value)
        except SyntaxError, e:
            self.fail(e)
        config.save_state()

        # Read data
        config2 = rw_database.get_handler(self.config_path, ConfigFile)
        try:
            config2_value = config2.get_value("test")
        except SyntaxError, e:
            self.fail(e)
        finally:
            lfs.remove(self.config_path)

        # Test data
        self.assertEqual(config2_value, value)

    def test_wrapped_quote_value(self):
        # Init data
        value = "\"HELLO, WORLD!\""
        self._init_test(value)