예제 #1
0
파일: utils.py 프로젝트: kennym/itools
def check_image(filename, context):
    if vfs.exists(filename) is False:
        print u"(WW) The filename '%s' doesn't exist" % filename
        filename = context.image_not_found_path
    im = None
    if filename.startswith('http://'):
        # Remote file
        # If the image is a remote file, we create a StringIO
        # object contains the image data to avoid reportlab problems ...
        data = vfs.open(filename).read()
        my_file = context.get_tmp_file()
        filename = my_file.name
        my_file.write(data)
        my_file.close()
        im = Image(string=data)
    if im is None:
        im = ro_database.get_handler(filename, Image)

    x, y = im.get_size()
    if not (x or y):
        print u'image not valid : %s' % filename
        filename = context.image_not_found_path
        im = ro_database.get_handler(filename, Image)
        x, y = im.get_size()

    return filename, (x, y)
예제 #2
0
def check_image(filename, context):
    if vfs.exists(filename) is False:
        print u"(WW) The filename '%s' doesn't exist" % filename
        filename = context.image_not_found_path
    im = None
    if filename.startswith('http://'):
        # Remote file
        # If the image is a remote file, we create a StringIO
        # object contains the image data to avoid reportlab problems ...
        data = vfs.open(filename).read()
        my_file = context.get_tmp_file()
        filename = my_file.name
        my_file.write(data)
        my_file.close()
        im = Image(string=data)
    if im is None:
        im = ro_database.get_handler(filename, Image)

    x, y = im.get_size()
    if not (x or y):
        print u'image not valid : %s' % filename
        filename = context.image_not_found_path
        im = ro_database.get_handler(filename, Image)
        x, y = im.get_size()

    return filename, (x, y)
예제 #3
0
 def test14_remove_folder(self):
     # Create hierarchy
     vfs.make_folder('tests/folder')
     vfs.make_folder('tests/folder/a')
     vfs.make_file('tests/folder/a/hello.txt')
     # Remove and test
     vfs.remove('tests/folder')
     self.assertEqual(vfs.exists('tests/folder'), False)
예제 #4
0
파일: test_fs.py 프로젝트: kennym/itools
 def test14_remove_folder(self):
     # Create hierarchy
     vfs.make_folder('tests/folder')
     vfs.make_folder('tests/folder/a')
     vfs.make_file('tests/folder/a/hello.txt')
     # Remove and test
     vfs.remove('tests/folder')
     self.assertEqual(vfs.exists('tests/folder'), False)
예제 #5
0
파일: metadata.py 프로젝트: nkhine/itools
def parse_setupconf(package_dir):
    """Return a dict containing information from setup.conf in a itools package
    plus the version of the package
    """
    attributes = {}
    if not vfs.is_folder(package_dir):
        return attributes
    if not vfs.exists(join(package_dir, "setup.conf")):
        return attributes
    config = SetupFile(join(package_dir, "setup.conf"))
    for attribute in config.schema:
        attributes[attribute] = config.get_value(attribute)
    if vfs.exists(join(package_dir, "version.txt")):
        attributes['version'] = open(join(package_dir, "version.txt")).read()
    else:
        attributes['version'] = get_package_version(attributes['name'])
    return attributes
예제 #6
0
def parse_setupconf(package_dir):
    """Return a dict containing information from setup.conf in a itools package
    plus the version of the package
    """
    attributes = {}
    if not vfs.is_folder(package_dir):
        return attributes
    if not vfs.exists(join(package_dir, "setup.conf")):
        return attributes
    config = SetupFile(join(package_dir, "setup.conf"))
    for attribute in config.schema:
        attributes[attribute] = config.get_value(attribute)
    if vfs.exists(join(package_dir, "version.txt")):
        attributes['version'] = open(join(package_dir, "version.txt")).read()
    else:
        attributes['version'] = get_package_version(attributes['name'])
    return attributes
예제 #7
0
 def get_environment_key(self, server):
     """ In development environment we can use '/ui_dev/skin/' directory
     for skin (to avoid build JS/CSS at every changes)
     """
     if server and server.is_development_environment():
         build_path = str(server.environment['build_path'])
         base_path = self.key.split('/ui/')[0]
         new_key = self.key.replace(base_path, build_path)
         new_key = new_key.replace('/ui/', '/ui_dev/')
         if vfs.exists(new_key):
             # Use local skin
             return new_key
     return self.key
