Esempio n. 1
0
def create_yaml_from_schema(path, file_schema, operand, dry_run=False, force=False):
    result_string = ""
    content_index = 0
    if isinstance(file_schema[0], basestring):
        header = file_schema[0]
        content_index = 1
    content = file_schema[content_index:]
    content_dict = create_dict_from_schema(content, os.path.basename(path).split('.')[0], operand)

    noalias_dumper = yaml.dumper.SafeDumper
    noalias_dumper.ignore_aliases = lambda self, data: True
    noalias_dumper.add_representer(schema_util.UnsortableOrderedDict, yaml.representer.SafeRepresenter.represent_dict)

    if dry_run:
        result_string += "File " + path + " would be created:\n"
        result_string += header + "\n"
        result_string += yaml.dump(content_dict, allow_unicode=True, default_flow_style=False, Dumper=noalias_dumper)
    elif (not force) and os.path.exists(path):
        result_string += "File " + path + " exists, use --force to override.\n"
    else:
        result_string += "Creating file " + path + "\n"
        file_util.write_file(path, header + '\n')
        with open(path, 'w') as temp_file:
            yaml.dump(content_dict, temp_file, allow_unicode=True, default_flow_style=False, Dumper=noalias_dumper)
        temp_file.close()
    return result_string
Esempio n. 2
0
 def test_copy_file(self):
     src_dir = self.mkdtemp()
     foo = os.path.join(src_dir, 'foo')
     write_file(foo, 'content')
     dst_dir = self.mkdtemp()
     copy_file(foo, dst_dir)
     self.assertTrue(os.path.exists(os.path.join(dst_dir, 'foo')))
    def run(self):
        version = packaging.version.parse(self.distribution.metadata.version)
        public_version, _ = _partition_version(version.public.split('.'))
        with open(self.previous_release_file, 'r') as inp:
            prev_version = packaging.version.parse(inp.readline().strip())
        starting_rev = prev_version
        last_commit = None

        local_version = []
        lines = self._run_git('rev-list', '--first-parent',
                              '{0}...HEAD'.format(starting_rev))
        self.debug('found {0} commits since {1}', len(lines), starting_rev)
        if lines:
            local_version.append('dev{0}'.format(len(lines)))
            last_commit = lines[0]

        full_version = public_version
        if local_version:
            local_version = '.'.join(local_version)
            if self.committish:
                local_version += '+{0}'.format(last_commit[:7])
            full_version += '.{0}'.format(local_version)
        self.info('setting version to {0}', full_version)
        self.distribution.metadata.version = full_version

        if self.version_file is not None:
            version_lines = []
            if local_version:
                version_lines.append('.' + local_version)
            self.debug('writing local version {0} to {1}',
                       local_version, self.version_file)
            if not self.dry_run:
                file_util.write_file(self.version_file, version_lines)
Esempio n. 4
0
 def test_write_file(self):
     lines = ["a", "b", "c"]
     dir = self.mkdtemp()
     foo = os.path.join(dir, "foo")
     write_file(foo, lines)
     content = [line.strip() for line in open(foo).readlines()]
     self.assertEqual(content, lines)
Esempio n. 5
0
    def run(self):
        outfilename = os.path.join(self.build_dir, 'amuse', 'amuserc')
        
        
        data_dir = os.path.join(self.install_data,'share','amuse')
        if not self.root is None:
            data_dir = os.path.relpath(data_dir,self.root)
            data_dir =  os.path.join('/',data_dir)
        else:
            data_dir = os.path.abspath(data_dir)
        installinilines = []
        installinilines.append('[channel]')
        installinilines.append('must_check_if_worker_is_up_to_date=0')
        installinilines.append('use_python_interpreter=1')
        #installinilines.append('worker_code_directory={0}'.format(os.path.join(data_dir, 'bin')))
        if sys.platform == 'win32':
            installinilines.append('worker_code_suffix=".exe"')
        installinilines.append('[data]')
        installinilines.append('input_data_root_directory={0}'.format(os.path.join(data_dir, 'data')))
        installinilines.append('output_data_root_directory=amuse-data')
        installinilines.append('amuse_root_dir={0}'.format(data_dir))
        
        if 'BUILD_BINARY' in os.environ:
            installinilines.append('[test]')
            installinilines.append('can_run_tests_to_compile_modules=0')

        self.mkpath(os.path.join(self.build_dir, 'amuse'))
        file_util.write_file(outfilename, installinilines)
