######
#  Create a file (html or markdown) with the output of
#      - JVMHeap
#      - LogFiles
#      - Ports
#      - Variables
#
#  Author:        Christoph Stoettner
#  Mail:          christoph.stoettner@stoeps.de
#  Documentation: http://scripting101.stoeps.de
#
#  Version:       2.0
#  Date:          2014-06-08
#
#  License:       Apache 2.0
#

# TODO: Create a menu for file selection

import ibmcnx.filehandle
import sys

emp1 = ibmcnx.filehandle.Ibmcnxfile()

sys.stdout = emp1

print '# JVM Settings of all AppServers:'
execfile( 'ibmcnx/doc/JVMSettings.py' )

print '# Used Ports:'
execfile( 'ibmcnx/doc/Ports.py' )

print '# LogFile Settgins:'
execfile( 'ibmcnx/doc/LogFiles.py' )

print '# WebSphere Variables'
execfile( 'ibmcnx/doc/Variables.py' )

Response:
<REPLACE_OLD> sys

sys.stdout <REPLACE_NEW> sys

emp1 <REPLACE_END> <REPLACE_OLD> open("/tmp/documentation.txt", "w")

print <REPLACE_NEW> ibmcnx.filehandle.Ibmcnxfile()

sys.stdout = emp1

print <REPLACE_END> <|endoftext|> ######
#  Create a file (html or markdown) with the output of
#      - JVMHeap
#      - LogFiles
#      - Ports
#      - Variables
#
#  Author:        Christoph Stoettner
#  Mail:          christoph.stoettner@stoeps.de
#  Documentation: http://scripting101.stoeps.de
#
#  Version:       2.0
#  Date:          2014-06-08
#
#  License:       Apache 2.0
#

# TODO: Create a menu for file selection

import ibmcnx.filehandle
import sys

emp1 = ibmcnx.filehandle.Ibmcnxfile()

sys.stdout = emp1

print '# JVM Settings of all AppServers:'
execfile( 'ibmcnx/doc/JVMSettings.py' )

print '# Used Ports:'
execfile( 'ibmcnx/doc/Ports.py' )

print '# LogFile Settgins:'
execfile( 'ibmcnx/doc/LogFiles.py' )

print '# WebSphere Variables'
execfile( 'ibmcnx/doc/Variables.py' )

Prompt:
4: Create script to save documentation to a file

Task-Url: http://github.com/stoeps13/ibmcnx2/issues/issue/4
######
#  Create a file (html or markdown) with the output of
#      - JVMHeap
#      - LogFiles
#      - Ports
#      - Variables
#
#  Author:        Christoph Stoettner
#  Mail:          christoph.stoettner@stoeps.de
#  Documentation: http://scripting101.stoeps.de
#
#  Version:       2.0
#  Date:          2014-06-08
#
#  License:       Apache 2.0
#

# TODO: Create a menu for file selection

import ibmcnx.filehandle
import sys

sys.stdout = open("/tmp/documentation.txt", "w")

print '# JVM Settings of all AppServers:'
execfile( 'ibmcnx/doc/JVMSettings.py' )

print '# Used Ports:'
execfile( 'ibmcnx/doc/Ports.py' )

print '# LogFile Settgins:'
execfile( 'ibmcnx/doc/LogFiles.py' )

print '# WebSphere Variables'
execfile( 'ibmcnx/doc/Variables.py' )


"""Decorators.

"""

from functools import wraps

from astropy import units as u

from poliastro.bodies import Body
from poliastro.twobody.rv import RVState

u.kms = u.km / u.s
u.km3s2 = u.km ** 3 / u.s ** 2

def state_from_vector(func):

    @wraps(func)
    def wrapper(t, u_, k, *args, **kwargs):
        r, v = u_[:3], u_[3:]
        ss = RVState(Body(k * u.km3s2), r * u.km, v * u.kms)

        return func(t, ss, *args, **kwargs)

    return wrapper

Response:
<DELETE> r, v, <DELETE_END> <|endoftext|> """Decorators.

"""

from functools import wraps

from astropy import units as u

from poliastro.bodies import Body
from poliastro.twobody.rv import RVState

u.kms = u.km / u.s
u.km3s2 = u.km ** 3 / u.s ** 2

def state_from_vector(func):

    @wraps(func)
    def wrapper(t, u_, k, *args, **kwargs):
        r, v = u_[:3], u_[3:]
        ss = RVState(Body(k * u.km3s2), r * u.km, v * u.kms)

        return func(t, ss, *args, **kwargs)

    return wrapper

Prompt:
Remove extra arguments from decorated function

"""Decorators.

"""

from functools import wraps

from astropy import units as u

from poliastro.bodies import Body
from poliastro.twobody.rv import RVState

u.kms = u.km / u.s
u.km3s2 = u.km ** 3 / u.s ** 2

def state_from_vector(func):

    @wraps(func)
    def wrapper(t, u_, k, *args, **kwargs):
        r, v = u_[:3], u_[3:]
        ss = RVState(Body(k * u.km3s2), r * u.km, v * u.kms)

        return func(t, ss, r, v, *args, **kwargs)

    return wrapper


import pandas as pd
import numpy as np
from xgboost.sklearn import XGBClassifier
from sklearn.preprocessing import LabelEncoder
from sklearn.cross_validation import cross_val_score
from sklearn.cross_validation import KFold
from sklearn.feature_selection import SelectFromModel

from utils.metrics import ndcg_scorer

path = '../data/processed/'
train_users = pd.read_csv(path + 'ohe_count_processed_train_users.csv')
y_train = train_users['country_destination']
train_users.drop('country_destination', axis=1, inplace=True)
train_users.drop('id', axis=1, inplace=True)
train_users = train_users.fillna(-1)
x_train = train_users.values
label_encoder = LabelEncoder()
encoded_y_train = label_encoder.fit_transform(y_train)

clf = XGBClassifier(n_estimators=1, nthread=-1, seed=42)
kf = KFold(len(x_train), n_folds=5, random_state=42)

score = cross_val_score(clf, x_train, encoded_y_train,
                        cv=kf, scoring=ndcg_scorer)
print 'Score:', score.mean()

class CustomXGB(XGBClassifier):

    @property
    def feature_importances_(self):
        """Return the feature importances (the higher, the more important the
           feature).
        Returns
        -------
        feature_importances_ : array, shape = [n_features]
        """
        booster = self.booster()
        scores = booster.get_fscore()
        all_scores = pd.Series(np.zeros(x_train.shape[1]))
        scores = pd.Series(scores)
        scores.index = scores.index.map(lambda x: x[1:]).astype(int)
        final_scores = all_scores + scores
        importances = final_scores.fillna(0).values
        return importances

custom = CustomXGB(n_estimators=1, seed=42, nthread=-1)
model = SelectFromModel(custom)
X_new = model.fit_transform(x_train, encoded_y_train)

score = cross_val_score(clf, X_new, encoded_y_train,
                        cv=kf, scoring=ndcg_scorer)
print 'Score:', score.mean()

Add structure to feature selection script

Response:
<REPLACE_OLD>  <REPLACE_NEW> import pandas as pd
import numpy as np
from xgboost.sklearn import XGBClassifier
from sklearn.preprocessing import LabelEncoder
from sklearn.cross_validation import cross_val_score
from sklearn.cross_validation import KFold
from sklearn.feature_selection import SelectFromModel

from utils.metrics import ndcg_scorer

path = '../data/processed/'
train_users = pd.read_csv(path + 'ohe_count_processed_train_users.csv')
y_train = train_users['country_destination']
train_users.drop('country_destination', axis=1, inplace=True)
train_users.drop('id', axis=1, inplace=True)
train_users = train_users.fillna(-1)
x_train = train_users.values
label_encoder = LabelEncoder()
encoded_y_train = label_encoder.fit_transform(y_train)

clf = XGBClassifier(n_estimators=1, nthread=-1, seed=42)
kf = KFold(len(x_train), n_folds=5, random_state=42)

score = cross_val_score(clf, x_train, encoded_y_train,
                        cv=kf, scoring=ndcg_scorer)
print 'Score:', score.mean()

class CustomXGB(XGBClassifier):

    @property
    def feature_importances_(self):
        """Return the feature importances (the higher, the more important the
           feature).
        Returns
        -------
        feature_importances_ : array, shape = [n_features]
        """
        booster = self.booster()
        scores = booster.get_fscore()
        all_scores = pd.Series(np.zeros(x_train.shape[1]))
        scores = pd.Series(scores)
        scores.index = scores.index.map(lambda x: x[1:]).astype(int)
        final_scores = all_scores + scores
        importances = final_scores.fillna(0).values
        return importances

custom = CustomXGB(n_estimators=1, seed=42, nthread=-1)
model = SelectFromModel(custom)
X_new = model.fit_transform(x_train, encoded_y_train)

score = cross_val_score(clf, X_new, encoded_y_train,
                        cv=kf, scoring=ndcg_scorer)
print 'Score:', score.mean()
 <REPLACE_END> <|endoftext|> import pandas as pd
import numpy as np
from xgboost.sklearn import XGBClassifier
from sklearn.preprocessing import LabelEncoder
from sklearn.cross_validation import cross_val_score
from sklearn.cross_validation import KFold
from sklearn.feature_selection import SelectFromModel

from utils.metrics import ndcg_scorer

path = '../data/processed/'
train_users = pd.read_csv(path + 'ohe_count_processed_train_users.csv')
y_train = train_users['country_destination']
train_users.drop('country_destination', axis=1, inplace=True)
train_users.drop('id', axis=1, inplace=True)
train_users = train_users.fillna(-1)
x_train = train_users.values
label_encoder = LabelEncoder()
encoded_y_train = label_encoder.fit_transform(y_train)

clf = XGBClassifier(n_estimators=1, nthread=-1, seed=42)
kf = KFold(len(x_train), n_folds=5, random_state=42)

score = cross_val_score(clf, x_train, encoded_y_train,
                        cv=kf, scoring=ndcg_scorer)
print 'Score:', score.mean()

class CustomXGB(XGBClassifier):

    @property
    def feature_importances_(self):
        """Return the feature importances (the higher, the more important the
           feature).
        Returns
        -------
        feature_importances_ : array, shape = [n_features]
        """
        booster = self.booster()
        scores = booster.get_fscore()
        all_scores = pd.Series(np.zeros(x_train.shape[1]))
        scores = pd.Series(scores)
        scores.index = scores.index.map(lambda x: x[1:]).astype(int)
        final_scores = all_scores + scores
        importances = final_scores.fillna(0).values
        return importances

custom = CustomXGB(n_estimators=1, seed=42, nthread=-1)
model = SelectFromModel(custom)
X_new = model.fit_transform(x_train, encoded_y_train)

score = cross_val_score(clf, X_new, encoded_y_train,
                        cv=kf, scoring=ndcg_scorer)
print 'Score:', score.mean()

Prompt: Add structure to feature selection script


# Script to plot original wav file against wav file resampled at 16 kHz

# Licensed under Apache v2 (see LICENSE)

from __future__ import division

import sys
import os
import glob
import numpy as np
import matplotlib.pyplot as plt

from numpy.random import randint
from scipy.signal import resample

# Problems doing this import
# May need to move this file to top level directory
from opensauce.helpers import wavread, round_half_away_from_zero

