コード例 #1
0
def create_client(muni_name, display_name=''):
    """Add an entry for a new municipality or update an existing one to the munis.js file with the required data"""
    
    with lcd(os.path.join('..', 'opentaba-client')):
        # download the online gush map
        geojson_gush_map = _download_gush_map(muni_name)
        
        # make sure we're using the master branch
        local('git checkout master')
    
        # load the current municipalities' index dictionary
        with open(os.path.join('..', 'opentaba-client', 'munis.js')) as index_data:
            original_index_json = loads(index_data.read().replace('var municipalities = ', '').rstrip('\n').rstrip(';'))
        
        new_index_json = deepcopy(original_index_json)
    
        # add a new entry if needed
        if muni_name not in new_index_json.keys():
            if display_name == '':
                abort('For new municipalities display name must be provided')
        
            new_index_json[muni_name] = {'display':'', 'center':[]}
    
        # update the display name and center of the municipality's entry
        new_index_json[muni_name]['display'] = display_name
        new_index_json[muni_name]['center'] = _get_muni_center(geojson_gush_map['features'])
        new_index_json[muni_name]['bounds'] = _get_muni_bounds(geojson_gush_map['features'])
        
        # don't try to add, commit etc. if no changes were made
        if dumps(new_index_json, sort_keys=True) == dumps(original_index_json, sort_keys=True):
            warn('No new data was found in the downloaded gush map. No changes were made to munis.js')
        else:
            # write back the munis.js file
            out = open(os.path.join('..', 'opentaba-client', 'munis.js'), 'w')
            out.write('var municipalities = ' + dumps(new_index_json, sort_keys=True, indent=4, separators=(',', ': ')) + ';')
            out.flush()
            os.fsync(out.fileno())
            out.close()
    
            # commit and push to origin
            local('git add munis.js')
            local('git commit -m "added %s to munis.js"' % muni_name)
            local('git push origin master')
            
            # merge into gh-pages branch
            local('git checkout gh-pages')
            local('git merge master --no-edit')
            local('git push origin gh-pages')
            
            # back to master for work
            local('git checkout master')
            
            print '*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*'
            print 'The new/updated municipality data was added to munis.js, its topojson '
            print 'gushim map will be loaded from the israel_gushim repository, and changes were '
            print 'committed and pushed to origin. If more data needs to be in munis.js, you can '
            print 'do it now and push again. The municipality\'s site is now live at:'
            print 'http://%s.opentaba.info/' % muni_name
            print '*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*'
コード例 #2
0
def update_gushim_server(muni_name):
    """Add the gush ids from an existing online gush map to the lib/gushim.py file"""

    # download the online gush map
    gush_map = _download_gush_map(muni_name)
    gush_ids = []

    # make a list of all gush ids in the file
    for geometry in gush_map['features']:
        gush_ids.append(geometry['properties']['Name'])

    # make sure we're using the master branch
    local('git checkout master')

    # open and load the existing gushim dictionary from lib/gushim.py
    with open(os.path.join('lib', 'gushim.py')) as gushim_data:
        existing_gushim = loads(gushim_data.read().replace('GUSHIM = ', ''))

    # if the municipality already exists replace it's list, otherwise create a new one
    existing_gushim[muni_name] = {'list': gush_ids}

    # write the dictionary back to lib/gushim.py
    out = open(os.path.join('lib', 'gushim.py'), 'w')
    out.write('GUSHIM = ' + dumps(existing_gushim, sort_keys=True, indent=4, separators=(',', ': ')))
    out.flush()
    os.fsync(out.fileno())
    out.close()

    # update the automated test to test for the new total number of gushim
    total = []
    for key in existing_gushim.keys():
        for g in existing_gushim[key]['list']:
            if g not in total:
                total.append(g)

    with open(os.path.join('Tests', 'functional_tests', 'test_return_json.py')) as test_data:
        test_code = test_data.read()
        gush_count_line_re = re.compile('(eq_\(len\(j\), )[0-9]+(\))')
        test_code = gush_count_line_re.sub('eq_(len(j), %s)' % len(total), test_code, count=1)

    out = open(os.path.join('Tests', 'functional_tests', 'test_return_json.py'), 'w')
    out.write(test_code)
    out.flush()
    os.fsync(out.fileno())
    out.close()

    # commit and push to origin
    local('git add %s' % os.path.join('lib', 'gushim.py'))
    local('git add %s' % os.path.join('Tests', 'functional_tests', 'test_return_json.py'))
    local('git commit -m "added gushim and updated tests for %s"' % muni_name)
    local('git push origin master')

    print '*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*'
    print 'The new/updated gushim data was added to lib/gushim.py and the test file '
    print 'Tests/functional_tests/test_return_json.py was updated.'
    print 'Both files were successfuly comitted and pushed to origin.'
    print '*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*'