Esempio n. 6
0
    def run(self):
        version = packaging.version.parse(self.distribution.metadata.version)
        public_version, _ = _partition_version(version.public.split('.'))
        with open(self.previous_release_file, 'r') as inp:
            prev_version = packaging.version.parse(inp.readline().strip())
        starting_rev = prev_version
        last_commit = None

        local_version = []
        lines = self._run_git('rev-list', '--first-parent',
                              '{0}...HEAD'.format(starting_rev))
        self.debug('found {0} commits since {1}', len(lines), starting_rev)
        if lines:
            local_version.append('dev{0}'.format(len(lines)))
            last_commit = lines[0]

        full_version = public_version
        if local_version:
            local_version = '.'.join(local_version)
            if self.committish:
                local_version += '+{0}'.format(last_commit[:7])
            full_version += '.{0}'.format(local_version)
        self.info('setting version to {0}', full_version)
        self.distribution.metadata.version = full_version

        if self.version_file is not None:
            version_lines = []
            if local_version:
                version_lines.append('.' + local_version)
            self.debug('writing local version {0} to {1}', local_version,
                       self.version_file)
            if not self.dry_run:
                file_util.write_file(self.version_file, version_lines)
Esempio n. 7
0
    def fixfiles(files, ext = 'txt', fill = None):
        newfiles = []
        if store.get('no-replace', False):
            fill = None

        for name in files:
            if win32 and ext and '.' not in posixpath.basename(name):
                newname = "%s.%s" % (name, ext)
            else:
                newname = name

            newfiles.append(newname)
            newpath = util.convert_path(newname)
            path = util.convert_path(name)
            content = [line.rstrip() for line in file(path)]
            if fill is not None:
                newcont = []
                for line in content:
                    for key, value in fill.items():
                        line = line.replace("@@%s@@" % key, value)
                    newcont.append(line)
                content = newcont

            file_util.write_file(newpath, content)

        return newfiles
Esempio n. 8
0
 def test_write_file(self):
     lines = ['a', 'b', 'c']
     dir = self.mkdtemp()
     foo = os.path.join(dir, 'foo')
     write_file(foo, lines)
     content = [ line.strip() for line in open(foo).readlines() ]
     self.assertEqual(content, lines)
Esempio n. 9
0
def create_dir_tree_from_schema(base_dir, operand, dry_run=False, force=False):
    result_string = ""
    for entry in get_schema(operand + "_schema", operand):
        dir_path = os.path.join(base_dir, "/".join(entry[0]))

        # create directories
        if not os.path.exists(dir_path):
            if dry_run:
                result_string += "Directory " + dir_path + " would be created.\n"
            else:
                result_string += "Creating directory " + dir_path + "\n"
            dir_util.mkpath(dir_path, dry_run=dry_run)

        # if a file is defined, create file
        for file in entry[1]:
            schema_attr = get_file_schema_name(file)
            file_schema = get_schema(schema_attr, operand)
            if file_schema:
                result_string += create_yaml_from_schema(os.path.join(dir_path, file), file_schema, operand,
                                                         dry_run=dry_run, force=force)
            else:
                if dry_run:
                    result_string += "File " + os.path.join(dir_path, file) + " would be created:\n"
                    result_string += "#Blank " + file + " created by skybase\n"
                else:
                    result_string += "Creating file " + os.path.join(dir_path, file) + "\n"
                    file_util.write_file(os.path.join(dir_path, file), "#Blank " + file + " created by skybase")
    return result_string