예제 #8
0
def get_minpackage(dir):
    package = split(dir)[1]
    path = join(dir, '__init__.py')
    if vfs.exists(path) and vfs.is_file(path):
        return {'name': package, 'version': get_package_version(package)}
    return None
예제 #9
0
파일: packages.py 프로젝트: nkhine/itools
def get_minpackage(dir):
    package = split(dir)[1]
    path = join(dir, "__init__.py")
    if vfs.exists(path) and vfs.is_file(path):
        return {"name": package, "version": get_package_version(package)}
    return None
예제 #10
0
def get_test_filenames(test_path, force_download):
    """Return the test file names
    If the test files does'nt exists, we download it
    """

    uris = {'http://download.wikimedia.org/qualitywiki/latest':
            [('qualitywiki-latest-stub-articles.xml', '.gz'),      #~  3.1 KB
             ('qualitywiki-latest-stub-meta-current.xml', '.gz'),  #~ 11.0 KB
             ('qualitywiki-latest-stub-meta-history.xml', '.gz')], #~ 28.9 KB
            'http://download.wikimedia.org/tawiki/latest':
            [('tawiki-latest-stub-articles.xml', '.gz'),           #~ 1.2 MB
             ('tawiki-latest-stub-meta-history.xml', '.gz')],      #~ 7.3 MB
            'http://www.w3.org/XML/Test/': [('xmlts20080205', '.tar.gz')]
            }
    compressed_dir_path = join(test_path, 'compressed_files')

    if force_download is True:
        if lfs.exists(compressed_dir_path):
            print 'Remove compressed directory ', compressed_dir_path
            lfs.remove(compressed_dir_path)
            for names in uris.itervalues():
                for (name, ext) in names:
                    path = join(test_path, name)
                    if lfs.exists(path):
                        print 'Remove %s file' % path
                        lfs.remove(path)

    # test directory
    if lfs.exists(test_path) is False:
        lfs.make_folder(test_path)

    # compressed directory
    if lfs.exists(compressed_dir_path) is False:
        lfs.make_folder(compressed_dir_path)
    else:
        lfs.open(compressed_dir_path)

    test_dir_filenames = lfs.get_names(test_path)
    for base_uri, names in uris.iteritems():
        for (name, ext) in names:
            if test_dir_filenames.count(name):
                continue
            compressed_dest = join(compressed_dir_path, '%s%s' % (name, ext))
            # check if tarball already exists
            if lfs.exists(compressed_dest) is False:
                src = join(base_uri, '%s%s' % (name, ext))
                print 'GET %s file' % src
                dest = join(test_path, name)
                if vfs.exists(src) is False:
                    print "%s uri does not exists" % src
                    continue
                src_file = vfs.open(src)
                # save Gzip file
                compressed_dest_file = lfs.make_file(compressed_dest)
                compressed_dest_file.write(src_file.read())
                compressed_dest_file.close()
                src_file.close()
            print 'Extract file %s' % compressed_dest
            # Uncompressed File Path
            if name == 'xmlts20080205':
                # uncompress only xmlconf.xml file
                tar = open_tar(compressed_dest)
                xmlconf_file = tar.extractfile('xmlconf/xmlconf.xml')
                ucf_path = join(test_path, name)
                ucf_file = lfs.make_file(ucf_path)
                ucf_file.write(xmlconf_file.read())
                ucf_file.close()
            else:
                # untar Gzip file
                compressed_dest_file = lfs.open(compressed_dest)
                gzip_file = GzipFile(compressed_dest)
                ucf_path = join(test_path, name)
                ucf_file = lfs.make_file(ucf_path)
                ucf_file.write(gzip_file.read())
                compressed_dest_file.close()
                gzip_file.close()
                ucf_file.close()

    tests = []
    # update test dir name
    test_dir_filenames = lfs.get_names(test_path)
    for filename in test_dir_filenames:
        real_path = join(test_path, filename)
        if lfs.is_file(real_path):
            bytes = lfs.get_size(real_path)
            tests.append((real_path, filename, bytes,
                          get_string_size(bytes)))
    tests.sort(key=lambda x: x[2])
    return tests