コード例 #3
0
def update_gushim_server(muni_name):
    """Add the gush ids from an existing online gush map to the lib/gushim.py file"""
    
    # download the online gush map
    gush_map = _download_gush_map(muni_name)
    gush_ids = []
    
    # make a list of all gush ids in the file
    for geometry in gush_map['features']:
        gush_ids.append(geometry['properties']['Name'])
    
    # make sure we're using the master branch
    local('git checkout master')
    
    # open and load the existing gushim dictionary from lib/gushim.py
    with open(os.path.join('lib', 'gushim.py')) as gushim_data:
        existing_gushim = loads(gushim_data.read().replace('GUSHIM = ', ''))
    
    # if the municipality already exists replace it's list, otherwise create a new one
    existing_gushim[muni_name] = {'list': gush_ids}
    
    # write the dictionary back to lib/gushim.py
    out = open(os.path.join('lib', 'gushim.py'), 'w')
    out.write('GUSHIM = ' + dumps(existing_gushim, sort_keys=True, indent=4, separators=(',', ': ')))
    out.flush()
    os.fsync(out.fileno())
    out.close()
    
    # update the automated test to test for the new total number of gushim
    total = []
    for key in existing_gushim.keys():
        for g in existing_gushim[key]['list']:
            if g not in total:
                total.append(g)
    
    with open(os.path.join('Tests', 'functional_tests', 'test_return_json.py')) as test_data:
        test_code = test_data.read()
        gush_count_line_re = re.compile('(eq_\(len\(j\), )[0-9]+(\))')
        test_code = gush_count_line_re.sub('eq_(len(j), %s)' % len(total), test_code, count=1)
    
    out = open(os.path.join('Tests', 'functional_tests', 'test_return_json.py'), 'w')
    out.write(test_code)
    out.flush()
    os.fsync(out.fileno())
    out.close()
    
    # commit and push to origin
    local('git add %s' % os.path.join('lib', 'gushim.py'))
    local('git add %s' % os.path.join('Tests', 'functional_tests', 'test_return_json.py'))
    local('git commit -m "added gushim and updated tests for %s"' % muni_name)
    local('git push origin master')
    
    print '*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*'
    print 'The new/updated gushim data was added to lib/gushim.py and the test file '
    print 'Tests/functional_tests/test_return_json.py was updated.'
    print 'Both files were successfuly comitted and pushed to origin.'
    print '*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*'
コード例 #4
0
def create_client(muni_name, display_name=''):
    """Add an entry for a new municipality or update an existing one to the munis.js file with the required data"""

    with lcd(os.path.join('..', 'opentaba-client')):
        # download the online gush map
        geojson_gush_map = _download_gush_map(muni_name)

        # make sure we're using the master branch
        local('git checkout master')

        # load the current municipalities' index dictionary
        with open(os.path.join('..', 'opentaba-client',
                               'munis.js')) as index_data:
            original_index_json = loads(index_data.read().replace(
                'var municipalities = ', '').rstrip('\n').rstrip(';'))

        new_index_json = deepcopy(original_index_json)

        # add a new entry if needed
        if muni_name not in new_index_json.keys():
            if display_name == '':
                abort('For new municipalities display name must be provided')

            new_index_json[muni_name] = {'display': '', 'center': []}

        # update the display name and center of the municipality's entry
        new_index_json[muni_name]['display'] = display_name
        new_index_json[muni_name]['center'] = _get_muni_center(
            geojson_gush_map['features'])
        new_index_json[muni_name]['bounds'] = _get_muni_bounds(
            geojson_gush_map['features'])

        # don't try to add, commit etc. if no changes were made
        if dumps(new_index_json, sort_keys=True) == dumps(original_index_json,
                                                          sort_keys=True):
            warn(
                'No new data was found in the downloaded gush map. No changes were made to munis.js'
            )
        else:
            # write back the munis.js file
            out = open(os.path.join('..', 'opentaba-client', 'munis.js'), 'w')
            out.write('var municipalities = ' + dumps(new_index_json,
                                                      sort_keys=True,
                                                      indent=4,
                                                      separators=(',', ': ')) +
                      ';')
            out.flush()
            os.fsync(out.fileno())
            out.close()

            # commit and push to origin
            local('git add munis.js')
            local('git commit -m "added %s to munis.js"' % muni_name)
            local('git push origin master')

            # merge into gh-pages branch
            local('git checkout gh-pages')
            local('git merge master --no-edit')
            local('git push origin gh-pages')

            # back to master for work
            local('git checkout master')

            print '*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*'
            print 'The new/updated municipality data was added to munis.js, its topojson '
            print 'gushim map will be loaded from the israel_gushim repository, and changes were '
            print 'committed and pushed to origin. If more data needs to be in munis.js, you can '
            print 'do it now and push again. The municipality\'s site is now live at:'
            print 'http://%s.opentaba.info/' % muni_name
            print '*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*'