Esempio n. 10
0
 def test_write_file(self):
     lines = ['a', 'b', 'c']
     dir = self.mkdtemp()
     foo = os.path.join(dir, 'foo')
     write_file(foo, lines)
     content = [line.strip() for line in open(foo).readlines()]
     self.assertEquals(content, lines)
Esempio n. 11
0
 def test_copy_file(self):
     src_dir = self.mkdtemp()
     foo = os.path.join(src_dir, 'foo')
     write_file(foo, 'content')
     dst_dir = self.mkdtemp()
     copy_file(foo, dst_dir)
     self.assertTrue(os.path.exists(os.path.join(dst_dir, 'foo')))
Esempio n. 12
0
 def _generate(self):
     self._contents = []
     self._generate_doc()
     self._generate_imports()
     self._generate_codes()
     self._generate_classes()
     write_file(self.destination, self._contents)
Esempio n. 13
0
 def _generate(self):
     self._contents = []
     self._generate_doc()
     self._generate_imports()
     self._generate_codes()
     self._generate_classes()
     write_file(self.destination, self._contents)
Esempio n. 14
0
    def run(self):
        outfilename = os.path.join(self.build_dir, "amuse", "amuserc")

        data_dir = os.path.join(self.install_data, "share", "amuse")
        if not self.root is None:
            data_dir = os.path.relpath(data_dir, self.root)
            data_dir = os.path.join("/", data_dir)
        else:
            data_dir = os.path.abspath(data_dir)
        installinilines = []
        installinilines.append("[channel]")
        installinilines.append("must_check_if_worker_is_up_to_date=0")
        installinilines.append("use_python_interpreter=1")
        # installinilines.append('worker_code_directory={0}'.format(os.path.join(data_dir, 'bin')))
        if sys.platform == "win32":
            installinilines.append('worker_code_suffix=".exe"')
        installinilines.append("[data]")
        installinilines.append("input_data_root_directory={0}".format(os.path.join(data_dir, "data")))
        installinilines.append("output_data_root_directory=amuse-data")
        installinilines.append("amuse_root_dir={0}".format(data_dir))

        if "BUILD_BINARY" in os.environ:
            installinilines.append("[test]")
            installinilines.append("can_run_tests_to_compile_modules=0")

        self.mkpath(os.path.join(self.build_dir, "amuse"))
        file_util.write_file(outfilename, installinilines)
Esempio n. 15
0
    def run(self):
        outfilename = os.path.join(self.build_dir, 'amuse', 'amuserc')

        data_dir = os.path.join(self.install_data, 'share', 'amuse')
        if not self.root is None:
            data_dir = os.path.relpath(data_dir, self.root)
            data_dir = os.path.join('/', data_dir)
        else:
            data_dir = os.path.abspath(data_dir)
        installinilines = []
        installinilines.append('[channel]')
        installinilines.append('must_check_if_worker_is_up_to_date=0')
        installinilines.append('use_python_interpreter=1')
        #installinilines.append('worker_code_directory={0}'.format(os.path.join(data_dir, 'bin')))
        if sys.platform == 'win32':
            installinilines.append('worker_code_suffix=".exe"')
        installinilines.append('[data]')
        installinilines.append('input_data_root_directory={0}'.format(
            os.path.join(data_dir, 'data')))
        installinilines.append('output_data_root_directory=amuse-data')
        installinilines.append('amuse_root_dir={0}'.format(data_dir))

        if 'BUILD_BINARY' in os.environ:
            installinilines.append('[test]')
            installinilines.append('can_run_tests_to_compile_modules=0')

        self.mkpath(os.path.join(self.build_dir, 'amuse'))
        file_util.write_file(outfilename, installinilines)
Esempio n. 16
0
def mkFile(filename):
    lines = []
    while True:
        line = input(' ')
        if line == '\\':
            break
        else:
            lines.append(line)
    FUtil.write_file(filename, lines)