def main(wav_dir, fs_rs):
    """Compare original data vs resampled data for all wav files in wav_dir,
    where resampling frequency is given in Hz by fs_rs
    """
    # Find all .wav files in test/data directory
    wav_files = glob.glob(os.path.join(wav_dir, '*.wav'))

    for wav_file in wav_files:
        print('Processing wav file {}'.format(wav_file))
        # y is data points, fs is sampling frequency
        y, fs = wavread(wav_file)
        # ns is number of samples
        ns = len(y)
        period = 1.0 / fs
        # Time points corresponding to samples
        t = np.arange(0, ns*period, period)

        # Resample to 16 kHz
        period_rs = 1.0 / fs_rs
        # Number of points in resample
        ns_rs = round_half_away_from_zero(ns * fs_rs / fs)
        # Do resample
        y_rs, t_rs = resample(y, ns_rs, t)

        # Number of points to plot
        n = 1000
        # Start plotting from this data point
        s = randint(10000, 35015-n)
        plt.figure()
        plt.plot(t, y, 'b-', markersize=1)
        plt.plot(t_rs, y_rs, 'ro', markersize=3)
        plt.xlim(s*period, (s+n)*period)
        plt.title(os.path.basename(wav_file))
        plt.xlabel('Time (s)')
        plt.ylabel('Amplitude')
        plt.savefig(os.path.splitext(os.path.basename(wav_file))[0] + '.pdf')

if __name__ == '__main__':
    main(sys.argv[1], int(sys.argv[2]))

Add script to check resampling of wav files

Response:
<REPLACE_OLD>  <REPLACE_NEW> # Script to plot original wav file against wav file resampled at 16 kHz

# Licensed under Apache v2 (see LICENSE)

from __future__ import division

import sys
import os
import glob
import numpy as np
import matplotlib.pyplot as plt

from numpy.random import randint
from scipy.signal import resample

# Problems doing this import
# May need to move this file to top level directory
from opensauce.helpers import wavread, round_half_away_from_zero

def main(wav_dir, fs_rs):
    """Compare original data vs resampled data for all wav files in wav_dir,
    where resampling frequency is given in Hz by fs_rs
    """
    # Find all .wav files in test/data directory
    wav_files = glob.glob(os.path.join(wav_dir, '*.wav'))

    for wav_file in wav_files:
        print('Processing wav file {}'.format(wav_file))
        # y is data points, fs is sampling frequency
        y, fs = wavread(wav_file)
        # ns is number of samples
        ns = len(y)
        period = 1.0 / fs
        # Time points corresponding to samples
        t = np.arange(0, ns*period, period)

        # Resample to 16 kHz
        period_rs = 1.0 / fs_rs
        # Number of points in resample
        ns_rs = round_half_away_from_zero(ns * fs_rs / fs)
        # Do resample
        y_rs, t_rs = resample(y, ns_rs, t)

        # Number of points to plot
        n = 1000
        # Start plotting from this data point
        s = randint(10000, 35015-n)
        plt.figure()
        plt.plot(t, y, 'b-', markersize=1)
        plt.plot(t_rs, y_rs, 'ro', markersize=3)
        plt.xlim(s*period, (s+n)*period)
        plt.title(os.path.basename(wav_file))
        plt.xlabel('Time (s)')
        plt.ylabel('Amplitude')
        plt.savefig(os.path.splitext(os.path.basename(wav_file))[0] + '.pdf')

if __name__ == '__main__':
    main(sys.argv[1], int(sys.argv[2]))
 <REPLACE_END> <|endoftext|> # Script to plot original wav file against wav file resampled at 16 kHz

# Licensed under Apache v2 (see LICENSE)

from __future__ import division

import sys
import os
import glob
import numpy as np
import matplotlib.pyplot as plt

from numpy.random import randint
from scipy.signal import resample

# Problems doing this import
# May need to move this file to top level directory
from opensauce.helpers import wavread, round_half_away_from_zero

def main(wav_dir, fs_rs):
    """Compare original data vs resampled data for all wav files in wav_dir,
    where resampling frequency is given in Hz by fs_rs
    """
    # Find all .wav files in test/data directory
    wav_files = glob.glob(os.path.join(wav_dir, '*.wav'))

    for wav_file in wav_files:
        print('Processing wav file {}'.format(wav_file))
        # y is data points, fs is sampling frequency
        y, fs = wavread(wav_file)
        # ns is number of samples
        ns = len(y)
        period = 1.0 / fs
        # Time points corresponding to samples
        t = np.arange(0, ns*period, period)

        # Resample to 16 kHz
        period_rs = 1.0 / fs_rs
        # Number of points in resample
        ns_rs = round_half_away_from_zero(ns * fs_rs / fs)
        # Do resample
        y_rs, t_rs = resample(y, ns_rs, t)

        # Number of points to plot
        n = 1000
        # Start plotting from this data point
        s = randint(10000, 35015-n)
        plt.figure()
        plt.plot(t, y, 'b-', markersize=1)
        plt.plot(t_rs, y_rs, 'ro', markersize=3)
        plt.xlim(s*period, (s+n)*period)
        plt.title(os.path.basename(wav_file))
        plt.xlabel('Time (s)')
        plt.ylabel('Amplitude')
        plt.savefig(os.path.splitext(os.path.basename(wav_file))[0] + '.pdf')

if __name__ == '__main__':
    main(sys.argv[1], int(sys.argv[2]))

Prompt: Add script to check resampling of wav files


from txircd.channel import IRCChannel
from txircd.modbase import Module

class Autojoin(Module):
	def joinOnConnect(self, user):
		if "client_join_on_connect" in self.ircd.servconfig:
			for channel in self.ircd.servconfig["client_join_on_connect"]:
				user.join(self.ircd.channels[channel] if channel in self.ircd.channels else IRCChannel(self.ircd, channel))
		return True

class Spawner(object):
	def __init__(self, ircd):
		self.ircd = ircd
		self.conn_join = None

	def spawn(self):
		self.conn_join = Autojoin().hook(self.ircd)
		return {
			"actions": {
				"register": [self.conn_join.joinOnConnect]
			}
		}

	def cleanup(self):
		self.ircd.actions["register"].remove(self.conn_join.joinOnConnect)

Response:
<REPLACE_OLD> channel))

class <REPLACE_NEW> channel))
		return True

class <REPLACE_END> <REPLACE_OLD> self.conn_join.joinOnConnect
			}
		}

	def <REPLACE_NEW> [self.conn_join.joinOnConnect]
			}
		}

	def <REPLACE_END> <|endoftext|> from txircd.channel import IRCChannel
from txircd.modbase import Module

class Autojoin(Module):
	def joinOnConnect(self, user):
		if "client_join_on_connect" in self.ircd.servconfig:
			for channel in self.ircd.servconfig["client_join_on_connect"]:
				user.join(self.ircd.channels[channel] if channel in self.ircd.channels else IRCChannel(self.ircd, channel))
		return True

class Spawner(object):
	def __init__(self, ircd):
		self.ircd = ircd
		self.conn_join = None

	def spawn(self):
		self.conn_join = Autojoin().hook(self.ircd)
		return {
			"actions": {
				"register": [self.conn_join.joinOnConnect]
			}
		}

	def cleanup(self):
		self.ircd.actions["register"].remove(self.conn_join.joinOnConnect)

Prompt:
Fix once again nobody being allowed to connect

from txircd.channel import IRCChannel
from txircd.modbase import Module

class Autojoin(Module):
	def joinOnConnect(self, user):
		if "client_join_on_connect" in self.ircd.servconfig:
			for channel in self.ircd.servconfig["client_join_on_connect"]:
				user.join(self.ircd.channels[channel] if channel in self.ircd.channels else IRCChannel(self.ircd, channel))

class Spawner(object):
	def __init__(self, ircd):
		self.ircd = ircd
		self.conn_join = None

	def spawn(self):
		self.conn_join = Autojoin().hook(self.ircd)
		return {
			"actions": {
				"register": self.conn_join.joinOnConnect
			}
		}

	def cleanup(self):
		self.ircd.actions["register"].remove(self.conn_join.joinOnConnect)


import javascript.traverser as traverser
from javascript.spidermonkey import get_tree
from appvalidator.constants import SPIDERMONKEY_INSTALLATION
from ..contextgenerator import ContextGenerator

def test_js_file(err, filename, data, line=0, context=None):
    "Tests a JS file by parsing and analyzing its tokens"

    if (SPIDERMONKEY_INSTALLATION is None or
        err.get_resource("SPIDERMONKEY") is None):  # Default value is False
        return

    # Set the tier to 4 (Security Tests)
    if err is not None:
        before_tier = err.tier
        err.set_tier(3)

    tree = get_tree(data, err, filename,
                    err and err.get_resource("SPIDERMONKEY") or
                    SPIDERMONKEY_INSTALLATION)
    if not tree:
        err.metadata.ran_js_tests = "no;missing ast"
        if err is not None:
            err.set_tier(before_tier)
        return

    trav = traverser.Traverser(
        err, filename, line, context=context or ContextGenerator(data))
    trav.run(tree)

    err.metadata.ran_js_tests = "yes"

    # Reset the tier so we don't break the world
    if err is not None:
        err.set_tier(before_tier)

Response:
<INSERT> err.metadata.ran_js_tests = "no;missing ast"
        <INSERT_END> <INSERT>    err.metadata.ran_js_tests = "yes"

 <INSERT_END> <|endoftext|> import javascript.traverser as traverser
from javascript.spidermonkey import get_tree
from appvalidator.constants import SPIDERMONKEY_INSTALLATION
from ..contextgenerator import ContextGenerator

def test_js_file(err, filename, data, line=0, context=None):
    "Tests a JS file by parsing and analyzing its tokens"

    if (SPIDERMONKEY_INSTALLATION is None or
        err.get_resource("SPIDERMONKEY") is None):  # Default value is False
        return

    # Set the tier to 4 (Security Tests)
    if err is not None:
        before_tier = err.tier
        err.set_tier(3)

    tree = get_tree(data, err, filename,
                    err and err.get_resource("SPIDERMONKEY") or
                    SPIDERMONKEY_INSTALLATION)
    if not tree:
        err.metadata.ran_js_tests = "no;missing ast"
        if err is not None:
            err.set_tier(before_tier)
        return

    trav = traverser.Traverser(
        err, filename, line, context=context or ContextGenerator(data))
    trav.run(tree)

    err.metadata.ran_js_tests = "yes"

    # Reset the tier so we don't break the world
    if err is not None:
        err.set_tier(before_tier)

Prompt:
Add information about JS test status to metadata
import javascript.traverser as traverser
from javascript.spidermonkey import get_tree
from appvalidator.constants import SPIDERMONKEY_INSTALLATION
from ..contextgenerator import ContextGenerator

def test_js_file(err, filename, data, line=0, context=None):
    "Tests a JS file by parsing and analyzing its tokens"

    if (SPIDERMONKEY_INSTALLATION is None or
        err.get_resource("SPIDERMONKEY") is None):  # Default value is False
        return

    # Set the tier to 4 (Security Tests)
    if err is not None:
        before_tier = err.tier
        err.set_tier(3)

    tree = get_tree(data, err, filename,
                    err and err.get_resource("SPIDERMONKEY") or
                    SPIDERMONKEY_INSTALLATION)
    if not tree:
        if err is not None:
            err.set_tier(before_tier)
        return

    trav = traverser.Traverser(
        err, filename, line, context=context or ContextGenerator(data))
    trav.run(tree)

    # Reset the tier so we don't break the world
    if err is not None:
        err.set_tier(before_tier)


from nose.plugins.skip import SkipTest
from urllib3.packages import six

try:
    from urllib3.contrib.pyopenssl import (inject_into_urllib3,
                                           extract_from_urllib3)
except ImportError as e:
    raise SkipTest('Could not import PyOpenSSL: %r' % e)

from ..with_dummyserver.test_https import TestHTTPS, TestHTTPS_TLSv1
from ..with_dummyserver.test_socketlevel import TestSNI, TestSocketClosing

def setup_module():
    inject_into_urllib3()

def teardown_module():
    extract_from_urllib3()

Enable PyOpenSSL testing on Python 3.

Enable PyOpenSSL testing on Python 3.

Response:
<REPLACE_OLD> six

if six.PY3:
    raise SkipTest('Testing of PyOpenSSL disabled on PY3')

try:
 <REPLACE_NEW> six

