def setUp(self):
        self.base_dir = os.path.dirname(os.path.realpath(__file__))

        __data_dir = os.path.join(self.base_dir, 'data')
        if not os.path.exists(__data_dir):
            os.mkdir(__data_dir)

        self.retriever = Retriever(__data_dir)
class RetrieverTest(unittest.TestCase):

    def setUp(self):
        self.base_dir = os.path.dirname(os.path.realpath(__file__))

        __data_dir = os.path.join(self.base_dir, 'data')
        if not os.path.exists(__data_dir):
            os.mkdir(__data_dir)

        self.retriever = Retriever(__data_dir)

    def test_download(self):
        records = ['ins1404159', 'ins1396140']

        for record in records:
            self.retriever.get_record(record)
            self.assertTrue(
                os.path.exists(os.path.join(self.base_dir, 'data', record)))

    def test_get_all_current_ids(self):
        inspire_ids = self.retriever.get_all_ids_in_current_system()
        print 'We have {0} records to retrieve'.format(len(inspire_ids))
        self.assertTrue(len(inspire_ids) > 0)
Esempio n. 3
0
    def __init__(self, min_length=0, starting_text=''):
        self.min_length = min_length
        self.change_text(starting_text)

    def change_text(self, text):
        self.text = text.ljust(self.min_length)

    def update(self, pbar):
        return ' ' + self.text + ' '

class AlwaysUpdatingProgressBar(ProgressBar):
    def _need_update(self):
        return True

makedirs(temp_dir)
retriever = Retriever(temp_dir)
inspire_ids = retriever.get_all_ids_in_current_system()

submission_label = Label(min_length=10)
pbar = AlwaysUpdatingProgressBar(maxval=len(inspire_ids),
                   widgets=[
                       Percentage(),
                       submission_label,
                       Bar(marker='#', left='[', right=']')
                   ]).start()

 # fallback for very large YAML exports
retriever2 = Retriever(temp_dir, base_url="http://hepdata.cedar.ac.uk/h2test/view/{0}/yaml")

for index, inspire_id in enumerate(inspire_ids):
    submission_label.change_text(inspire_id)