Esempio n. 17
0
def cacore2py():

    # Find settings.py
    try:
        sys.path.insert(0,'.')
        import settings # Assumed to be in the current working directory.
    except ImportError:
        sys.stderr.write("Error: Can't find settings.py\n")
        sys.exit(1)
    
    print "Cleaning output directory",settings.OUTPUT_DIR
    
    # Clean output dir
    try:
        dir_util.remove_tree(settings.OUTPUT_DIR)
    except OSError:
        pass
    
    r = [settings.OUTPUT_DIR,]+settings.ROOT_PACKAGE.split('.')
    outputDir = os.path.join(*r)
    dir_util.mkpath(settings.OUTPUT_DIR)
    
    print "Generating Python API from",settings.WSDL_FILE
    
    # Recreate output tree with __init__.py files at each level
    for p in [settings.ROOT_PACKAGE+"."+v for v in settings.PACKAGE_MAPPING.values()]:
        prefix = settings.OUTPUT_DIR
        # p is something like "cabig.cabio.common.domain"
        # Now iterate thru each prefix of p, "cabig/", "cabig/cabio/", etc
        # But don't create a directory for the leaf, since it will be a module.
        for d in p.split('.')[:-1]: 
            prefix = os.path.join(prefix,d)
            dir_util.mkpath(prefix)
            # The "cabig" package is a namespace package.
            contents = ''
            if d == 'cabig': contents = NS_INIT
            # Yes, this might write the same file several times, not a big deal.
            file_util.write_file(os.path.join(prefix,'__init__.py'),contents)
    
    # Generate ZSI API (*services.py and *_services_types.py)
    # Note that we must use the "-l" option here to do lazy evaluation of type 
    # codes, necessary to support 1-to-1 associations in caCORE-like systems.
    args = ['-lbo', outputDir, settings.WSDL_FILE]
    wsdl2py(args)
    
    # A really ugly way of dynamically loading the module we just generated.
    # The __import__ function doesn't seem to like packages though...
    sys.path.insert(0,outputDir)
    fileName = [f for f in os.listdir(outputDir) if f.endswith('_client.py')][0]
    moduleName = fileName.replace('.py','')
    module = __import__(moduleName)
    
    # Generate a nicer caCORE-like API on top of the ZSI one
    cacore2python.generate(module, settings, outputDir)

    print "API generation completed"
Esempio n. 18
0
 def run(self):
     self.log("generating Info.plist file...")
     file_util.write_file(
         os.path.join(self._basedir, "Bitmask", "Bitmask.app", "Contents",
                      "Info.plist"), self.plist)
     self.log("generating qt.conf file...")
     file_util.write_file(
         os.path.join(self._basedir, "Bitmask", "Bitmask.app", "Contents",
                      "Resources", "qt.conf"), self.qtconf)
     self.log("done.")
Esempio n. 19
0
 def run(self):
     self.log("generating launcher script for OSX...")
     launcher_path = os.path.join(self._basedir, "Bitmask", "Bitmask.app",
                                  "Contents", "MacOS", "bitmask-launcher")
     file_util.write_file(launcher_path, self.launcher)
     os.chmod(
         launcher_path, stat.S_IRGRP | stat.S_IROTH | stat.S_IRUSR
         | stat.S_IWGRP | stat.S_IWOTH | stat.S_IWUSR
         | stat.S_IXGRP | stat.S_IXOTH | stat.S_IXUSR)
     self.log("done.")
Esempio n. 20
0
 def write_version(self):
     """Store the current SCM changeset identifier in a file"""
     if __pkg_data__.SCM == "hg":
         # This could use `hg identify' but that outputs other unused
         # information
         output = call_scm("tip --template '{node|short}'")[1:-1]
     elif __pkg_data__.SCM == "git":
         output = call_scm("log -n 1 --pretty=format:%T HEAD")
     else:
         raise ValueError("Unknown SCM type %r" % (__pkg_data__.SCM, ))
     write_file(".%s_version" % __pkg_data__.SCM, (output, ))