try:
 <REPLACE_END> <|endoftext|> from nose.plugins.skip import SkipTest
from urllib3.packages import six

try:
    from urllib3.contrib.pyopenssl import (inject_into_urllib3,
                                           extract_from_urllib3)
except ImportError as e:
    raise SkipTest('Could not import PyOpenSSL: %r' % e)

from ..with_dummyserver.test_https import TestHTTPS, TestHTTPS_TLSv1
from ..with_dummyserver.test_socketlevel import TestSNI, TestSocketClosing

def setup_module():
    inject_into_urllib3()

def teardown_module():
    extract_from_urllib3()

Prompt:
Enable PyOpenSSL testing on Python 3.

from nose.plugins.skip import SkipTest
from urllib3.packages import six

if six.PY3:
    raise SkipTest('Testing of PyOpenSSL disabled on PY3')

try:
    from urllib3.contrib.pyopenssl import (inject_into_urllib3,
                                           extract_from_urllib3)
except ImportError as e:
    raise SkipTest('Could not import PyOpenSSL: %r' % e)

from ..with_dummyserver.test_https import TestHTTPS, TestHTTPS_TLSv1
from ..with_dummyserver.test_socketlevel import TestSNI, TestSocketClosing

def setup_module():
    inject_into_urllib3()

def teardown_module():
    extract_from_urllib3()


import os
from ij import IJ, ImagePlus
from ij.gui import GenericDialog

def run():
  srcDir = IJ.getDirectory("Input_directory")
  if not srcDir:
    return
  dstDir = IJ.getDirectory("Output_directory")
  if not dstDir:
    return
  gd = GenericDialog("Process Folder")
  gd.addStringField("File_extension", ".tif")
  gd.addStringField("File_name_contains", "")
  gd.addCheckbox("Keep directory structure when saving", True)
  gd.showDialog()
  if gd.wasCanceled():
    return
  ext = gd.getNextString()
  containString = gd.getNextString()
  keepDirectories = gd.getNextBoolean()
  for root, directories, filenames in os.walk(srcDir):
    for filename in filenames:
      # Check for file extension
      if not filename.endswith(ext):
        continue
      # Check for file name pattern
      if containString not in filename:
        continue
      process(srcDir, dstDir, root, filename, keepDirectories)

def process(srcDir, dstDir, currentDir, fileName, keepDirectories):
  print "Processing:"

  # Opening the image
  print "Open image file", fileName
  imp = IJ.openImage(os.path.join(currentDir, fileName))

  # Put your processing commands here!

  # Saving the image
  saveDir = currentDir.replace(srcDir, dstDir) if keepDirectories else dstDir
  if not os.path.exists(saveDir):
    os.makedirs(saveDir)
  print "Saving to", saveDir
  IJ.saveAs(imp, "Tiff", os.path.join(saveDir, fileName));
  imp.close()

run()

Add python template to process a folder of images

Response:
<REPLACE_OLD>  <REPLACE_NEW> import os
from ij import IJ, ImagePlus
from ij.gui import GenericDialog

def run():
  srcDir = IJ.getDirectory("Input_directory")
  if not srcDir:
    return
  dstDir = IJ.getDirectory("Output_directory")
  if not dstDir:
    return
  gd = GenericDialog("Process Folder")
  gd.addStringField("File_extension", ".tif")
  gd.addStringField("File_name_contains", "")
  gd.addCheckbox("Keep directory structure when saving", True)
  gd.showDialog()
  if gd.wasCanceled():
    return
  ext = gd.getNextString()
  containString = gd.getNextString()
  keepDirectories = gd.getNextBoolean()
  for root, directories, filenames in os.walk(srcDir):
    for filename in filenames:
      # Check for file extension
      if not filename.endswith(ext):
        continue
      # Check for file name pattern
      if containString not in filename:
        continue
      process(srcDir, dstDir, root, filename, keepDirectories)

def process(srcDir, dstDir, currentDir, fileName, keepDirectories):
  print "Processing:"

  # Opening the image
  print "Open image file", fileName
  imp = IJ.openImage(os.path.join(currentDir, fileName))

  # Put your processing commands here!

  # Saving the image
  saveDir = currentDir.replace(srcDir, dstDir) if keepDirectories else dstDir
  if not os.path.exists(saveDir):
    os.makedirs(saveDir)
  print "Saving to", saveDir
  IJ.saveAs(imp, "Tiff", os.path.join(saveDir, fileName));
  imp.close()

run()
 <REPLACE_END> <|endoftext|> import os
from ij import IJ, ImagePlus
from ij.gui import GenericDialog

def run():
  srcDir = IJ.getDirectory("Input_directory")
  if not srcDir:
    return
  dstDir = IJ.getDirectory("Output_directory")
  if not dstDir:
    return
  gd = GenericDialog("Process Folder")
  gd.addStringField("File_extension", ".tif")
  gd.addStringField("File_name_contains", "")
  gd.addCheckbox("Keep directory structure when saving", True)
  gd.showDialog()
  if gd.wasCanceled():
    return
  ext = gd.getNextString()
  containString = gd.getNextString()
  keepDirectories = gd.getNextBoolean()
  for root, directories, filenames in os.walk(srcDir):
    for filename in filenames:
      # Check for file extension
      if not filename.endswith(ext):
        continue
      # Check for file name pattern
      if containString not in filename:
        continue
      process(srcDir, dstDir, root, filename, keepDirectories)

def process(srcDir, dstDir, currentDir, fileName, keepDirectories):
  print "Processing:"

  # Opening the image
  print "Open image file", fileName
  imp = IJ.openImage(os.path.join(currentDir, fileName))

  # Put your processing commands here!

  # Saving the image
  saveDir = currentDir.replace(srcDir, dstDir) if keepDirectories else dstDir
  if not os.path.exists(saveDir):
    os.makedirs(saveDir)
  print "Saving to", saveDir
  IJ.saveAs(imp, "Tiff", os.path.join(saveDir, fileName));
  imp.close()

run()

Prompt: Add python template to process a folder of images


class Base1:
    def __init__(self, *args):
        print("Base1.__init__", args)

class Ctuple1(Base1, tuple):
    pass

a = Ctuple1()
print(len(a))
a = Ctuple1([1, 2, 3])
print(len(a))

print("---")

class Ctuple2(tuple, Base1):
    pass

a = Ctuple2()
print(len(a))
a = Ctuple2([1, 2, 3])
print(len(a))

a = tuple([1,2,3])
b = Ctuple1([1,2,3])
c = Ctuple2([1,2,3])

print(a == b)
print(b == c)
print(c == a)

Response:
<REPLACE_OLD> 3])
print(len(a))
 <REPLACE_NEW> 3])
print(len(a))

a = tuple([1,2,3])
b = Ctuple1([1,2,3])
c = Ctuple2([1,2,3])

print(a == b)
print(b == c)
print(c == a)
 <REPLACE_END> <|endoftext|> class Base1:
    def __init__(self, *args):
        print("Base1.__init__", args)

class Ctuple1(Base1, tuple):
    pass

a = Ctuple1()
print(len(a))
a = Ctuple1([1, 2, 3])
print(len(a))

print("---")

class Ctuple2(tuple, Base1):
    pass

a = Ctuple2()
print(len(a))
a = Ctuple2([1, 2, 3])
print(len(a))

a = tuple([1,2,3])
b = Ctuple1([1,2,3])
c = Ctuple2([1,2,3])

print(a == b)
print(b == c)
print(c == a)

Prompt:
tests/basics: Expand test cases for equality of subclasses.

class Base1:
    def __init__(self, *args):
        print("Base1.__init__", args)

class Ctuple1(Base1, tuple):
    pass

a = Ctuple1()
print(len(a))
a = Ctuple1([1, 2, 3])
print(len(a))

print("---")

class Ctuple2(tuple, Base1):
    pass

a = Ctuple2()
print(len(a))
a = Ctuple2([1, 2, 3])
print(len(a))


import subprocess
import logging
import os

def fix_env_in_case_of_invalid_locale_name(env):
    """See https://github.com/ros-drivers/hokuyo_node/issues/3"""
    env["LC_ALL"] = "C"

def run(command, cwd=None):
    env = os.environ.copy()
    fix_env_in_case_of_invalid_locale_name(env)
    try:
        return subprocess.check_output(command, cwd=cwd, stderr=subprocess.STDOUT, stdin=open("/dev/null"),
                                       close_fds=True, env=env)
    except subprocess.CalledProcessError as e:
        logging.error("Failed command '%s' output:\n%s" % (command, e.output))
        raise

Response:
<REPLACE_OLD> logging

def <REPLACE_NEW> logging
import os

def fix_env_in_case_of_invalid_locale_name(env):
    """See https://github.com/ros-drivers/hokuyo_node/issues/3"""
    env["LC_ALL"] = "C"

def <REPLACE_END> <INSERT>    env = os.environ.copy()
    fix_env_in_case_of_invalid_locale_name(env)
 <INSERT_END> <REPLACE_OLD> subprocess.check_output(
 <REPLACE_NEW> subprocess.check_output(command, cwd=cwd, stderr=subprocess.STDOUT, stdin=open("/dev/null"),
 <REPLACE_END> <DELETE> command, cwd=cwd, stderr=subprocess.STDOUT,
 <DELETE_END> <REPLACE_OLD> stdin=open("/dev/null"), close_fds=True)
 <REPLACE_NEW>                 close_fds=True, env=env)
 <REPLACE_END> <|endoftext|> import subprocess
import logging
import os

def fix_env_in_case_of_invalid_locale_name(env):
    """See https://github.com/ros-drivers/hokuyo_node/issues/3"""
    env["LC_ALL"] = "C"

def run(command, cwd=None):
    env = os.environ.copy()
    fix_env_in_case_of_invalid_locale_name(env)
    try:
        return subprocess.check_output(command, cwd=cwd, stderr=subprocess.STDOUT, stdin=open("/dev/null"),
                                       close_fds=True, env=env)
    except subprocess.CalledProcessError as e:
        logging.error("Failed command '%s' output:\n%s" % (command, e.output))
        raise

Prompt:
Fix env var for osmosis when locale name is invalid

See https://github.com/ros-drivers/hokuyo_node/issues/3

import subprocess
import logging

def run(command, cwd=None):
    try:
        return subprocess.check_output(
            command, cwd=cwd, stderr=subprocess.STDOUT,
            stdin=open("/dev/null"), close_fds=True)
    except subprocess.CalledProcessError as e:
        logging.error("Failed command '%s' output:\n%s" % (command, e.output))
        raise


from werkzeug.wrappers import Request

from lexington.util.di import depends_on

@depends_on(['environ'])
def get_request(environ):
    return Request(environ)

@depends_on(['request'])
def get_method(request):
    return request.method

@depends_on(['request'])
def get_path(request):
    return request.path

@depends_on(['request'])
def get_query_string(request):
    return request.query_string

@depends_on(['request'])
def get_query(request):
    return request.args

def register_all(dependencies):
    dependant_functions = {
        'request': get_request,
        'method': get_method,
        'path': get_path,
        'query_string': get_query_string,
        'query': get_query,
    }
    for name, dependant in dependant_functions.items():
        dependencies.register_dependant(name, dependant)

Reduce direct dependencies on environ

Reduce direct dependencies on environ

Response:
<DELETE> urllib import parse
from <DELETE_END> <REPLACE_OLD> Request(environ)

# TODO: clean up all of these...
@depends_on(['environ'])
def get_method(environ):
 <REPLACE_NEW> Request(environ)

@depends_on(['request'])
def get_method(request):
 <REPLACE_END> <REPLACE_OLD> environ['REQUEST_METHOD']

@depends_on(['environ'])
def get_path(environ):
 <REPLACE_NEW> request.method

@depends_on(['request'])
def get_path(request):
 <REPLACE_END> <REPLACE_OLD> environ['PATH_INFO']

