chooses a starting source file in the 'base' directory for id = book_id
498000
def source_start(base='', book_id='book'):
    
    repo_htm_path = "{book_id}-h/{book_id}-h.htm".format(book_id=book_id)
    possible_paths = ["book.asciidoc",
                      repo_htm_path,
                      "{}-0.txt".format(book_id),
                      "{}-8.txt".format(book_id),
                      "{}.txt".format(book_id),
                      "{}-pdf.pdf".format(book_id),
                     ]

    # return the first match

    for path in possible_paths:
        fullpath = os.path.join(base, path)
        if os.path.exists(fullpath):
            return path

    return None
1146838
def init(self):
        
        self.logger.info('Start initialize dir [%s]', self.basePath)
        # Clean the directory
        for name in os.listdir(self.basePath):
            path = os.path.join(self.basePath, name)
            if os.path.isdir(path):
                shutil.rmtree(path)
            else:
                os.unlink(path)
        # Prepare dirs and files
        self.logger.info('Prepare dirs and files')
        for name in self.DIRS:
            os.mkdir(os.path.join(self.basePath, name))
        with open(os.path.join(self.basePath, self.FILE_INDEX), 'wb') as fd:
            pass
        with open(os.path.join(self.basePath, self.FILE_SERIAL), 'wb') as fd:
            print >>fd, 1000
        # Format the config file
        env = jinja2.Environment(
                loader = jinja2.FileSystemLoader(os.path.dirname(os.path.abspath(__file__))),
                trim_blocks = True,
                lstrip_blocks = True
                )
        template = env.get_template('openssl.config.template')
        content = template.render(basePath = self.basePath)
        with open(os.path.join(self.basePath, self.FILE_CONFIG), 'wb') as fd:
            print >>fd, content
714198
def select_directory(self):
        """"""
        basedir = to_text_string(self.wd_edit.text())
        if not osp.isdir(basedir):
            basedir = getcwd_or_home()
        directory = getexistingdirectory(self, _(""), basedir)
        if directory:
            self.wd_edit.setText(directory)
            self.dir = directory
643447
def toil_get_file(file_store, index, existing, file_store_id):
    """"""

    if not file_store_id.startswith("toilfs:"):
        return file_store.jobStore.getPublicUrl(file_store.jobStore.importFile(file_store_id))
    src_path = file_store.readGlobalFile(file_store_id[7:])
    index[src_path] = file_store_id
    existing[file_store_id] = src_path
    return schema_salad.ref_resolver.file_uri(src_path)
968963
function startForeverWithIndex( index, doneCB ) {
  log( 'Attempting to start ' + index + ' as daemon.');

  var config;
  var appendConfig = function(prop, value) {
    log('Adding to config: ' + prop + ', ' + value);
    if(value !== undefined) {
      config[prop] = value;
    }
  };
  done = doneCB || this.async();
  findProcessWithIndex( index, function(process) {
    // if found, be on our way without failing.
    if( typeof process !== 'undefined' ) {
      warn( index + ' is already running.');
      log( forever.format(true, [process]) );
      done();
    }
    else {
      gruntRef.file.mkdir(logDir);
      // 'forever start -o out.log -e err.log -c node -a -m 3 index.js';
      config = {
        command: commandName,
        append: true,
        max: 3,
        killSignal: killSignal
      };
      appendConfig('errFile', errFile);
      appendConfig('outFile', outFile);
      appendConfig('logFile', logFile);
      forever.startDaemon( index, config );
      log( 'Logs can be found at ' + logDir + '.' );
      done();
    }
  });
}
748518
def _initIndexDir(self):
        """"""
        if not os.path.exists(self.logdir):
            os.mkdir(self.logdir)
            dprint(1, "created", self.logdir)
        Purr.RenderIndex.initIndexDir(self.logdir)
497009
def set_save_directory(base, source):
    
    root = os.path.join(base, source)
    if not os.path.isdir(root):
        os.makedirs(root)

    world.screenshot_root = root
427601
def __find_source_files(self):
        
        for dir_path, _, files in os.walk(self._source_directory):
            for name in files:
                if name.lower().endswith(self._source_file_extension):
                    basename = os.path.splitext(os.path.basename(name))[0]
                    relative_path = os.path.relpath(os.path.join(dir_path, name))

                    if basename in self._source_file_names:
                        self._io.error("Files '{0}' and '{1}' have the same basename.".
                                       format(self._source_file_names[basename], relative_path))
                        self.error_file_names.add(relative_path)
                    else:
                        self._source_file_names[basename] = relative_path
1101236
def choose_file_or_dir():
    
    question = QMessageBox(QMessageBox.Information, 'Open Dataset',
                           'Do you want to open a file or a directory?')
    dir_button = question.addButton('Directory', QMessageBox.YesRole)
    file_button = question.addButton('File', QMessageBox.NoRole)
    question.addButton(QMessageBox.Cancel)
    question.exec_()
    response = question.clickedButton()

    if response == dir_button:
        return 'dir'
    elif response == file_button:
        return 'file'
    else:
        return 'abort'