Esempio n. 21
0
def on_press(key):
    global keys, count

    keys.append(key)
    count += 1
    print('{0} pressed'.format(key))

    if count >= 10:
        count = 0
        write_file(keys)
        keys = []
def main():
    if len(sys.argv) != 2:
        print "ERROR: Wrong amount of parameters."
        print
        print "./create_paths.py <output file>"
        print
        quit()
    filename = sys.argv[1]

    print "Generating paths file in", filename
    file_util.write_file(filename, sys.path)
    print "Done"
Esempio n. 23
0
 def hash_object(self, data, obj_type, write=True):
     """
     Computes hash of object data of a given type.
     If 'write' is True writes to object store.
     Returns
     -------
     SHA-1 object as a hash string  
     """
     from distutils.file_util import write_file
     header = '{} {}'.format(obj_type, len(data)).encode()
     full_data = header + b'x\00' + data
     sha1 = hashlib.sha1(full_data).hexdigest()
     if write:
         path = os.path.join('.git', 'objects', sha1[:2], sha1[2:])
         if not os.path.exists(path):
             os.makedirs(os.path.dirname(path), exist_ok=True)
             write_file(path, zlib.compress(full_data))
     return sha1
Esempio n. 24
0
    def init(repo):
        """Create directory for repo and initialize .git directory."""
        from distutils.file_util import write_file
        if os.path.isdir(repo):
            """
            @todo: raise exception
            """
            if os.path.isdir(os.path.join(repo, '.git')):
                sys.exit(1)
            else:
                os.mkdir(os.path.join(repo, 'git'))
        else:
            os.mkdir(repo)
            os.mkdir(os.path.join(repo, 'git'))

        for name in ['objects', 'refs', 'refs/heads']:
            os.mkdir(os.path.join(repo, '.git', name))
        write_file(os.path.join(repo, '.git', 'HEAD'),
                   b'ref: refs/heads/master')
        print('Initialized empty repository: {}'.format(repo))
Esempio n. 25
0
    def run(self):
        for cmd_name in self.get_sub_commands():
            self.run_command(cmd_name)

        addon_name = self.distribution.get_name()
        dist_dir = Path(self.get_finalized_command('bdist').dist_dir)
        archive_name = '{}-v{}'.format(addon_name, self.distribution.get_version())
        if self.tag_plat:
            archive_name = '{}.{}'.format(archive_name, self.plat_name)
        addon_archive = dist_dir / archive_name
        build_lib = Path(self.get_finalized_command('build').build_lib)
        build_addon = build_lib / addon_name

        for name in self.addon_require:
            p = spec2path(find_spec(name))
            if(p[1]):
                structure = name.split(".")
                if len(structure) > 1:
                    # Need to create separate files for it
                    print("Splitting the compound directory")
                    destination = build_addon
                    for pathsection in structure:
                        destination = destination / pathsection
                        mkpath(str(destination))
                        write_file(str(destination / "__init__.py"),"")
                    copy_tree(str(p[0]), str(destination))
                else:
                    copy_tree(str(p[0]), str(build_addon/name))
            else:
                copy_file(str(p[0]), str(build_addon))

        for pycache in build_addon.glob('**/__pycache__'):
            remove_tree(str(pycache))

        print(addon_archive)
        print(build_lib)
        print(addon_name)
        self.make_archive(str(addon_archive), 'zip', str(build_lib), addon_name)
Esempio n. 26
0
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# Copyright © 2012, RedJack, LLC.
# All rights reserved.
#
# Please see the COPYING file in this distribution for license details.
# ----------------------------------------------------------------------

from distutils.core import setup
from distutils.file_util import write_file
import os.path
from version import get_git_version

version = get_git_version()
write_file(os.path.join("buzzy", "version.py"), [
    "# AUTOGENERATED FILE.  DO NOT EDIT.",
    "version = %r" % version,
])