@depends_on(['environ'])
def get_query_string(environ):
 <REPLACE_NEW> request.path

@depends_on(['request'])
def get_query_string(request):
 <REPLACE_END> <REPLACE_OLD> environ['QUERY_STRING']

@depends_on(['query_string'])
def get_query(query_string):
 <REPLACE_NEW> request.query_string

@depends_on(['request'])
def get_query(request):
 <REPLACE_END> <REPLACE_OLD> parse.parse_qs(query_string)

def <REPLACE_NEW> request.args

def <REPLACE_END> <|endoftext|> from werkzeug.wrappers import Request

from lexington.util.di import depends_on

@depends_on(['environ'])
def get_request(environ):
    return Request(environ)

@depends_on(['request'])
def get_method(request):
    return request.method

@depends_on(['request'])
def get_path(request):
    return request.path

@depends_on(['request'])
def get_query_string(request):
    return request.query_string

@depends_on(['request'])
def get_query(request):
    return request.args

def register_all(dependencies):
    dependant_functions = {
        'request': get_request,
        'method': get_method,
        'path': get_path,
        'query_string': get_query_string,
        'query': get_query,
    }
    for name, dependant in dependant_functions.items():
        dependencies.register_dependant(name, dependant)

Prompt:
Reduce direct dependencies on environ

from urllib import parse
from werkzeug.wrappers import Request

from lexington.util.di import depends_on

@depends_on(['environ'])
def get_request(environ):
    return Request(environ)

# TODO: clean up all of these...
@depends_on(['environ'])
def get_method(environ):
    return environ['REQUEST_METHOD']

@depends_on(['environ'])
def get_path(environ):
    return environ['PATH_INFO']

@depends_on(['environ'])
def get_query_string(environ):
    return environ['QUERY_STRING']

@depends_on(['query_string'])
def get_query(query_string):
    return parse.parse_qs(query_string)

def register_all(dependencies):
    dependant_functions = {
        'request': get_request,
        'method': get_method,
        'path': get_path,
        'query_string': get_query_string,
        'query': get_query,
    }
    for name, dependant in dependant_functions.items():
        dependencies.register_dependant(name, dependant)


#!/usr/bin/env python

'''
Run pylint on a Jinja 2 template.
'''

import jinja2, os, subprocess, sys, tempfile

# Clagged pieces from the runner.
START_BLOCK = '/*-'
END_BLOCK = '-*/'
START_VARIABLE = '/*?'
END_VARIABLE = '?*/'
START_COMMENT = '/*#'
END_COMMENT = '#*/'

def main(argv, out, err):
    if len(argv) < 2 or argv[1] in ['--help', '-?']:
        print >>err, 'usage: %s file pylint_args...' % argv[0]
        return -1

    if not os.path.exists(argv[1]):
        print >>err, '%s not found' % argv[1]
        return -1

    root, template = os.path.split(os.path.abspath(argv[1]))

    # Construct a Jinja environment that matches that of the runner.
    env = jinja2.Environment(
        loader=jinja2.FileSystemLoader(root),
        extensions=["jinja2.ext.do", "jinja2.ext.loopcontrols"],
        block_start_string=START_BLOCK,
        block_end_string=END_BLOCK,
        variable_start_string=START_VARIABLE,
        variable_end_string=END_VARIABLE,
        comment_start_string=START_COMMENT,
        comment_end_string=END_COMMENT)

    # Compile the template requested to a temporary directory.
    tmp = tempfile.mkdtemp()
    print >>out, 'compiling to %s...' % tmp
    env.compile_templates(tmp, filter_func=lambda x: x == template, zip=None,
        ignore_errors=False)

    # Find it and run pylint on it.
    py = os.path.join(tmp, os.listdir(tmp)[0])
    print 'running pylint on %s...' % py
    return subprocess.call(['pylint', py] + argv[2:])

if __name__ == '__main__':
    sys.exit(main(sys.argv, sys.stdout, sys.stderr))

Add a tool for running pylint on Jinja templates.

Closes JIRA CAMKES-315

Response:
<REPLACE_OLD>  <REPLACE_NEW> #!/usr/bin/env python

'''
Run pylint on a Jinja 2 template.
'''

import jinja2, os, subprocess, sys, tempfile

# Clagged pieces from the runner.
START_BLOCK = '/*-'
END_BLOCK = '-*/'
START_VARIABLE = '/*?'
END_VARIABLE = '?*/'
START_COMMENT = '/*#'
END_COMMENT = '#*/'

def main(argv, out, err):
    if len(argv) < 2 or argv[1] in ['--help', '-?']:
        print >>err, 'usage: %s file pylint_args...' % argv[0]
        return -1

    if not os.path.exists(argv[1]):
        print >>err, '%s not found' % argv[1]
        return -1

    root, template = os.path.split(os.path.abspath(argv[1]))

    # Construct a Jinja environment that matches that of the runner.
    env = jinja2.Environment(
        loader=jinja2.FileSystemLoader(root),
        extensions=["jinja2.ext.do", "jinja2.ext.loopcontrols"],
        block_start_string=START_BLOCK,
        block_end_string=END_BLOCK,
        variable_start_string=START_VARIABLE,
        variable_end_string=END_VARIABLE,
        comment_start_string=START_COMMENT,
        comment_end_string=END_COMMENT)

    # Compile the template requested to a temporary directory.
    tmp = tempfile.mkdtemp()
    print >>out, 'compiling to %s...' % tmp
    env.compile_templates(tmp, filter_func=lambda x: x == template, zip=None,
        ignore_errors=False)

    # Find it and run pylint on it.
    py = os.path.join(tmp, os.listdir(tmp)[0])
    print 'running pylint on %s...' % py
    return subprocess.call(['pylint', py] + argv[2:])

if __name__ == '__main__':
    sys.exit(main(sys.argv, sys.stdout, sys.stderr))
 <REPLACE_END> <|endoftext|> #!/usr/bin/env python

'''
Run pylint on a Jinja 2 template.
'''

import jinja2, os, subprocess, sys, tempfile

# Clagged pieces from the runner.
START_BLOCK = '/*-'
END_BLOCK = '-*/'
START_VARIABLE = '/*?'
END_VARIABLE = '?*/'
START_COMMENT = '/*#'
END_COMMENT = '#*/'

def main(argv, out, err):
    if len(argv) < 2 or argv[1] in ['--help', '-?']:
        print >>err, 'usage: %s file pylint_args...' % argv[0]
        return -1

    if not os.path.exists(argv[1]):
        print >>err, '%s not found' % argv[1]
        return -1

    root, template = os.path.split(os.path.abspath(argv[1]))

    # Construct a Jinja environment that matches that of the runner.
    env = jinja2.Environment(
        loader=jinja2.FileSystemLoader(root),
        extensions=["jinja2.ext.do", "jinja2.ext.loopcontrols"],
        block_start_string=START_BLOCK,
        block_end_string=END_BLOCK,
        variable_start_string=START_VARIABLE,
        variable_end_string=END_VARIABLE,
        comment_start_string=START_COMMENT,
        comment_end_string=END_COMMENT)

    # Compile the template requested to a temporary directory.
    tmp = tempfile.mkdtemp()
    print >>out, 'compiling to %s...' % tmp
    env.compile_templates(tmp, filter_func=lambda x: x == template, zip=None,
        ignore_errors=False)

    # Find it and run pylint on it.
    py = os.path.join(tmp, os.listdir(tmp)[0])
    print 'running pylint on %s...' % py
    return subprocess.call(['pylint', py] + argv[2:])

if __name__ == '__main__':
    sys.exit(main(sys.argv, sys.stdout, sys.stderr))

Prompt:
Add a tool for running pylint on Jinja templates.

Closes JIRA CAMKES-315


import pytest

from ceph_deploy.cli import get_parser

class TestParserRGW(object):

    def setup(self):
        self.parser = get_parser()

    def test_rgw_help(self, capsys):
        with pytest.raises(SystemExit):
            self.parser.parse_args('rgw --help'.split())
        out, err = capsys.readouterr()
        assert 'usage: ceph-deploy rgw' in out
        assert 'positional arguments:' in out
        assert 'optional arguments:' in out

    @pytest.mark.skipif(reason="http://tracker.ceph.com/issues/12150")
    def test_rgw_create_host_required(self, capsys):
        with pytest.raises(SystemExit):
            self.parser.parse_args('rgw create'.split())
        out, err = capsys.readouterr()
        assert "error: too few arguments" in err

    def test_rgw_create_one_host(self):
        args = self.parser.parse_args('rgw create host1'.split())
        assert args.rgw[0][0] == 'host1'

    def test_rgw_create_multiple_hosts(self):
        hostnames = ['host1', 'host2', 'host3']
        args = self.parser.parse_args(['rgw', 'create'] + hostnames)
        # args.rgw is a list of tuples, and tuple[0] is the hostname
        hosts = [x[0] for x in args.rgw]
        assert frozenset(hosts) == frozenset(hostnames)

Add argparse tests for rgw module

[RM-11742] Add argparse tests for rgw module

Signed-off-by: Travis Rhoden <e5e44d6dbac12e32e01c3bb8b67940d8b42e225b@redhat.com>

Response:
<REPLACE_OLD>  <REPLACE_NEW> import pytest

from ceph_deploy.cli import get_parser

class TestParserRGW(object):

    def setup(self):
        self.parser = get_parser()

    def test_rgw_help(self, capsys):
        with pytest.raises(SystemExit):
            self.parser.parse_args('rgw --help'.split())
        out, err = capsys.readouterr()
        assert 'usage: ceph-deploy rgw' in out
        assert 'positional arguments:' in out
        assert 'optional arguments:' in out

    @pytest.mark.skipif(reason="http://tracker.ceph.com/issues/12150")
    def test_rgw_create_host_required(self, capsys):
        with pytest.raises(SystemExit):
            self.parser.parse_args('rgw create'.split())
        out, err = capsys.readouterr()
        assert "error: too few arguments" in err

    def test_rgw_create_one_host(self):
        args = self.parser.parse_args('rgw create host1'.split())
        assert args.rgw[0][0] == 'host1'

    def test_rgw_create_multiple_hosts(self):
        hostnames = ['host1', 'host2', 'host3']
        args = self.parser.parse_args(['rgw', 'create'] + hostnames)
        # args.rgw is a list of tuples, and tuple[0] is the hostname
        hosts = [x[0] for x in args.rgw]
        assert frozenset(hosts) == frozenset(hostnames)
 <REPLACE_END> <|endoftext|> import pytest

from ceph_deploy.cli import get_parser

class TestParserRGW(object):

    def setup(self):
        self.parser = get_parser()

    def test_rgw_help(self, capsys):
        with pytest.raises(SystemExit):
            self.parser.parse_args('rgw --help'.split())
        out, err = capsys.readouterr()
        assert 'usage: ceph-deploy rgw' in out
        assert 'positional arguments:' in out
        assert 'optional arguments:' in out

    @pytest.mark.skipif(reason="http://tracker.ceph.com/issues/12150")
    def test_rgw_create_host_required(self, capsys):
        with pytest.raises(SystemExit):
            self.parser.parse_args('rgw create'.split())
        out, err = capsys.readouterr()
        assert "error: too few arguments" in err

    def test_rgw_create_one_host(self):
        args = self.parser.parse_args('rgw create host1'.split())
        assert args.rgw[0][0] == 'host1'

    def test_rgw_create_multiple_hosts(self):
        hostnames = ['host1', 'host2', 'host3']
        args = self.parser.parse_args(['rgw', 'create'] + hostnames)
        # args.rgw is a list of tuples, and tuple[0] is the hostname
        hosts = [x[0] for x in args.rgw]
        assert frozenset(hosts) == frozenset(hostnames)

Prompt:
[RM-11742] Add argparse tests for rgw module

Signed-off-by: Travis Rhoden <e5e44d6dbac12e32e01c3bb8b67940d8b42e225b@redhat.com>


