def main(): try: repo = nog.createRepo('test-resolveimgsrc-optimization') except RuntimeError: repo = nog.openRepo('test-resolveimgsrc-optimization') master = repo.getMaster() root = nog.Tree() root.name = 'root' lines = [ '# {} small squares'.format(N), '', ] images = nog.Tree() images.name = 'images' for i in range(N): img = nog.Object() name = 'img-{}.png'.format(i) img.name = name img.blob = '/tmp/test.png' images.append(img) lines.append('<img src="./images/{}" width="20">'.format(name)) md = nog.Object() md.name = 'images.md' md.text = '\n'.join(lines) root.append(md) root.append(images) repo.commitTree(subject='images', tree=root, parent=master.sha1)
def main(): for r in range(nRepos): repoName = '{0}{1}'.format(repoBaseName, r) print('Creating repo {0}'.format(repoName)) try: repo = nog.createRepo(repoName) except RuntimeError: repo = nog.openRepo(repoName) master = repo.getMaster() root = nog.Tree() root.name = 'root' root.meta['files'] = {} for t in range(nTreesPerRepo): treeName = 'Tree{0}'.format(t) tree = nog.Tree() tree.name = treeName for i in range(nEntriesPerTree): entry = nog.Object() entry.name = 'entry-{}'.format(i) entry.meta['entryNum'] = i entry.meta['entryName'] = entry.name entry.meta['repoName'] = repoName entry.meta['treeName'] = treeName tree.append(entry) root.append(tree) repo.commitTree(subject='images', tree=root, parent=master.sha1)
def upload(dirToUpload, repoName, overwrite): absDirToUpload = os.path.abspath(dirToUpload) if not os.path.isdir(absDirToUpload): raise IOError("\'{0}\' is not a directory".format(absDirToUpload)) tree = nog.Tree() tree.name = os.path.basename(os.path.normpath(absDirToUpload)) addContentsOfDirToTree(absDirToUpload, tree) try: repo = nog.openRepo(repoName) except RuntimeError: print('Repo \'{0}\' does not exist, let\'s create it.'.format(repoName)) repo = nog.createRepo(repoName) master = repo.getMaster() root = master.tree for idx, t in root.enumerateEntries(tree.name): if overwrite: print('Repo \'{0}\' already contains entry \'{1}\'. Removing it.'.format(repoName, tree.name)) root.pop(idx) else: raise RuntimeError('Repo \'{0}\' already contains entry \'{1}\'. Use --force-overwrite to overwrite.'.format(repoName, tree.name)) root.append(tree) repo.commitTree("Dataset upload", root, master.sha1) print('Upload complete.')
def test_ensureTestingRepo(): global remote try: remote = nog.openRepo(repoName) except RuntimeError: remote = nog.createRepo(repoName) assert remote.url.endswith(repoName)
def main(): try: repo = nog.createRepo(repoName) except RuntimeError: repo = nog.openRepo(repoName) master = repo.getMaster() root = nog.Tree() root.name = 'root' root.meta['workspace'] = {} datalist = nog.Tree() datalist.name = 'datalist' datalist.meta['datalist'] = {} for i in range(nImages): img = nog.Object() img.name = 'img-{}.png'.format(i) img.blob = '/tmp/test.png' datalist.append(img) root.append(datalist) programs = nog.Tree() programs.name = 'programs' programs.meta['programs'] = {} root.append(programs) jobs = nog.Tree() jobs.name = 'jobs' jobs.meta['jobs'] = {} root.append(jobs) # The result tree can be organized as: # # ``` # /results/result-0/report.md # /results/result-1/report.md # ... # ``` # # or as: # # ``` # /results/subresults-0/subresult-0-0/report.md # /results/subresults-0/subresult-0-1/report.md # /results/subresults-1/subresult-1-0/report.md # ... # ``` # # Simulate both structures in a single tree. results = nog.Tree() results.name = 'results' results.meta['results'] = {} root.append(results) for i in range(nResults): results.append(makeResultTree('result-{}'.format(i))) subresults = nog.Tree() subresults.name = 'subresults-{}'.format(i) results.append(subresults) for j in range(nResults): r = makeResultTree('subresult-{}-{}'.format(i, j)) for k in range(nRepeatResults): subresults.append(r) repo.commitTree(subject='images', tree=root, parent=master.sha1)