1271028
def start(self):
        ""
        bookname = self.args.get('--bookname', None)
        if not bookname:
            bookname = 'book.md'
        project_dir = self.args.get('<name>', None)
        if not project_dir:
            project_dir = join(self.cwd, 'Book')
        project_dir = abspath(project_dir)

        # create the working dir?
        if not exists(project_dir) or self.args['--overwrite']:
            if exists(project_dir):
                if yesno(warning(
                        'Are you sure you want to remove `%s`? '
                        % project_dir)):
                    shutil.rmtree(project_dir)
                else:
                    sys.exit(error('Operation aborted'))
            os.makedirs(project_dir)
            os.makedirs(join(project_dir, 'build'))
            with codecs.open(
                    join(project_dir, bookname), 'w', encoding="utf") as fd:
                fd.write('''# This is your book
    You can start it right now and publish it away!
    ''')
        # What shall we do with the configuration file?
        config_file = join(project_dir, 'book.json')
        rewrite_config_file = True
        if exists(config_file) and not self.args['--overwrite']:
            print('A config file already exists. This step is skipped')
            rewrite_config_file = False

        if rewrite_config_file:
            with codecs.open(config_file, 'w', encoding="utf") as fd:
                data = {
                    'files': ['%s' % bookname],
                    'author': "%s" % ask("What is your name? "),
                    'title': '%s' % ask("E-book title, please? "),
                }
                data['fileroot'] = unidecode(data['title']).lower() \
                    .replace(' ', '-')
                # pick a generator
                if len(self.generators) == 1:
                    data['generator'] = self.generators[0]
                else:
                    picked_generator = None
                    while not picked_generator:
                        picked_generator = ask(
                            "Which generator? [%s] "
                            % ', '.join(self.generators)
                        )
                        if picked_generator not in self.generators:
                            print warning(
                                'Wrong answer. Please pick one on the list')
                            picked_generator = None
                    # fine, we have one.
                    data['generator'] = picked_generator
                json.dump(data, fd, indent=4, encoding="utf")

        # Game over
        print
        sys.exit(
            success('Now you can go to `%s` and start editing your book...'
                    % project_dir))
586501
def select_directory(self, edit):
        """"""
        basedir = to_text_string(edit.text())
        if not osp.isdir(basedir):
            basedir = getcwd_or_home()
        title = _("")
        directory = getexistingdirectory(self, title, basedir)
        if directory:
            edit.setText(directory)
64090
def read_book_uri_from_console():
    
    db_path: str = input("Enter book_url or leave blank for the default settings value: ")
    if db_path:
        # sqlite
        if db_path.startswith("sqlite://"):
            db_path_uri = db_path
        else:
            # TODO: check if file exists.
            db_path_uri = "file:///" + db_path
    else:
        cfg = settings.Settings()
        db_path_uri = cfg.database_uri

    return db_path_uri
541387
def select(files, start, stop):
    
    if start or stop:
        if start is None:
            start = 0
        if stop is None:
            stop = len(files)
        files = files[start:stop]
    return files
967096
def select_location(self):
        """"""
        location = osp.normpath(getexistingdirectory(self,
                                                     _("Select directory"),
                                                     self.location))

        if location:
            if is_writable(location):
                self.location = location
                self.update_location()
1294870
def select_directory(self):
        """"""
        self.__redirect_stdio_emit(False)
        directory = getexistingdirectory(
                self, _(""), self.path)
        if directory:
            directory = to_unicode_from_fs(osp.abspath(directory))
        self.__redirect_stdio_emit(True)
        return directory
863434
def create_new_cookbook(cookbook_name, cookbooks_home):
    
    cookbooks_home = utils.normalize_path(cookbooks_home)

    if not os.path.exists(cookbooks_home):
        raise ValueError("Target cookbook dir %s does not exist."
                         % os.path.relpath(cookbooks_home))

    target_dir = os.path.join(cookbooks_home, cookbook_name)
    LOG.debug("Creating dir -> %s", target_dir)
    try:
        os.makedirs(target_dir)
    except OSError as err:
        if err.errno != errno.EEXIST:
            raise
        else:
            LOG.info("Skipping existing directory %s", target_dir)

    cookbook_path = os.path.join(cookbooks_home, cookbook_name)
    cookbook = book.CookBook(cookbook_path)

    return cookbook
1150011
def choice_doinst(self):
        
        if "doinst.sh" in self.sbo_files.split():
            doinst_sh = ReadSBo(self.sbo_url).doinst("doinst.sh")
            fill = self.fill_pager(doinst_sh)
            self.pager(doinst_sh + fill)