"""empty message

Revision ID: df33f3613823
Revises: 15741cc426db
Create Date: 2017-07-14 11:37:46.347709

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'df33f3613823'
down_revision = '15741cc426db'
branch_labels = None
depends_on = None

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('patients', sa.Column('age', sa.Integer(), nullable=True))
    op.add_column('patients', sa.Column('age_unit', sa.String(length=1), nullable=True))
    op.add_column('patients', sa.Column('birth_date', sa.Date(), nullable=True))
    op.add_column('patients', sa.Column('gender', sa.String(length=1), nullable=True))
    op.add_column('users', sa.Column('password_hash', sa.String(length=128), nullable=True))
    # ### end Alembic commands ###

def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'password_hash')
    op.drop_column('patients', 'gender')
    op.drop_column('patients', 'birth_date')
    op.drop_column('patients', 'age_unit')
    op.drop_column('patients', 'age')
    # ### end Alembic commands ###

Add migration for patient model

:rocket: Add migration for patient model

Response:
<INSERT> """empty message

Revision ID: df33f3613823
Revises: 15741cc426db
Create Date: 2017-07-14 11:37:46.347709

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'df33f3613823'
down_revision = '15741cc426db'
branch_labels = None
depends_on = None

def upgrade():
 <INSERT_END> <INSERT>   # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('patients', sa.Column('age', sa.Integer(), nullable=True))
    op.add_column('patients', sa.Column('age_unit', sa.String(length=1), nullable=True))
    op.add_column('patients', sa.Column('birth_date', sa.Date(), nullable=True))
    op.add_column('patients', sa.Column('gender', sa.String(length=1), nullable=True))
    op.add_column('users', sa.Column('password_hash', sa.String(length=128), nullable=True))
    # ### end Alembic commands ###

def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'password_hash')
    op.drop_column('patients', 'gender')
    op.drop_column('patients', 'birth_date')
    op.drop_column('patients', 'age_unit')
    op.drop_column('patients', 'age')
    # ### end Alembic commands ###
 <INSERT_END> <|endoftext|> """empty message

Revision ID: df33f3613823
Revises: 15741cc426db
Create Date: 2017-07-14 11:37:46.347709

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'df33f3613823'
down_revision = '15741cc426db'
branch_labels = None
depends_on = None

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('patients', sa.Column('age', sa.Integer(), nullable=True))
    op.add_column('patients', sa.Column('age_unit', sa.String(length=1), nullable=True))
    op.add_column('patients', sa.Column('birth_date', sa.Date(), nullable=True))
    op.add_column('patients', sa.Column('gender', sa.String(length=1), nullable=True))
    op.add_column('users', sa.Column('password_hash', sa.String(length=128), nullable=True))
    # ### end Alembic commands ###

def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'password_hash')
    op.drop_column('patients', 'gender')
    op.drop_column('patients', 'birth_date')
    op.drop_column('patients', 'age_unit')
    op.drop_column('patients', 'age')
    # ### end Alembic commands ###

Prompt: :rocket: Add migration for patient model


""" rhcephcompose CLI """

from argparse import ArgumentParser
import kobo.conf
from rhcephcompose.compose import Compose

class RHCephCompose(object):
    """ Main class for rhcephcompose CLI. """

    def __init__(self):

        parser = ArgumentParser(description='Generate a compose for RHCS.')
        parser.add_argument('config_file', metavar='config',
                            help='main configuration file for this release.')
        parser.add_argument('--insecure', action='store_const', const=True,
                            default=False, help='skip SSL verification')
        args = parser.parse_args()

        conf = kobo.conf.PyConfigParser()
        conf.load_from_file(args.config_file)
        if args.insecure:
            conf['chacra_ssl_verify'] = False
            import requests
            from requests.packages.urllib3.exceptions\
                import InsecureRequestWarning
            requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

        compose = Compose(conf)
        compose.run()

Response:
<INSERT> parser.add_argument('--insecure', action='store_const', const=True,
                            default=False, help='skip SSL verification')
        <INSERT_END> <REPLACE_OLD> conf.load_from_file(args.config_file)

 <REPLACE_NEW> conf.load_from_file(args.config_file)
        if args.insecure:
            conf['chacra_ssl_verify'] = False
            import requests
            from requests.packages.urllib3.exceptions\
                import InsecureRequestWarning
            requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

 <REPLACE_END> <|endoftext|> """ rhcephcompose CLI """

from argparse import ArgumentParser
import kobo.conf
from rhcephcompose.compose import Compose

class RHCephCompose(object):
    """ Main class for rhcephcompose CLI. """

    def __init__(self):

        parser = ArgumentParser(description='Generate a compose for RHCS.')
        parser.add_argument('config_file', metavar='config',
                            help='main configuration file for this release.')
        parser.add_argument('--insecure', action='store_const', const=True,
                            default=False, help='skip SSL verification')
        args = parser.parse_args()

        conf = kobo.conf.PyConfigParser()
        conf.load_from_file(args.config_file)
        if args.insecure:
            conf['chacra_ssl_verify'] = False
            import requests
            from requests.packages.urllib3.exceptions\
                import InsecureRequestWarning
            requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

        compose = Compose(conf)
        compose.run()

Prompt:
Add --insecure option to command line to disable SSL certificate verification when communicating with chacra

""" rhcephcompose CLI """

from argparse import ArgumentParser
import kobo.conf
from rhcephcompose.compose import Compose

class RHCephCompose(object):
    """ Main class for rhcephcompose CLI. """

    def __init__(self):

        parser = ArgumentParser(description='Generate a compose for RHCS.')
        parser.add_argument('config_file', metavar='config',
                            help='main configuration file for this release.')
        args = parser.parse_args()

        conf = kobo.conf.PyConfigParser()
        conf.load_from_file(args.config_file)

        compose = Compose(conf)
        compose.run()


"""Prints out submitted plugins that we don't already know about.

Also deletes any empty submissions.
"""

import json
import re

import rethinkdb as r

import db.github_repos
import db.util

r_conn = db.util.r_conn

_GITHUB_LINK_REGEX = re.compile(r'github.com/(.*?)/([^/?#]*)')

def delete_empty_submissions():
    """Delete submitted plugins that don't have enough info for us to act on.

    Since we have no form validation, many submissions are just people who
    click the "submit" button.
    """
    deleted = r.table('submitted_plugins').filter({
        'name': '',
        'author': '',
        'github-link': '',
        'vimorg-link': '',
    }).delete().run(r_conn())

    print 'Deleted empty submissions:'
    print deleted

def main():
    delete_empty_submissions()

    known_vimorg_plugins = []
    known_github_plugins = []
    new_plugins = []
    unparseable_plugins = []

    submissions = r.table('submitted_plugins').run(r_conn())
    for submission in submissions:
        if submission['vimorg-link']:
            known_vimorg_plugins.append(submission)
            continue

        github_link = submission['github-link']
        if github_link:
            matches = _GITHUB_LINK_REGEX.findall(github_link)
            if not matches:
                unparseable_plugins.append(submission)
                continue

            repo_owner, repo_name = matches[0]
            db_repo = db.github_repos.PluginGithubRepos.get_with_owner_repo(
                    repo_owner, repo_name)

            if db_repo:
                known_github_plugins.append(submission)
            else:
                new_plugins.append(submission)

    print
    print '%s submissions are known vim.org plugins' % len(
            known_vimorg_plugins)
    print '%s submissions are known github.com plugins' % len(
            known_github_plugins)

    print
    print '%s submissions have unparseable github.com links:' % len(
            unparseable_plugins)
    for submission in unparseable_plugins:
        print submission

    print
    print '%s submissions are new plugins:' % len(new_plugins)
    for submission in new_plugins:
        print json.dumps(submission, indent=2)

if __name__ == '__main__':
    main()

Add a script to easily view new submitted plugins

Summary: That is, submitted plugins that we don't already know about and are non-empty.

Test Plan:
- imported the `submitted_plugins` table from prod
- ran `PYTHONPATH=. python tools/clean_submitted_plugins.py`
- saw the output looked reasonable

Reviewers: xymostech, spicyj

Reviewed By: spicyj

Differential Revision: http://phabricator.benalpert.com/D213

Response:
<REPLACE_OLD>  <REPLACE_NEW> """Prints out submitted plugins that we don't already know about.

Also deletes any empty submissions.
"""

import json
import re

import rethinkdb as r

import db.github_repos
import db.util

r_conn = db.util.r_conn

_GITHUB_LINK_REGEX = re.compile(r'github.com/(.*?)/([^/?#]*)')

def delete_empty_submissions():
    """Delete submitted plugins that don't have enough info for us to act on.

    Since we have no form validation, many submissions are just people who
    click the "submit" button.
    """
    deleted = r.table('submitted_plugins').filter({
        'name': '',
        'author': '',
        'github-link': '',
        'vimorg-link': '',
    }).delete().run(r_conn())

    print 'Deleted empty submissions:'
    print deleted

def main():
    delete_empty_submissions()

    known_vimorg_plugins = []
    known_github_plugins = []
    new_plugins = []
    unparseable_plugins = []

    submissions = r.table('submitted_plugins').run(r_conn())
    for submission in submissions:
        if submission['vimorg-link']:
            known_vimorg_plugins.append(submission)
            continue

        github_link = submission['github-link']
        if github_link:
            matches = _GITHUB_LINK_REGEX.findall(github_link)
            if not matches:
                unparseable_plugins.append(submission)
                continue

            repo_owner, repo_name = matches[0]
            db_repo = db.github_repos.PluginGithubRepos.get_with_owner_repo(
                    repo_owner, repo_name)

            if db_repo:
                known_github_plugins.append(submission)
            else:
                new_plugins.append(submission)

    print
    print '%s submissions are known vim.org plugins' % len(
            known_vimorg_plugins)
    print '%s submissions are known github.com plugins' % len(
            known_github_plugins)

    print
    print '%s submissions have unparseable github.com links:' % len(
            unparseable_plugins)
    for submission in unparseable_plugins:
        print submission

    print
    print '%s submissions are new plugins:' % len(new_plugins)
    for submission in new_plugins:
        print json.dumps(submission, indent=2)

if __name__ == '__main__':
    main()
 <REPLACE_END> <|endoftext|> """Prints out submitted plugins that we don't already know about.

