def pre_setup(self):
        """ Make a copy of at the ini files and set the port number and host in the new testing.ini
        """
        self.working_config = self.workspace / self.config_filename

        # We need the other ini files as well here as they may be chained
        for filename in glob.glob(os.path.join(self.config_dir, '*.ini')):
            shutil.copy(filename, self.workspace)

        path.copy(self.original_config, self.working_config)

        parser = ConfigParser.ConfigParser()
        parser.read(self.original_config)
        parser.set('server:main', 'port', self.port)
        parser.set('server:main', 'host', self.hostname)
        [
            parser.set(section, k, v)
            for section, cfg in self.extra_config_vars.items()
            for (k, v) in cfg.items()
        ]
        with open(str(self.working_config), 'w') as fp:
            parser.write(fp)

        # Set the uri to be the external hostname and the url prefix
        self._uri = "http://%s:%s/%s" % (os.uname()[1], self.port,
                                         parser.get('app:main', 'url_prefix'))
Ejemplo n.º 2
0
def copy_dataset(config):
  if config.dataset.main_path.isdir() and \
     len(config.dataset.main_path.listdir()) > 0:
    print('FOUND COPY OF DATASET, NOT COPYING ANYTHING')
    return
  
  old_path = config.dataset.original_dataset_path
  flist = dir_util.copy_tree(old_path, config.dataset.main_path, 
                             update=1, verbose=3)
  
  # make a backup of the train/test annotation files
  path.copy(path(config.dataset.train_annos_file), path(config.dataset.train_annos_file_bk))
  path.copy(path(config.dataset.test_annos_file), path(config.dataset.test_annos_file_bk))
Ejemplo n.º 3
0
def setnewclip(clip_id):
    global work
    global dquiz, quizid
    print 'setnewclip', clip_id
    work.sndfn = path(clip_id).name
    if SOUNDPATH in clip_id:
        print 'clip from activity'
    else:
        print 'clip from datastore'
        #copy image to activity
        srcpath = clip_id
        dstpath = SOUNDPATH / work.sndfn
        path.copy(srcpath, dstpath)
    print 'setnewclip', work.sndfn
    display_page()
Ejemplo n.º 4
0
def setnewimg(image_id):
    global work
    global dquiz, quizid
    #image_id is absolute path name
    work.imgfn = path(work.imgfn).name
    print 'setnewimg', image_id
    if IMAGEPATH in image_id:
        print 'image from activity'
    else:
        print 'image from datastore'
        #copy image to activity
        srcpath = image_id
        dstpath = IMAGEPATH / work.imgfn
        path.copy(srcpath, dstpath)
    print 'setnewimg', work.imgfn
    display_page()
Ejemplo n.º 5
0
def makebundle(quiz_id):
    q = "SELECT text FROM categories WHERE id = '%i'" % quiz_id
    res = __SERVICES__.db.query(q)
    quizname = res[0][0]
    create_empty_folder(BUNDLEPATH)
    #get list of questions (by question_id)
    q = "SELECT question_id FROM quizlink WHERE quiz_id = '%i'" % quiz_id
    questionlist = __SERVICES__.db.query(q)
    #get actual questions
    questions = []
    for questionid in questionlist:
        q = "SELECT * from questions WHERE id = '%i'" % questionid[0]
        res = __SERVICES__.db.query(q)
        question = Question()
        question.id = res[0][0]
        question.prompt = res[0][1]
        question.response = res[0][2]
        question.imgfn = res[0][3]
        question.sndfn = res[0][4]
        question.map = res[0][5]
        question.answer_link = res[0][6]
        questions.append(question)
    #copy images and sounds to BUNDLEPATH
    for question in questions:
        if len(question.imgfn) > 0:
            src = IMAGEPATH / question.imgfn
            path.copy(src, BUNDLEPATH)
        if len(question.sndfn) > 0:
            src = SOUNDPATH / question.sndfn
            path.copy(src, BUNDLEPATH)
    questions_to_xml(questions, quizname, BUNDLEPATH)
    fn = quizname + '.iqxo'
    pth = BUNDLEPATH / fn
    print 'makebundle: zip_folder', pth
    zip_folder(BUNDLEPATH, pth)
    print 'makebundle: write bundle to datastore'
    dsobject = datastore.create()
    dsobject.metadata['title'] = quizname
    dsobject.metadata['mime_type'] = 'application/x-imagequiz'
    dsobject.set_file_path(pth)
    datastore.write(dsobject)
    sf.clear_text_items()