예제 #11
0
파일: test_fs.py 프로젝트: kennym/itools
 def test00_exists(self):
     exists = vfs.exists('tests/index.html.en')
     self.assertEqual(exists, True)
예제 #12
0
파일: test_fs.py 프로젝트: kennym/itools
 def tearDown(self):
     if vfs.exists('tests/toto.txt'):
         vfs.remove('tests/toto.txt')
예제 #13
0
파일: test_fs.py 프로젝트: kennym/itools
 def test17_move_file(self):
     vfs.copy('tests/hello.txt', 'tests/hello.txt.bak')
     vfs.move('tests/hello.txt.bak', 'tests/hello.txt.old')
     file = vfs.open('tests/hello.txt.old')
     self.assertEqual(file.read(), 'hello world\n')
     self.assertEqual(vfs.exists('tests/hello.txt.bak'), False)
예제 #14
0
파일: test_fs.py 프로젝트: kennym/itools
 def test13_remove_empty_folder(self):
     vfs.remove('tests/folder')
     self.assertEqual(vfs.exists('tests/folder'), False)
예제 #15
0
 def test13_remove_empty_folder(self):
     vfs.remove('tests/folder')
     self.assertEqual(vfs.exists('tests/folder'), False)
예제 #16
0
 def tearDown(self):
     if vfs.exists('sandbox'):
         vfs.remove('sandbox')
예제 #17
0
파일: packages.py 프로젝트: kennym/itools
def get_minpackage(dir):
    package = split(dir)[1]
    path = join(dir, '__init__.py')
    if vfs.exists(path) and vfs.is_file(path):
        return {'name': package, 'version': get_package_version(package)}
    return None
예제 #18
0
            units = handler.get_units(srx_handler=srx_handler)
            units = list(units)
        except Exception:
            print
            print '*'
            print '* Error:', path
            print '*'
            raise

        relative_path = Path('..').resolve2(path)
        for source, context, line in units:
            po.add_unit(relative_path, source, context, line)
    print

    # Update locale.pot
    if not vfs.exists('locale/locale.pot'):
        vfs.make_file('locale/locale.pot')

    write('* Update PO template ')
    data = po.to_str()
    file = vfs.open('locale/locale.pot', WRITE)
    try:
        file.write(data)
    finally:
        file.close()
    print

    # Update PO files
    folder = vfs.open('locale')
    filenames = set([x for x in folder.get_names() if x[-3:] == '.po'])
    filenames.add('%s.po' % src_language)
예제 #19
0
파일: test_fs.py 프로젝트: kennym/itools
 def test12_remove_file(self):
     vfs.remove('tests/file')
     self.assertEqual(vfs.exists('tests/file'), False)
예제 #20
0
 def test17_move_file(self):
     vfs.copy('tests/hello.txt', 'tests/hello.txt.bak')
     vfs.move('tests/hello.txt.bak', 'tests/hello.txt.old')
     file = vfs.open('tests/hello.txt.old')
     self.assertEqual(file.read(), 'hello world\n')
     self.assertEqual(vfs.exists('tests/hello.txt.bak'), False)
예제 #21
0
 def test19_traverse(self):
     for x in vfs.traverse('.'):
         self.assertEqual(vfs.exists(x), True)
예제 #22
0
 def tearDown(self):
     if vfs.exists('tests/toto.txt'):
         vfs.remove('tests/toto.txt')
예제 #23
0
파일: test_fs.py 프로젝트: kennym/itools
 def test19_traverse(self):
     for x in vfs.traverse('.'):
         self.assertEqual(vfs.exists(x), True)
예제 #24
0
 def tearDown(self):
     if vfs.exists('tmp'):
         vfs.remove('tmp')
예제 #25
0
파일: test_fs.py 프로젝트: kennym/itools
 def tearDown(self):
     if vfs.exists('tmp'):
         vfs.remove('tmp')
예제 #26
0
 def test00_exists(self):
     exists = vfs.exists('tests/index.html.en')
     self.assertEqual(exists, True)
