def create_template_file(tdir, template, from_template=None, template_code=None):
    splitted = template.split('/')
    fname = splitted[-1]
    if len(splitted) > 1:  # we have to check/create containing dirs
        for dname in splitted[:-1]:
            if not tdir.has_key(dname):
                # lets create it
                new = Directory(dname)
                tdir[dname] = new
                tdir = tdir
    
            tdir = tdir[dname]
    
    
    # get the template-template name
    if from_template and from_template != 'none':
        print 'getting template template:', from_template
        # and create the pagetemplate from the template-template
        if fname not in tdir.keys():
            templ = DTMLTemplate()
            tdir.factories[fname] = JinjaTemplate
            templ.template = templatepath(from_template) + '.dtml'
            tdir[fname] = templ
    else:
        # if template code is given, fill it into the file
        if template_code:
            if fname not in tdir.keys():
                file = File()
                file.data = template_code
                tdir[fname] = file
 def test_file_persistance(self):
     filepath = os.path.join(self.tempdir, 'file.txt')
     file = File(name=filepath)
     file.direct_sync = True
     self.assertFalse(os.path.exists(filepath))
     file()
     self.assertFalse(os.path.isdir(filepath))
     self.assertTrue(os.path.exists(filepath))
     with open(filepath) as f:
         out = f.read()
     self.assertEqual(out, '')
    def test_file_permissions(self):
        filepath = os.path.join(self.tempdir, 'file.txt')
        file = File(name=filepath)
        self.assertEqual(file.fs_mode, None)

        file.fs_mode = 0o644
        file.direct_sync = True

        file()
        self.assertTrue(os.path.exists(filepath))
        self.assertEqual(os.stat(filepath).st_mode & 0o777, 0o644)

        file.fs_mode = 0o600
        file()
        self.assertEqual(os.stat(filepath).st_mode & 0o777, 0o600)

        file = File(name=filepath)
        self.assertEqual(file.fs_mode, 0o600)
Exemple #4
0
def generate_vanilla_profile(self, source, target):
    egg = egg_source(source)
    if not is_generator_egg(egg):
        return

    tgv = TaggedValues(source)
    profilename = tgv.direct('name', 'generator:profile', source.name)

    basepath = os.path.dirname(agx.generator.generator.__file__)
    profilepath = os.path.join(basepath, 'resources', 'vanilla_profile')

    # read the model files
    model_di = open(os.path.join(profilepath, 'model.profile.di')).read()
    model_uml = open(os.path.join(profilepath, 'model.profile.uml')).read()
    model_notation = open(os.path.join(profilepath,
                                       'model.profile.notation')).read()

    eggdir = read_target_node(egg_source(source), target.target)

    # create profiles dir
    if 'profiles' not in eggdir.keys():
        profiles = Directory()
        profiles.__name__ = 'profiles'
        eggdir['profiles'] = profiles

    profiles = eggdir['profiles']

    # add the model files with correct name and change the references
    if profilename + '.profile.di' not in profiles.keys():
        ff = File()
        ff._data = model_di.replace('model.profile.notation',
                                    profilename + '.profile.notation')
        profiles[profilename + '.profile.di'] = ff

    if profilename + '.profile.uml' not in profiles.keys():
        ff = File()
        ff._data = model_uml.replace('profilename_changeme', profilename)
        profiles[profilename + '.profile.uml'] = ff

    if profilename + '.profile.notation' not in profiles.keys():
        ff = File()
        ff._data = model_notation.replace('model.profile.uml',
                                          profilename + '.profile.uml')
        profiles[profilename + '.profile.notation'] = ff
    def test_file_mode_text(self):
        filepath = os.path.join(self.tempdir, 'file.txt')
        file = File(name=filepath)
        file.direct_sync = True

        self.assertEqual(file.mode, MODE_TEXT)
        self.assertEqual(file.data, '')
        self.assertEqual(file.lines, [])

        file.data = 'abc\ndef'
        file()
        with open(filepath) as f:
            out = f.readlines()
        self.assertEqual(out, ['abc\n', 'def'])

        file = File(name=filepath)
        self.assertEqual(file.data, 'abc\ndef')
        self.assertEqual(file.lines, ['abc', 'def'])

        file.lines = ['a', 'b', 'c']
        file()
        with open(filepath) as f:
            out = f.read()
        self.assertEqual(out, 'a\nb\nc')
def typeicon(self, source, target):
    egg = egg_source(source)
    package = read_target_node(egg, target.target)
    resources = package['resources']
    icon = '%s_icon.png' % source.name.lower()
    klass = read_target_node(source, target.target)
    folderish = token(str(klass.uuid), True, folderish=False).folderish
    if not icon in resources:
        default = package['profiles']['default']
        type_name = type_id(source, target.target)
        name = '%s.xml' % type_name

        fti = default['types'][name]
        if folderish:
            path = templatepath('folder_icon.png')
        else:
            path = templatepath('document_icon.png')

        file = resources[icon] = File()
        file.mode = MODE_BINARY
        with open(path) as template:
            file.data = template.read()
def generate_vanilla_profile(self, source, target):
    egg = egg_source(source)
    if not is_generator_egg(egg):
        return

    tgv = TaggedValues(source)
    profilename = tgv.direct('name', 'generator:profile', source.name)

    basepath = os.path.dirname(agx.generator.generator.__file__)
    profilepath = os.path.join(basepath, 'resources', 'vanilla_profile')

    # read the model files
    model_di = open(os.path.join(profilepath, 'model.profile.di')).read()
    model_uml = open(os.path.join(profilepath, 'model.profile.uml')).read()
    model_notation = open(
        os.path.join(profilepath, 'model.profile.notation')).read()

    eggdir = read_target_node(egg_source(source), target.target)

    # create profiles dir
    if 'profiles' not in eggdir.keys():
        profiles = Directory()
        profiles.__name__ = 'profiles'
        eggdir['profiles'] = profiles

    profiles = eggdir['profiles']

    # add the model files with correct name and change the references
    if profilename + '.profile.di' not in profiles.keys():
        ff = File()
        ff._data = model_di.replace(
            'model.profile.notation', profilename + '.profile.notation')
        profiles[profilename + '.profile.di'] = ff

    if profilename + '.profile.uml' not in profiles.keys():
        ff = File()
        ff._data = model_uml.replace('profilename_changeme', profilename)
        profiles[profilename + '.profile.uml'] = ff
    
    if profilename + '.profile.notation' not in profiles.keys():
        ff = File()
        ff._data = model_notation.replace(
            'model.profile.uml', profilename + '.profile.uml')
        profiles[profilename + '.profile.notation'] = ff