Ejemplo n.º 6
0
    def pre_setup(self):
        """ Make a copy of the development and testing ini file and set the port number and host
        """
        # We need the development.ini as well here as they are chained
        dev_cfg = path(os.getcwd()) / 'development.ini'
        dev_cfg_copy = self.workspace / 'development.ini'
        path.copy(dev_cfg, dev_cfg_copy)

        self.original_config = path(os.getcwd()) / 'testing.ini'
        self.config = self.workspace / 'testing.ini'
        path.copy(self.original_config, self.config)

        parser = ConfigParser.ConfigParser()
        parser.read(self.original_config)
        parser.set('server:main', 'port', self.port)
        parser.set('server:main', 'host', self.hostname)
        with self.config.open('w') as fp:
            parser.write(fp)

        # Set the uri to be the external hostname and the url prefix
        self._uri = "http://%s:%s/%s" % (os.uname()[1], self.port, parser.get('app:main', 'url_prefix'))
Ejemplo n.º 7
0
    def pre_setup(self):
        """ Make a copy of at the ini files and set the port number and host in the new testing.ini
        """
        self.working_config = self.workspace / self.config_filename

        # We need the other ini files as well here as they may be chained
        for filename in glob.glob(os.path.join(self.config_dir, '*.ini')):
            shutil.copy(filename, self.workspace)

        path.copy(self.original_config, self.working_config)

        parser = ConfigParser.ConfigParser()
        parser.read(self.original_config)
        parser.set('server:main', 'port', self.port)
        parser.set('server:main', 'host', self.hostname)
        [parser.set(section, k, v) for section, cfg in self.extra_config_vars.items() for (k, v) in cfg.items()]
        with self.working_config.open('w') as fp:
            parser.write(fp)

        # Set the uri to be the external hostname and the url prefix
        self._uri = "http://%s:%s/%s" % (os.uname()[1], self.port, parser.get('app:main', 'url_prefix'))
Ejemplo n.º 8
0
    def __init__(self, sugaractivity, handle, rsrc, base="/nfs/show"):
        GObject.GObject.__init__(self)
        self.__handle = handle
        if self.__handle.object_id is None:
            print 'slideshow - from home view'
        else:
            obj = datastore.get(self.__handle.object_id)
            print 'object:', obj.get_file_path()
        self.__logger = logging.getLogger('Deck')
        self.__base = base
        self.__rsrc = rsrc
        self.__activity = sugaractivity

        self.__is_initiating = True
        self.__nav_locked = False
        self.__active_sub = -1
        self.__self_text = ""
        self.__text_tag = None
        self.__xmlpath = os.path.join(base, "deck.xml")
        # we always create a new presentation and copy over it on resume
        if path(base).exists():
            # we can't have permissions.info for this to work
            subprocess.call("cp -r " + base + " " +
                            os.path.expanduser("~/save"),
                            shell=True)
            subprocess.call("rm -rf " + base + '/*', shell=True)
        else:
            path.mkdir(base)
        path.copy(self.__rsrc / 'deck.xml', base / 'deck.xml')
        path.copy(self.__rsrc / 'title.html', base / 'title.html')
        path.copy(self.__rsrc / 'title_thumb.png', base / 'title_thumb.png')
        self.reload()
        self.set_title('New')
Ejemplo n.º 9
0
    def addSlide(self, file_path):

        INSTANCE = path(activity.get_activity_root()) / 'instance'
        filepath = path(file_path)
        print 'addSlide file_path', filepath.exists(), filepath
        filename = filepath.name
        inpath = INSTANCE / 'deck' / filename
        print 'inpath', inpath.exists(), inpath
        path.copy(filepath, inpath)
        outpath = path(activity.get_activity_root()) / \
            'instance' / 'deck' / filename
        print 'outpath=', outpath.exists(), outpath
        self.resizeImage(inpath, outpath, 640, 480)
        print 'outpath=', outpath.exists(), outpath

        print 'get slide dimensions'
        dims = self.getSlideDimensionsFromXML(0)
        if not dims:
            wf = 640
            hf = 480
        else:
            wf, hf = dims
        w = str(int(wf))
        h = str(int(hf))
        print 'add slide', w, h
        newslide = self.__dom.createElement("slide")
        newslide.setAttribute("height", h)
        newslide.setAttribute("title", "newslide")
        newslide.setAttribute("width", w)
        newlayer = self.__dom.createElement("layer")
        txt = self.__dom.createTextNode(filename)
        newlayer.appendChild(txt)
        newslide.appendChild(newlayer)
        self.__deck.appendChild(newslide)
        print '**************addSlide*************'
        print self.__dom.toprettyxml()
        print '***********************************'
        self.save()