예제 #27
0
파일: test_fs.py 프로젝트: kennym/itools
 def test01_does_not_exist(self):
     exists = vfs.exists('tests/fdsfsf')
     self.assertEqual(exists, False)
예제 #28
0
 def test01_does_not_exist(self):
     exists = vfs.exists('tests/fdsfsf')
     self.assertEqual(exists, False)
예제 #29
0
 def tearDown(self):
     if vfs.exists('sandbox'):
         vfs.remove('sandbox')
예제 #30
0
 def test12_remove_file(self):
     vfs.remove('tests/file')
     self.assertEqual(vfs.exists('tests/file'), False)
예제 #31
0
    def __init__(self, target, read_only=False, cache_size=None,
                 profile_space=False):
        target = lfs.get_absolute_path(target)
        self.target = target
        self.read_only = read_only
        # Set timestamp
        self.timestamp = str(int(time() / 2))
        # Load the config
        config = get_config(target)
        self.config = config
        load_modules(config)
        self.modules = config.get_value('modules')

        # Contact Email
        self.smtp_from = config.get_value('smtp-from')

        # Full-text indexing
        self.index_text =  config.get_value('index-text', type=Boolean,
                                            default=True)
        # Accept cors
        self.accept_cors = config.get_value(
            'accept-cors', type=Boolean, default=False)

        # Profile Memory
        if profile_space is True:
            import guppy.heapy.RM

        # The database
        if cache_size is None:
            cache_size = config.get_value('database-size')
        if ':' in cache_size:
            size_min, size_max = cache_size.split(':')
        else:
            size_min = size_max = cache_size
        size_min, size_max = int(size_min), int(size_max)
        read_only = read_only or config.get_value('database-readonly')
        database = get_database(target, size_min, size_max, read_only)
        self.database = database

        # Find out the root class
        root = get_root(database)

        # Load environment file
        root_file_path = inspect.getfile(root.__class__)
        environement_path = str(get_reference(root_file_path).resolve('environment.json'))
        if vfs.exists(environement_path):
            with open(environement_path, 'r') as f:
                data = f.read()
                self.environment = json.loads(data)

        # Init fake context
        context = get_fake_context(database, root.context_cls)
        context.server = self

        # Initialize
        access_log = '%s/log/access' % target
        super(Server, self).__init__(root, access_log=access_log)

        # Email service
        self.spool = lfs.resolve2(self.target, 'spool')
        spool_failed = '%s/failed' % self.spool
        if not lfs.exists(spool_failed):
            lfs.make_folder(spool_failed)
        # Configuration variables
        get_value = config.get_value
        self.smtp_host = get_value('smtp-host')
        self.smtp_login = get_value('smtp-login', default='').strip()
        self.smtp_password = get_value('smtp-password', default='').strip()
        # Email is sent asynchronously
        self.flush_spool()

        # Logging
        log_file = '%s/log/events' % target
        log_level = config.get_value('log-level')
        if log_level not in log_levels:
            msg = 'configuraion error, unexpected "%s" value for log-level'
            raise ValueError, msg % log_level
        log_level = log_levels[log_level]
        logger = Logger(log_file, log_level, rotate=timedelta(weeks=3))
        register_logger(logger, None)
        logger = WebLogger(log_file, log_level)
        register_logger(logger, 'itools.web')
        # Session timeout
        self.session_timeout = get_value('session-timeout')
        # Register routes
        self.register_dispatch_routes()
예제 #32
0
            units = handler.get_units(srx_handler=srx_handler)
            units = list(units)
        except Exception:
            print
            print '*'
            print '* Error:', path
            print '*'
            raise

        relative_path = Path('..').resolve2(path)
        for source, context, line in units:
            po.add_unit(relative_path, source, context, line)
    print

    # Update locale.pot
    if not vfs.exists('locale/locale.pot'):
        vfs.make_file('locale/locale.pot')

    write('* Update PO template ')
    data = po.to_str()
    file = vfs.open('locale/locale.pot', WRITE)
    try:
        file.write(data)
    finally:
        file.close()
    print

    # Update PO files
    folder = vfs.open('locale')
    filenames = set([ x for x in folder.get_names() if x[-3:] == '.po' ])
    filenames.add('%s.po' % src_language)