Also deletes any empty submissions.
"""

import json
import re

import rethinkdb as r

import db.github_repos
import db.util

r_conn = db.util.r_conn

_GITHUB_LINK_REGEX = re.compile(r'github.com/(.*?)/([^/?#]*)')

def delete_empty_submissions():
    """Delete submitted plugins that don't have enough info for us to act on.

    Since we have no form validation, many submissions are just people who
    click the "submit" button.
    """
    deleted = r.table('submitted_plugins').filter({
        'name': '',
        'author': '',
        'github-link': '',
        'vimorg-link': '',
    }).delete().run(r_conn())

    print 'Deleted empty submissions:'
    print deleted

def main():
    delete_empty_submissions()

    known_vimorg_plugins = []
    known_github_plugins = []
    new_plugins = []
    unparseable_plugins = []

    submissions = r.table('submitted_plugins').run(r_conn())
    for submission in submissions:
        if submission['vimorg-link']:
            known_vimorg_plugins.append(submission)
            continue

        github_link = submission['github-link']
        if github_link:
            matches = _GITHUB_LINK_REGEX.findall(github_link)
            if not matches:
                unparseable_plugins.append(submission)
                continue

            repo_owner, repo_name = matches[0]
            db_repo = db.github_repos.PluginGithubRepos.get_with_owner_repo(
                    repo_owner, repo_name)

            if db_repo:
                known_github_plugins.append(submission)
            else:
                new_plugins.append(submission)

    print
    print '%s submissions are known vim.org plugins' % len(
            known_vimorg_plugins)
    print '%s submissions are known github.com plugins' % len(
            known_github_plugins)

    print
    print '%s submissions have unparseable github.com links:' % len(
            unparseable_plugins)
    for submission in unparseable_plugins:
        print submission

    print
    print '%s submissions are new plugins:' % len(new_plugins)
    for submission in new_plugins:
        print json.dumps(submission, indent=2)

if __name__ == '__main__':
    main()

Prompt:
Add a script to easily view new submitted plugins

Summary: That is, submitted plugins that we don't already know about and are non-empty.

Test Plan:
- imported the `submitted_plugins` table from prod
- ran `PYTHONPATH=. python tools/clean_submitted_plugins.py`
- saw the output looked reasonable

Reviewers: xymostech, spicyj

Reviewed By: spicyj

Differential Revision: http://phabricator.benalpert.com/D213


import pytest

from django.test import TestCase
from django.core.urlresolvers import reverse

from molo.core.tests.base import MoloTestCaseMixin

@pytest.mark.django_db
class TestImportFromGit(TestCase, MoloTestCaseMixin):

    def setUp(self):
        self.mk_main()
        self.user = self.login()

    def test_wagtail_has_import_menu_item(self):
        response = self.client.get(reverse('import-from-git'))
        self.assertContains(
            response, 'Import content from a Universal Core site')

Fix import UI django view's tests

Fix import UI django view's tests

Response:
<REPLACE_OLD> self.client.get(reverse("import-from-git"))
 <REPLACE_NEW> self.client.get(reverse('import-from-git'))
 <REPLACE_END> <REPLACE_OLD> self.assertContains(response, <REPLACE_NEW> self.assertContains(
            response, <REPLACE_END> <REPLACE_OLD> Git')
 <REPLACE_NEW> a Universal Core site')
 <REPLACE_END> <|endoftext|> import pytest

from django.test import TestCase
from django.core.urlresolvers import reverse

from molo.core.tests.base import MoloTestCaseMixin

@pytest.mark.django_db
class TestImportFromGit(TestCase, MoloTestCaseMixin):

    def setUp(self):
        self.mk_main()
        self.user = self.login()

    def test_wagtail_has_import_menu_item(self):
        response = self.client.get(reverse('import-from-git'))
        self.assertContains(
            response, 'Import content from a Universal Core site')

Prompt:
Fix import UI django view's tests

import pytest

from django.test import TestCase
from django.core.urlresolvers import reverse

from molo.core.tests.base import MoloTestCaseMixin

@pytest.mark.django_db
class TestImportFromGit(TestCase, MoloTestCaseMixin):

    def setUp(self):
        self.mk_main()
        self.user = self.login()

    def test_wagtail_has_import_menu_item(self):
        response = self.client.get(reverse("import-from-git"))
        self.assertContains(response, 'Import content from Git')


# coding=utf-8
from setuptools import setup, find_packages

setup(
    name="git-up",
    version="1.3.0",
    packages=find_packages(exclude=["tests"]),
    scripts=['PyGitUp/gitup.py'],
    install_requires=['GitPython==1.0.0', 'colorama==0.3.3',
                      'termcolor==1.1.0', 'docopt==0.6.2',
                      'six==1.9.0'],

    # Tests
    test_suite="nose.collector",
    tests_require='nose',

    # Executable
    entry_points={
        'console_scripts': [
            'git-up = PyGitUp.gitup:run'
        ]
    },

    # Additional data
    package_data={
        'PyGitUp': ['check-bundler.rb'],
        '': ['README.rst', 'LICENCE']
    },

    zip_safe=False,

    # Metadata
    author="Markus Siemens",
    author_email="markus@m-siemens.de",
    description="A python implementation of 'git up'",
    license="MIT",
    keywords="git git-up",
    url="https://github.com/msiemens/PyGitUp",
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "Environment :: Console",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: MIT License",
        "Topic :: Software Development :: Version Control",
        "Topic :: Utilities"
    ],

    long_description=open('README.rst').read()
)

Use full module path for entry point

Use full module path for entry point

Response:
<REPLACE_OLD> gitup:run'
 <REPLACE_NEW> PyGitUp.gitup:run'
 <REPLACE_END> <|endoftext|> # coding=utf-8
from setuptools import setup, find_packages

setup(
    name="git-up",
    version="1.3.0",
    packages=find_packages(exclude=["tests"]),
    scripts=['PyGitUp/gitup.py'],
    install_requires=['GitPython==1.0.0', 'colorama==0.3.3',
                      'termcolor==1.1.0', 'docopt==0.6.2',
                      'six==1.9.0'],

    # Tests
    test_suite="nose.collector",
    tests_require='nose',

    # Executable
    entry_points={
        'console_scripts': [
            'git-up = PyGitUp.gitup:run'
        ]
    },

    # Additional data
    package_data={
        'PyGitUp': ['check-bundler.rb'],
        '': ['README.rst', 'LICENCE']
    },

    zip_safe=False,

    # Metadata
    author="Markus Siemens",
    author_email="markus@m-siemens.de",
    description="A python implementation of 'git up'",
    license="MIT",
    keywords="git git-up",
    url="https://github.com/msiemens/PyGitUp",
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "Environment :: Console",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: MIT License",
        "Topic :: Software Development :: Version Control",
        "Topic :: Utilities"
    ],

    long_description=open('README.rst').read()
)

Prompt:
Use full module path for entry point

# coding=utf-8
from setuptools import setup, find_packages

setup(
    name="git-up",
    version="1.3.0",
    packages=find_packages(exclude=["tests"]),
    scripts=['PyGitUp/gitup.py'],
    install_requires=['GitPython==1.0.0', 'colorama==0.3.3',
                      'termcolor==1.1.0', 'docopt==0.6.2',
                      'six==1.9.0'],

    # Tests
    test_suite="nose.collector",
    tests_require='nose',

    # Executable
    entry_points={
        'console_scripts': [
            'git-up = gitup:run'
        ]
    },

    # Additional data
    package_data={
        'PyGitUp': ['check-bundler.rb'],
        '': ['README.rst', 'LICENCE']
    },

    zip_safe=False,

    # Metadata
    author="Markus Siemens",
    author_email="markus@m-siemens.de",
    description="A python implementation of 'git up'",
    license="MIT",
    keywords="git git-up",
    url="https://github.com/msiemens/PyGitUp",
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "Environment :: Console",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: MIT License",
        "Topic :: Software Development :: Version Control",
        "Topic :: Utilities"
    ],

    long_description=open('README.rst').read()
)


#
# Copyright (C) 2017 Maha Farhat
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
"""
Any useful django forms. Forn now just the testing form.
"""

from django.forms import Form

from .fields import UploadField

class TestUploadForm(Form):
    test_files = UploadField(
        extensions=['.vcf'],
    )

Add a test form object for testing

Add a test form object for testing

Response:
<INSERT> #
# Copyright (C) 2017 Maha Farhat
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. <INSERT_END> <INSERT> See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
"""
Any useful django forms. Forn now just the testing form.
"""

from django.forms import Form

from .fields import UploadField

class TestUploadForm(Form):
    test_files = UploadField(
        extensions=['.vcf'],
    )

 <INSERT_END> <|endoftext|> #
# Copyright (C) 2017 Maha Farhat
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
"""
Any useful django forms. Forn now just the testing form.
"""

from django.forms import Form

from .fields import UploadField

class TestUploadForm(Form):
    test_files = UploadField(
        extensions=['.vcf'],
    )

Prompt: Add a test form object for testing


import unittest
import os

os.environ['OGN_CONFIG_MODULE'] = 'config/test.py'

from ogn_python import db   # noqa: E402

class TestBaseDB(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        db.drop_all()
        db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
        db.session.commit()
        db.create_all()

    def setUp(self):
        pass

    def tearDown(self):
        db.session.execute("""
            DELETE FROM aircraft_beacons;
            DELETE FROM receiver_beacons;
            DELETE FROM takeoff_landings;
            DELETE FROM logbook;
            DELETE FROM receiver_coverages;
            DELETE FROM device_stats;
            DELETE FROM receiver_stats;
            DELETE FROM receivers;
            DELETE FROM devices;
        """)

if __name__ == '__main__':
    unittest.main()

Drop db before each test

Drop db before each test

Response:
<INSERT> db.drop_all()
        <INSERT_END> <|endoftext|> import unittest
import os

os.environ['OGN_CONFIG_MODULE'] = 'config/test.py'

from ogn_python import db   # noqa: E402

class TestBaseDB(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        db.drop_all()
        db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
        db.session.commit()
        db.create_all()

    def setUp(self):
        pass

    def tearDown(self):
        db.session.execute("""
            DELETE FROM aircraft_beacons;
            DELETE FROM receiver_beacons;
            DELETE FROM takeoff_landings;
            DELETE FROM logbook;
            DELETE FROM receiver_coverages;
            DELETE FROM device_stats;
            DELETE FROM receiver_stats;
            DELETE FROM receivers;
            DELETE FROM devices;
        """)

if __name__ == '__main__':
    unittest.main()

Prompt:
Drop db before each test

import unittest
import os

os.environ['OGN_CONFIG_MODULE'] = 'config/test.py'

from ogn_python import db   # noqa: E402

class TestBaseDB(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        db.session.execute('CREATE EXTENSION IF NOT EXISTS postgis;')
        db.session.commit()
        db.create_all()

    def setUp(self):
        pass

    def tearDown(self):
        db.session.execute("""
            DELETE FROM aircraft_beacons;
            DELETE FROM receiver_beacons;
            DELETE FROM takeoff_landings;
            DELETE FROM logbook;
            DELETE FROM receiver_coverages;
            DELETE FROM device_stats;
            DELETE FROM receiver_stats;
            DELETE FROM receivers;
            DELETE FROM devices;
        """)

if __name__ == '__main__':
    unittest.main()


import numpy as np
from sklearn.cross_validation import cross_val_score
from sklearn.externals import joblib as pickle

class scorer(object):
    def __init__(self, model_instance, descriptor_generator_instance):
        self.model = model_instance
        self.descriptor_generator = descriptor_generator_instance

    def fit(self, ligands, target):
        self.train_descs = self.descriptor_generator.build(ligands)
        self.train_target = target
        return self.model.fit(descs,target)

    def predict(self, ligands):
        descs = self.descriptor_generator.build(ligands)
        return self.model.predict(descs)

    def score(self, ligands, target):
        descs = self.descriptor_generator.build(ligands)
        return self.model.score(descs,target)

    def cross_validate(n = 10, test_set = None, test_target = None):
        if test_set and test_target:
            cv_set = np.vstack((self.train_descs, test_set))
            cv_target = np.vstack((self.train_target, test_target))
        else:
            cv_set = self.train_descs
            cv_target = self.train_target
        return cross_val_score(self.model, cv_set, cv_target, cv = n)

    def save(filename):
        f = open(filename,'wb')
        pickle.dump(self, filename)
        f.close()

    @classmethod
    def load(filename):
        return pickle.load(open(filename,'rb'))

Response:
<REPLACE_OLD> model, descriptor_generator, model_opts = {}, desc_opts = {}):
 <REPLACE_NEW> model_instance, descriptor_generator_instance):
 <REPLACE_END> <REPLACE_OLD> model()
 <REPLACE_NEW> model_instance
 <REPLACE_END> <REPLACE_OLD> descriptor_generator(**desc_opts)
 <REPLACE_NEW> descriptor_generator_instance
 <REPLACE_END> <|endoftext|> import numpy as np
from sklearn.cross_validation import cross_val_score
from sklearn.externals import joblib as pickle

class scorer(object):
    def __init__(self, model_instance, descriptor_generator_instance):
        self.model = model_instance
        self.descriptor_generator = descriptor_generator_instance

    def fit(self, ligands, target):
        self.train_descs = self.descriptor_generator.build(ligands)
        self.train_target = target
        return self.model.fit(descs,target)

    def predict(self, ligands):
        descs = self.descriptor_generator.build(ligands)
        return self.model.predict(descs)

    def score(self, ligands, target):
        descs = self.descriptor_generator.build(ligands)
        return self.model.score(descs,target)

    def cross_validate(n = 10, test_set = None, test_target = None):
        if test_set and test_target:
            cv_set = np.vstack((self.train_descs, test_set))
            cv_target = np.vstack((self.train_target, test_target))
        else:
            cv_set = self.train_descs
            cv_target = self.train_target
        return cross_val_score(self.model, cv_set, cv_target, cv = n)

    def save(filename):
        f = open(filename,'wb')
        pickle.dump(self, filename)
        f.close()

    @classmethod
    def load(filename):
        return pickle.load(open(filename,'rb'))

Prompt:
Make scorer accept instances of model and desc. gen.

import numpy as np
from sklearn.cross_validation import cross_val_score
from sklearn.externals import joblib as pickle

class scorer(object):
    def __init__(self, model, descriptor_generator, model_opts = {}, desc_opts = {}):
        self.model = model()
        self.descriptor_generator = descriptor_generator(**desc_opts)

    def fit(self, ligands, target):
        self.train_descs = self.descriptor_generator.build(ligands)
        self.train_target = target
        return self.model.fit(descs,target)

    def predict(self, ligands):
        descs = self.descriptor_generator.build(ligands)
        return self.model.predict(descs)

    def score(self, ligands, target):
        descs = self.descriptor_generator.build(ligands)
        return self.model.score(descs,target)

    def cross_validate(n = 10, test_set = None, test_target = None):
        if test_set and test_target:
            cv_set = np.vstack((self.train_descs, test_set))
            cv_target = np.vstack((self.train_target, test_target))
        else:
            cv_set = self.train_descs
            cv_target = self.train_target
        return cross_val_score(self.model, cv_set, cv_target, cv = n)

    def save(filename):
        f = open(filename,'wb')
        pickle.dump(self, filename)
        f.close()

    @classmethod
    def load(filename):
        return pickle.load(open(filename,'rb'))


# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

class Migration(migrations.Migration):

    dependencies = [
        ('wagtailimages', '0013_make_rendition_upload_callable'),
        ('catalogue', '0010_auto_20160616_1048'),
    ]

    operations = [
        migrations.AddField(
            model_name='category',
            name='description',
            field=models.TextField(verbose_name='Description', blank=True),
        ),
        migrations.AddField(
            model_name='category',
            name='image',
            field=models.ForeignKey(related_name='+', on_delete=django.db.models.deletion.SET_NULL, blank=True, to='wagtailimages.Image', null=True),
        ),
        migrations.AddField(
            model_name='category',
            name='name',
            field=models.CharField(max_length=255, verbose_name='Name', db_index=True),
        ),
    ]

Add field instead of alter field

Add field instead of alter field

Response:
<REPLACE_OLD> migrations.AlterField(
 <REPLACE_NEW> migrations.AddField(
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

class Migration(migrations.Migration):

    dependencies = [
        ('wagtailimages', '0013_make_rendition_upload_callable'),
        ('catalogue', '0010_auto_20160616_1048'),
    ]

    operations = [
        migrations.AddField(
            model_name='category',
            name='description',
            field=models.TextField(verbose_name='Description', blank=True),
        ),
        migrations.AddField(
            model_name='category',
            name='image',
            field=models.ForeignKey(related_name='+', on_delete=django.db.models.deletion.SET_NULL, blank=True, to='wagtailimages.Image', null=True),
        ),
        migrations.AddField(
            model_name='category',
            name='name',
            field=models.CharField(max_length=255, verbose_name='Name', db_index=True),
        ),
    ]

Prompt:
Add field instead of alter field

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

class Migration(migrations.Migration):

    dependencies = [
        ('wagtailimages', '0013_make_rendition_upload_callable'),
        ('catalogue', '0010_auto_20160616_1048'),
    ]

    operations = [
        migrations.AddField(
            model_name='category',
            name='description',
            field=models.TextField(verbose_name='Description', blank=True),
        ),
        migrations.AddField(
            model_name='category',
            name='image',
            field=models.ForeignKey(related_name='+', on_delete=django.db.models.deletion.SET_NULL, blank=True, to='wagtailimages.Image', null=True),
        ),
        migrations.AlterField(
            model_name='category',
            name='name',
            field=models.CharField(max_length=255, verbose_name='Name', db_index=True),
        ),
    ]


import json
from django.core.management.base import BaseCommand
from toggle.models import Toggle

from corehq.apps.locations.models import SQLLocation
from corehq.apps.domain.models import Domain
from corehq.toggles import HIERARCHICAL_LOCATION_FIXTURE, NAMESPACE_DOMAIN

class Command(BaseCommand):
    help = """
    To migrate to new flat fixture for locations. Enable FF HIERARCHICAL_LOCATION_FIXTURE for
    apps with locations and having commtrack:enabled in app files
    The Feature Flag FLAT_LOCATION_FIXTURE should be removed after this
    """

    def handle(self, *args, **options):
        domains_having_locations = (
            SQLLocation.objects.order_by('domain').distinct('domain')
            .values_list('domain', flat=True)
        )
        domains_with_hierarchical_fixture = find_applications_with_hierarchical_fixture(
            domains_having_locations
        )
        toggle = Toggle.get(HIERARCHICAL_LOCATION_FIXTURE.slug)
        for domain in domains_with_hierarchical_fixture:
            toggle.add(domain, True, NAMESPACE_DOMAIN)

def find_applications_with_hierarchical_fixture(domains):
    search_string = 'commtrack:enabled'
    domain_with_application = {}
    for domain in domains:
        domain_obj = Domain.get_by_name(domain)
        for application in domain_obj.applications():
            raw_doc = json.dumps(application.get_db().get(application.id))
            if search_string in raw_doc:
                search_string[domain] = application.id
                continue
    return domain_with_application

Response:
<REPLACE_OLD> from <REPLACE_NEW> import json
from <REPLACE_END> <DELETE> LocationFixtureConfiguration, <DELETE_END> <INSERT> corehq.apps.domain.models import Domain
from <INSERT_END> <REPLACE_OLD> FLAT_LOCATION_FIXTURE

class <REPLACE_NEW> HIERARCHICAL_LOCATION_FIXTURE, NAMESPACE_DOMAIN

class <REPLACE_END> <REPLACE_OLD> Update <REPLACE_NEW> Enable FF HIERARCHICAL_LOCATION_FIXTURE for
    <REPLACE_END> <REPLACE_OLD> not having
    FLAT_LOCATION_FIXTURE enabled to have LocationFixtureConfiguration with
    sync_hierarchical_fixture True and sync_flat_fixture False to have old fixtures enabled.
 <REPLACE_NEW> having commtrack:enabled in app files
 <REPLACE_END> <INSERT> FLAT_LOCATION_FIXTURE <INSERT_END> <REPLACE_OLD> set(SQLLocation.objects.values_list('domain', flat=True))
 <REPLACE_NEW> (
            SQLLocation.objects.order_by('domain').distinct('domain')
            .values_list('domain', flat=True)
        )
        domains_with_hierarchical_fixture = find_applications_with_hierarchical_fixture(
            domains_having_locations
        )
 <REPLACE_END> <REPLACE_OLD> Toggle.get(FLAT_LOCATION_FIXTURE.slug)
        enabled_users = toggle.enabled_users
        enabled_domains = [user.split('domain:')[1] for user in enabled_users]
        for domain_name in domains_having_locations:
 <REPLACE_NEW> Toggle.get(HIERARCHICAL_LOCATION_FIXTURE.slug)
        for domain in domains_with_hierarchical_fixture:
            toggle.add(domain, True, NAMESPACE_DOMAIN)

def find_applications_with_hierarchical_fixture(domains):
    search_string = 'commtrack:enabled'
    domain_with_application = {}
    for domain in domains:
        domain_obj = Domain.get_by_name(domain)
        for application in domain_obj.applications():
            raw_doc = json.dumps(application.get_db().get(application.id))
 <REPLACE_END> <REPLACE_OLD> domain_name not in enabled_domains:
                domain_config = LocationFixtureConfiguration.for_domain(domain_name)
                # update configs that had not been changed which means both values are at default True
                if domain_config.sync_hierarchical_fixture and domain_config.sync_flat_fixture:
                    # update them to use hierarchical fixture
                    domain_config.sync_flat_fixture = False
                    domain_config.sync_hierarchical_fixture = True
                    domain_config.save()
 <REPLACE_NEW> search_string in raw_doc:
                search_string[domain] = application.id
                continue
    return domain_with_application
 <REPLACE_END> <|endoftext|> import json
from django.core.management.base import BaseCommand
from toggle.models import Toggle

from corehq.apps.locations.models import SQLLocation
from corehq.apps.domain.models import Domain
from corehq.toggles import HIERARCHICAL_LOCATION_FIXTURE, NAMESPACE_DOMAIN

class Command(BaseCommand):
    help = """
    To migrate to new flat fixture for locations. Enable FF HIERARCHICAL_LOCATION_FIXTURE for
    apps with locations and having commtrack:enabled in app files
    The Feature Flag FLAT_LOCATION_FIXTURE should be removed after this
    """

    def handle(self, *args, **options):
        domains_having_locations = (
            SQLLocation.objects.order_by('domain').distinct('domain')
            .values_list('domain', flat=True)
        )
        domains_with_hierarchical_fixture = find_applications_with_hierarchical_fixture(
            domains_having_locations
        )
        toggle = Toggle.get(HIERARCHICAL_LOCATION_FIXTURE.slug)
        for domain in domains_with_hierarchical_fixture:
            toggle.add(domain, True, NAMESPACE_DOMAIN)

def find_applications_with_hierarchical_fixture(domains):
    search_string = 'commtrack:enabled'
    domain_with_application = {}
    for domain in domains:
        domain_obj = Domain.get_by_name(domain)
        for application in domain_obj.applications():
            raw_doc = json.dumps(application.get_db().get(application.id))
            if search_string in raw_doc:
                search_string[domain] = application.id
                continue
    return domain_with_application

Prompt:
Update migration to fetch domains with applications using old location fixture
from django.core.management.base import BaseCommand
from toggle.models import Toggle

from corehq.apps.locations.models import LocationFixtureConfiguration, SQLLocation
from corehq.toggles import FLAT_LOCATION_FIXTURE

class Command(BaseCommand):
    help = """
    To migrate to new flat fixture for locations. Update apps with locations and not having
    FLAT_LOCATION_FIXTURE enabled to have LocationFixtureConfiguration with
    sync_hierarchical_fixture True and sync_flat_fixture False to have old fixtures enabled.
    The Feature Flag should be removed after this
    """

    def handle(self, *args, **options):
        domains_having_locations = set(SQLLocation.objects.values_list('domain', flat=True))
        toggle = Toggle.get(FLAT_LOCATION_FIXTURE.slug)
        enabled_users = toggle.enabled_users
        enabled_domains = [user.split('domain:')[1] for user in enabled_users]
        for domain_name in domains_having_locations:
            if domain_name not in enabled_domains:
                domain_config = LocationFixtureConfiguration.for_domain(domain_name)
                # update configs that had not been changed which means both values are at default True
                if domain_config.sync_hierarchical_fixture and domain_config.sync_flat_fixture:
                    # update them to use hierarchical fixture
                    domain_config.sync_flat_fixture = False
                    domain_config.sync_hierarchical_fixture = True
                    domain_config.save()


from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

from performanceplatform.collector.ga.core \
    import create_client, query_documents_for, send_data

from performanceplatform.collector.write import DataSet

def main(credentials, data_set_config, query, options, start_at, end_at):
    client = create_client(credentials)

    documents = query_documents_for(
        client, query, options,
        options.get('dataType', data_set_config['data-type']),
        start_at, end_at)

    data_set = DataSet.from_config(data_set_config)
    send_data(data_set, documents)

Response:
<REPLACE_OLD> data_set_config['data-type'], start_at, end_at
 <REPLACE_NEW> options.get('dataType', data_set_config['data-type']),
 <REPLACE_END> <REPLACE_OLD> )

 <REPLACE_NEW>     start_at, end_at)

 <REPLACE_END> <|endoftext|> from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

from performanceplatform.collector.ga.core \
    import create_client, query_documents_for, send_data

from performanceplatform.collector.write import DataSet

def main(credentials, data_set_config, query, options, start_at, end_at):
    client = create_client(credentials)

    documents = query_documents_for(
        client, query, options,
        options.get('dataType', data_set_config['data-type']),
        start_at, end_at)

    data_set = DataSet.from_config(data_set_config)
    send_data(data_set, documents)

Prompt:
Allow the 'dataType' field to be overriden

The 'dataType' field in records predates data groups and data types. As
such they don't always match the new world order of data types. It's
fine to change in all cases other than Licensing which is run on
limelight, that we don't really want to touch.

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

from performanceplatform.collector.ga.core \
    import create_client, query_documents_for, send_data

from performanceplatform.collector.write import DataSet

def main(credentials, data_set_config, query, options, start_at, end_at):
    client = create_client(credentials)

    documents = query_documents_for(
        client, query, options,
        data_set_config['data-type'], start_at, end_at
    )

    data_set = DataSet.from_config(data_set_config)
    send_data(data_set, documents)


import subprocess

from vim_turing_machine.machines.merge_overlapping_intervals.decode_intervals import decode_intervals
from vim_turing_machine.machines.merge_overlapping_intervals.encode_intervals import encode_intervals
from vim_turing_machine.machines.merge_overlapping_intervals.merge_overlapping_intervals import MergeOverlappingIntervalsGenerator
from vim_turing_machine.vim_constants import VIM_MACHINE_FILENAME
from vim_turing_machine.vim_machine import VimTuringMachine

NUM_BITS = 3

def run_vim_machine(intervals):
    initial_tape = encode_intervals(intervals, NUM_BITS)

    gen = MergeOverlappingIntervalsGenerator(NUM_BITS)
    merge_overlapping_intervals = VimTuringMachine(gen.merge_overlapping_intervals_transitions(), debug=False)

    # Write to the vim machine file
    merge_overlapping_intervals.run(initial_tape=initial_tape)

    subprocess.run(
        [
            'vim',
            '-u',
            'vimrc',
            VIM_MACHINE_FILENAME,
            '-c',
            # Execute the vim machine and then save the resulting file
            ":execute 'normal gg0yy@\"' | :x",
        ],
        timeout=10,
        check=True,
    )

def read_contents_of_tape():
    with open(VIM_MACHINE_FILENAME, 'r') as f:
        tape_lines = []
        found_beginning_of_tape = False

        for line in f:
            # Look for the lines between '_t:' and 'notvalid'
            if line.startswith('_t:'):
                found_beginning_of_tape = True
            elif line.startswith('notvalid'):
                return convert_tape_to_string(tape_lines)
            elif found_beginning_of_tape:
                tape_lines.append(line)

    raise AssertionError('Could not find the tape')

def convert_tape_to_string(tape_lines):
    return ''.join(tape_lines).replace(' ', '').replace('\n', '')

def test_merge_intervals_in_vim():
    run_vim_machine([[1, 2], [2, 3], [5, 7]])
    tape = read_contents_of_tape()

    intervals = decode_intervals(tape, num_bits=NUM_BITS)
    assert intervals == [[1, 3], [5, 7]]

Add an integration test for the vim machine.

Response:
<REPLACE_OLD>  <REPLACE_NEW> import subprocess

from vim_turing_machine.machines.merge_overlapping_intervals.decode_intervals import decode_intervals
from vim_turing_machine.machines.merge_overlapping_intervals.encode_intervals import encode_intervals
from vim_turing_machine.machines.merge_overlapping_intervals.merge_overlapping_intervals import MergeOverlappingIntervalsGenerator
from vim_turing_machine.vim_constants import VIM_MACHINE_FILENAME
from vim_turing_machine.vim_machine import VimTuringMachine

NUM_BITS = 3

def run_vim_machine(intervals):
    initial_tape = encode_intervals(intervals, NUM_BITS)

    gen = MergeOverlappingIntervalsGenerator(NUM_BITS)
    merge_overlapping_intervals = VimTuringMachine(gen.merge_overlapping_intervals_transitions(), debug=False)

    # Write to the vim machine file
    merge_overlapping_intervals.run(initial_tape=initial_tape)

    subprocess.run(
        [
            'vim',
            '-u',
            'vimrc',
            VIM_MACHINE_FILENAME,
            '-c',
            # Execute the vim machine and then save the resulting file
            ":execute 'normal gg0yy@\"' | :x",
        ],
        timeout=10,
        check=True,
    )

def read_contents_of_tape():
    with open(VIM_MACHINE_FILENAME, 'r') as f:
        tape_lines = []
        found_beginning_of_tape = False

        for line in f:
            # Look for the lines between '_t:' and 'notvalid'
            if line.startswith('_t:'):
                found_beginning_of_tape = True
            elif line.startswith('notvalid'):
                return convert_tape_to_string(tape_lines)
            elif found_beginning_of_tape:
                tape_lines.append(line)

    raise AssertionError('Could not find the tape')

def convert_tape_to_string(tape_lines):
    return ''.join(tape_lines).replace(' ', '').replace('\n', '')

def test_merge_intervals_in_vim():
    run_vim_machine([[1, 2], [2, 3], [5, 7]])
    tape = read_contents_of_tape()

    intervals = decode_intervals(tape, num_bits=NUM_BITS)
    assert intervals == [[1, 3], [5, 7]]
 <REPLACE_END> <|endoftext|> import subprocess

from vim_turing_machine.machines.merge_overlapping_intervals.decode_intervals import decode_intervals
from vim_turing_machine.machines.merge_overlapping_intervals.encode_intervals import encode_intervals
from vim_turing_machine.machines.merge_overlapping_intervals.merge_overlapping_intervals import MergeOverlappingIntervalsGenerator
from vim_turing_machine.vim_constants import VIM_MACHINE_FILENAME
from vim_turing_machine.vim_machine import VimTuringMachine

NUM_BITS = 3

def run_vim_machine(intervals):
    initial_tape = encode_intervals(intervals, NUM_BITS)

    gen = MergeOverlappingIntervalsGenerator(NUM_BITS)
    merge_overlapping_intervals = VimTuringMachine(gen.merge_overlapping_intervals_transitions(), debug=False)

    # Write to the vim machine file
    merge_overlapping_intervals.run(initial_tape=initial_tape)

    subprocess.run(
        [
            'vim',
            '-u',
            'vimrc',
            VIM_MACHINE_FILENAME,
            '-c',
            # Execute the vim machine and then save the resulting file
            ":execute 'normal gg0yy@\"' | :x",
        ],
        timeout=10,
        check=True,
    )

def read_contents_of_tape():
    with open(VIM_MACHINE_FILENAME, 'r') as f:
        tape_lines = []
        found_beginning_of_tape = False

        for line in f:
            # Look for the lines between '_t:' and 'notvalid'
            if line.startswith('_t:'):
                found_beginning_of_tape = True
            elif line.startswith('notvalid'):
                return convert_tape_to_string(tape_lines)
            elif found_beginning_of_tape:
                tape_lines.append(line)

    raise AssertionError('Could not find the tape')

def convert_tape_to_string(tape_lines):
    return ''.join(tape_lines).replace(' ', '').replace('\n', '')

def test_merge_intervals_in_vim():
    run_vim_machine([[1, 2], [2, 3], [5, 7]])
    tape = read_contents_of_tape()

    intervals = decode_intervals(tape, num_bits=NUM_BITS)
    assert intervals == [[1, 3], [5, 7]]

Prompt: Add an integration test for the vim machine.


# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import unittest

class ToHTMLTest(unittest.TestCase):
    SAMPLE = (
        "Проверяем *CommonMark*.\n\nВставляем `код`.\nИ другие штуки.\n\n"
        "
Test of HTML.
")

    def setUp(self):
        from paka.cmark import to_html

        self.func = to_html

    def check(self, source, expected, **kwargs):
        self.assertEqual(self.func(source, **kwargs), expected)

    def test_empty(self):
        self.check("", "")

    def test_ascii(self):
        self.check("Hello, Noob!", "
Hello, Noob!
\n")

    def test_non_ascii(self):
        self.check(
            self.SAMPLE,
            (
                "
Проверяем CommonMark.
\n"
                "
Вставляем код. И другие штуки.
\n"
                "
Test of HTML.
\n"))

    def test_breaks(self):
        self.check(
            self.SAMPLE,
            (
                "
Проверяем CommonMark.
\n"
                "
Вставляем код.\nИ другие штуки.
\n"
                "
Test of HTML.
\n"),
            breaks=True)

Add HTML fragment to test sample

Add HTML fragment to test sample

Response:
<INSERT> (
        <INSERT_END> <REPLACE_OLD> штуки."

 <REPLACE_NEW> штуки.\n\n"
        "<p>Test of <em>HTML</em>.</p>")

 <REPLACE_END> <REPLACE_OLD> штуки.</p>\n"))

 <REPLACE_NEW> штуки.</p>\n"
                "<p>Test of <em>HTML</em>.</p>\n"))

 <REPLACE_END> <REPLACE_OLD> штуки.</p>\n"),
 <REPLACE_NEW> штуки.</p>\n"
                "<p>Test of <em>HTML</em>.</p>\n"),
 <REPLACE_END> <|endoftext|> # -*- coding: utf-8 -*-

from __future__ import unicode_literals

import unittest

class ToHTMLTest(unittest.TestCase):
    SAMPLE = (
        "Проверяем *CommonMark*.\n\nВставляем `код`.\nИ другие штуки.\n\n"
        "<p>Test of <em>HTML</em>.</p>")

    def setUp(self):
        from paka.cmark import to_html

        self.func = to_html

    def check(self, source, expected, **kwargs):
        self.assertEqual(self.func(source, **kwargs), expected)

    def test_empty(self):
        self.check("", "")

    def test_ascii(self):
        self.check("Hello, Noob!", "<p>Hello, Noob!</p>\n")

    def test_non_ascii(self):
        self.check(
            self.SAMPLE,
            (
                "<p>Проверяем <em>CommonMark</em>.</p>\n"
                "<p>Вставляем <code>код</code>. И другие штуки.</p>\n"
                "<p>Test of <em>HTML</em>.</p>\n"))

    def test_breaks(self):
        self.check(
            self.SAMPLE,
            (
                "<p>Проверяем <em>CommonMark</em>.</p>\n"
                "<p>Вставляем <code>код</code>.\nИ другие штуки.</p>\n"
                "<p>Test of <em>HTML</em>.</p>\n"),
            breaks=True)

Prompt:
Add HTML fragment to test sample

# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import unittest

class ToHTMLTest(unittest.TestCase):
    SAMPLE = "Проверяем *CommonMark*.\n\nВставляем `код`.\nИ другие штуки."

    def setUp(self):
        from paka.cmark import to_html

        self.func = to_html

    def check(self, source, expected, **kwargs):
        self.assertEqual(self.func(source, **kwargs), expected)

    def test_empty(self):
        self.check("", "")

    def test_ascii(self):
        self.check("Hello, Noob!", "
Hello, Noob!
\n")

    def test_non_ascii(self):
        self.check(
            self.SAMPLE,
            (
                "
Проверяем CommonMark.
\n"
                "
Вставляем код. И другие штуки.
\n"))

    def test_breaks(self):
        self.check(
            self.SAMPLE,
            (
                "
Проверяем CommonMark.
\n"
                "
Вставляем код.\nИ другие штуки.
\n"),
            breaks=True)