Ejemplo n.º 10
0
def make_new_album(from_dir):
    #currently, no error handling
    frd = path(from_dir)
    d = raw_input("What is the album's name? ")
    try:
        os.mkdir(path.joinpath('photos', d))
        os.chdir(path.joinpath('photos', d))
        cwd = path.getcwd()
        included = []
        for f in frd.files():
            commands.getoutput('eog %s' % f)
            ans = raw_input('include this file in the album? (y/[n]) ')
            if ans.lower() == 'y' or ans.lower() == 'yes':
                cmt = raw_input('picture caption: (blank for none)')
                path.copy(f, cwd)
                n = f.name.replace(f.name[-4:], '.thumb' + f.name[-4:])
                thumb = path.joinpath(cwd, n)
                path.copy(f, thumb)
                cur_pic = path.joinpath(cwd, f.name)
                included.append(Photo(cur_pic, thumb, cmt)) 
                im = resize_image(Image.open(thumb), (200, 150))
                im.save(file(thumb, 'w'))
        return included
Ejemplo n.º 11
0
def getbundle(pth):
    global uglyflag
    quizname = path(pth).namebase
    create_empty_folder(BUNDLEPATH)
    unzip_bundle(pth, BUNDLEPATH)
    #copy images and sounds to IMAGEPATH, SOUNDPATH
    for f in BUNDLEPATH.files():
        if f.ext in ['.jpg', '.svg', '.png', '.gif']:
            path.copy(f, IMAGEPATH)
        if f.ext in ['.ogg', '.mp3', '.wav']:
            path.copy(f, SOUNDPATH)
        if f.ext == '.xml':
            xmlpth = f
    print 'convert xml to questions', xmlpth
    questions = xml_to_questions(xmlpth)
    print 'add quiz to categories'
    #add quiz to categories
    q = "INSERT INTO categories (text) VALUES ('%s')" % quizname
    __SERVICES__.db.commit(q)
    q = "SELECT id FROM categories WHERE text = '%s'" % quizname
    res = __SERVICES__.db.query(q)
    quiz_id = res[0][0]
    #add questions to db
    for question in questions:
        q = u'INSERT INTO questions (prompt, response, image_fn, sound_fn, map, answer_link)VALUES ("%s", "%s", "%s", "%s", "%s", "%s")' % (
            question.prompt, question.response, question.imgfn, question.sndfn,
            question.map, "")
        __SERVICES__.db.commit(q)
        question_id = __SERVICES__.db.lastrowid()
        q = "INSERT INTO quizlink (quiz_id, question_id) VALUES ('%i', '%i')" % (
            quiz_id, question_id)
        __SERVICES__.db.commit(q)
        q = "INSERT INTO leitner (question_id, count_found, count_notfound, box, time, day) VALUES ('%i', '%i', '%i', '%i', '%i', '%i')" % (
            question_id, 0, 0, 0, 0, 0)
        __SERVICES__.db.commit(q)
    if not uglyflag:
        sf.clear_text_items()
Ejemplo n.º 12
0
    def pre_setup(self):
        """ Make a copy of the development and testing ini file and set the
            port number and host
        """
        # We need the development.ini as well here as they are chained
        if not self.testing_ini:
            dev_cfg = path(os.getcwd()) / 'development.ini'
            dev_cfg_copy = self.workspace / 'development.ini'
            path.copy(dev_cfg, dev_cfg_copy)

            self.original_config = path(os.getcwd()) / 'testing.ini'
            self.config = self.workspace / 'testing.ini'
            path.copy(self.original_config, self.config)

        else:
            if not os.path.isfile(self.testing_ini):
                raise ConfigNotFoundError(
                    "{0} not found".format(self.testing_ini)
                )

            # development_ini isn't used if you have set testing_ini

            # Copy the original file and reuse its file name. The given file
            # name should be distinct in the dir it will get copied to!
            self.original_config = path(self.testing_ini)
            cfg_filename = os.path.basename(self.testing_ini)
            self.config = self.workspace / cfg_filename
            path.copy(self.original_config, self.config)

        parser = ConfigParser.ConfigParser()
        # self.original_config only refers to testing.ini, development.ini
        # isn't used?
        parser.read(self.original_config)
        parser.set('server:main', 'port', self.port)
        parser.set('server:main', 'host', self.hostname)
        with self.config.open('w') as fp:
            parser.write(fp)

        # Set the uri to be the external hostname and the optional url prefix
        parts = ["http:/", "{}:{}".format(os.uname()[1], self.port)]
        if parser.has_option('app:main', 'url_prefix'):
            parts.append(parser.get('app:main', 'url_prefix'))
        self._uri = "/".join(parts)