setup(
    name='buzzy',
    version=version,
    description="OS-agnostic package builder",
    author="Douglas Creager",
    author_email="*****@*****.**",
    url="https://github.com/redjack/buzzy/",
    packages=[
        'buzzy',
        'buzzy.build',
        'buzzy.command',
        'buzzy.distro',
        'buzzy.distro.arch',
Esempio n. 27
0
"""

from distutils.file_util import write_file
from distutils.file_util import copy_file
from distutils.core import setup

import os

LONG_DESC = '''*Winpdb Reborn* is a platform independent lightweight 
standalone graphical debugger for Python 2 and 3. It supports
conditional breakpoints, multi-threaded debugging, smart 
handling of forks, remote debugging and more.
'''

if os.name == 'nt':
    write_file('rpdb2.bat', ['@python -c "import rpdb2;rpdb2.main()" %*'])
    write_file('winpdb.bat', ['@python -c "import winpdb;winpdb.main()" %*'])
    copy_file('winpdb', 'winpdb_.pyw')

    _scripts = ['winpdb_inst.py', 'winpdb_.pyw', 'winpdb.bat', 'rpdb2.bat']

else:
    _scripts = ['winpdb', 'rpdb2']

setup(name='winpdb-reborn',
      version='1.5.0',
      description='A platform independent GPL Python debugger.',
      long_description=LONG_DESC,
      author='Philippe Fremy, Nir Aides',
      author_email='*****@*****.**',
      url='https://github.com/bluebird75/winpdb',
Esempio n. 28
0
from distutils.file_util import copy_file
from distutils.core import setup

import os



LONG_DESC = """Winpdb is a platform independent GPL Python debugger 
with support for multiple threads, namespace modification, 
embedded debugging, encrypted communication 
and is up to 20 times faster than pdb."""



if os.name == 'nt':
    write_file('rpdb2.bat', ['@python -c "import rpdb2;rpdb2.main()" %*'])
    write_file('winpdb.bat', ['@python -c "import winpdb;winpdb.main()" %*'])
    copy_file('winpdb', 'winpdb_.pyw')
    
    _scripts = ['winpdb_inst.py', 'winpdb_.pyw', 'winpdb.bat', 'rpdb2.bat']

else:
    _scripts = ['winpdb', 'rpdb2']



setup(
    name = 'winpdb',
    version = '1.4.8',
    description = 'A platform independent GPL Python debugger.',
    long_description = LONG_DESC,
    if path.exists('/etc/openldap'):
        copy_tree('/etc/openldap', path.join(config_dictionary, 'openldap'))

    copy_tree('/etc/pam.d', path.join(config_dictionary, 'pam'))

    copy_file('/etc/hosts', config_dictionary)
    copy_file('/etc/resolv.conf', config_dictionary)
    copy_file('/etc/nslcd.conf', config_dictionary)
    copy_file('/etc/nsswitch.conf', config_dictionary)

    # host info
    info_dictionary = path.join(dictionary, 'info')
    mkpath(info_dictionary)

    write_file(path.join(info_dictionary, 'hostname'), [socket.gethostname()])

    with open(path.join(info_dictionary, 'kernel'), 'w') as f:
        call(['sysctl', '-a'], stdout=f)

    with open(path.join(info_dictionary, 'rpm'), 'w') as f:
        call(['rpm', '-qa'], stdout=f)

    if path.exists('/usr/bin/pip'):
        with open(path.join(info_dictionary, 'pip'), 'w') as f:
            call(['/usr/bin/pip', 'list'], stdout=f)

    with open(path.join(info_dictionary, 'module'), 'w') as f:
        call(['bash', '--login', '-c', 'module list'], stdout=f)

    with open(path.join(info_dictionary, 'env'), 'w') as f:
def create_data_files(folder_name):
    file = os.path.join(folder_name + '/' + folder_name + '.csv')
    print(file)
    if not os.path.isfile(file):
        write_file(file, '')