Пример #1
0
    def build_tree(self):
        """Create directories structure in build directory
        
        The structure is pretty much 'build/content_type/content_name' for the
        main language and 'build/language_code/content_type/content_name' for the others.
        """
        types = ["articles", "authors", "archive"]

        try:
            mkdir(self.build_path)
        except FileExistsError as e:
            pass
        try:
            mkdir(join(self.build_path, "res"))
        except FileExistsError as e:
            pass
        for f in ls(join(self.content_path, "res")):
            cp(join(self.content_path, "res", f),
               join(self.build_path, "res", f))

        for l in self.locales:
            try:
                mkdir(join(self.build_path, l['code']))
            except FileExistsError as e:
                pass
            for t in types:
                try:
                    mkdir(join(self.build_path, l['code'], t))
                except FileExistsError as e:
                    pass
def move_files():
    amp_char_pos = 0
    uscore_char_pos = 0
    person1 = ""
    person2 = ""

    for filename in os.listdir(source_path):
        if filename.endswith(".mp3"):
            if filename.find("&") > 0:  # doubles
                amp_char_pos = filename.find("&")
                uscore_char_pos = filename.find("_")
                person1 = filename[:amp_char_pos]
                person2 = filename[amp_char_pos + 1:uscore_char_pos]

                # copy to person 1
                if not os.path.exists(output_path + "/" + person1):
                    os.makedirs(output_path + "/" + person1)
                cp(source_path + "/" + filename,
                   output_path + "/" + person1 + "/" + filename)

                # move to person 2
                if not os.path.exists(output_path + "/" + person2):
                    os.makedirs(output_path + "/" + person2)
                mv(source_path + "/" + filename,
                   output_path + "/" + person2 + "/" + filename)

            else:  # singles
                uscore_char_pos = filename.find("_")
                person1 = filename[:uscore_char_pos]

                # move to person 1
                if not os.path.exists(output_path + "/" + person1):
                    os.makedirs(output_path + "/" + person1)
                mv(source_path + "/" + filename,
                   output_path + "/" + person1 + "/" + filename)
Пример #3
0
def filecopier(fileset, dirlist, compliantfilepathinput):
    for iterfile in fileset:
        #goes over the set
        filenamedir = iterfile
        characterizingfeature = input(
            "What are you looking for in the text file lines?")
        with open(iterfile, 'r+') as file:
            #passes the item to a list
            trasharray = file.readlines()
            for i in trasharray:
                if characterizingfeature in i:
                    trasharray = i.split('=')
                    itemname = trasharray[1]
                    break
        #specific code that fixes formatting to get the item name and directories to what we want. It's kind of spaghetti since I did incremental changes to the code to produce my result.
        filenamelist = str(filenamedir).split('\\')
        filename = str(filenamelist[int(len(filenamelist) - 1)])
        filenamedir = str(filenamedir)
        filenamedir = filenamedir.strip('\n')
        itemname = itemname.split('\\')
        itemname = itemname[1].strip('\n')
        destdir = str(
            str(compliantfilepathinput) + '\\' + itemname + '\\' + filename)
        destdir = destdir.strip('\n')
        cp(filenamedir, destdir)
Пример #4
0
def replace_header(fname, licence_text, delete_backups):
    # Strip newline
    fname = fname.strip('\n')
    # create backup
    cp(fname, fname + '.bak')
    with open(fname, 'r') as ifh:
        # Split the file into prelude (old licence), and content
        lines = ifh.read().splitlines()
        # Check new licence already present
        if check_lines_for_qflex_licence(lines) is True:
            print("QFlex Licence already found in file", fname)
            return

        idx_begin = index_containing_substring(lines, licence_begin_string)
        idx_end = index_containing_substring(lines, licence_end_string)

        if idx_begin == -1 and idx_end == -1:
            # Prepend
            content = lines
        else:
            # Get rid of old text
            if idx_begin != 0:
                print(
                    'Old copyright block found not at beginning of file! Skipping....',
                    fname)
                return
            content = lines[idx_end + 1:]

        # Add new licence text
        new_content = licence_text + content
        content_with_newlines = [t + '\n' for t in new_content]

    with open(fname, 'w') as ofh:  # truncate
        ofh.writelines(content_with_newlines)
Пример #5
0
def voms_proxy_init(args=''):
    d = dict()

    proc = subprocess.Popen(['/bin/bash'],
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            shell=True)
    cmd = 'voms-proxy-init ' + args
    output = proc.communicate(cmd)[0]

    if len(output) >= 4:
        if len(output) == 5:
            output = output[1:]
        output_lines = output.splitlines()[1::2]
        proxy_path = output_lines[0].replace("Created proxy in ", '')[:-1]
        proxy_expiration = output_lines[1].replace(
            "Your proxy is valid until ", '')
        proxy_expiration_datetime = datetime.strptime(
            proxy_expiration.partition(' ')[2].replace('UTC ', ''),
            '%b %d %H:%M:%S %Y')
        proxy_expiration_timestamp = proxy_expiration_datetime.strftime('%s')

        d['path'] = proxy_path
        d['expiration'] = proxy_expiration_datetime
        d['TS'] = proxy_expiration_timestamp

        cp(proxy_path, '/tmp/fts-voms-proxy')
    else:
        print('FATAL: an error occurred. See below for details:')
        print(output)

    return d
Пример #6
0
def capture():
    camera = cv2.VideoCapture(0)
    ret, image1 = camera.read()
    image = cv2.resize(image1, (640, 360))
    cv2.imwrite("file.jpg", image)

    face_detector = dlib.get_frontal_face_detector()

    detected = face_detector(image, 1)
    camera.release()
    if (detected):
        for i, face_rect in enumerate(detected):
            cv2.rectangle(image, (face_rect.left(), face_rect.top()),
                          (face_rect.right(), face_rect.bottom()), (0, 0, 150),
                          2)

            cv2.imwrite("file1.jpg", image)
            cp(
                'file1.jpg',
                '/Users/sadhvik/Documents/MiniProject/SourceCode/Web/static/InsertImage/file1.jpg'
            )
            os.remove("file1.jpg")
            return True
    else:
        return False
Пример #7
0
	def __init__(self, filepath, parent = None):
		QObject.__init__(self)
		self.setParent(parent)
		self.filepath = filepath

		if not os.path.exists(os.path.dirname(filepath)):
			os.makedirs(os.path.dirname(filepath))

		self.doSave = True
 
		try:
			self.cfg = json.loads(open(filepath).read())
			cp(filepath, filepath + '.bak')
		except Exception as e:
			if os.path.exists(filepath):
				QMessageBox.warning(None, 'Configfile Error', 'Error while parsing the config File. Message is\n\n"%s"' % e)
				self.doSave = False
			else:
				QMessageBox.information(None, 'Config created', 'Configuration file "%s" was created' % filepath)
			self.cfg={}

		self.create(['General'])
		self.create(['Links'])
		self.create(['Plugin'])
		self.saveDelayWidgetBusy(False)
Пример #8
0
def copy_file(oldpath, newpath, ext=''):
    """
    Copy file from oldpath to newpath.
    If file already exists, remove it first.

    Parameters
    ----------
    oldpath: str or path
        A string or a fullpath to a file that has to be copied
    newpath: str or path
        A string or a fullpath to the new destination of the file
    ext: str
        Possible extension to add to the oldpath and newpath. Not necessary.

    Notes
    -----
    Outcome:
    newpath + ext:
        Copies file to new destination
    """
    from shutil import copy as cp

    check_file_exists(oldpath + ext)

    if os.path.isfile(newpath + ext):
        os.remove(newpath + ext)

    cp(oldpath + ext, newpath + ext)
def copy_file(file, path, notespath):
    try:
        cp(f'{path}{file}', os.path.join(notespath, 'resources'))
    except FileNotFoundError:
        print(f'File "{file}" not found in {path}')
        return False
    else:
        return True
Пример #10
0
def new_folder(folder_name):
    if os.path.isdir(folder_name):
        raise ArgumentTypeError("{} already exists".format(folder_name))
    else:
        os.mkdir(folder_name)
        cp(os.path.join(FIXEDPATHS.DEFAULTS, 'workflow.cfg'),
           os.path.join(folder_name, 'hydrant.cfg'))
        return folder_name
Пример #11
0
def copy_file(file, path):
    try:
        cp(f'{path}{file}', 'notes/resource/')
    except FileNotFoundError:
        print(f'File "{file}" not found in {path}')
        return False
    else:
        return True
Пример #12
0
def BACKUP():

    from shutil import copyfile as cp

    cp(_CONST('PATH_DIR') + 'WORDS.parquet', 'WORDS.parquet.bk')
    cp(_CONST('PATH_DIR') + 'MOVIES.parquet', 'MOVIES.parquet.bk')

    exit(0)
Пример #13
0
def main(args):
    ds_name = args.ds_name
    ds_path = join_pth(os.getcwd(), 'data', ds_name)
    dt_path = join_pth(ds_path, 'data_train')
    ds_img_pth = join_pth(ds_path, 'images')
    ds_ans_pth = join_pth(ds_path, 'annots')

    cp(dt_path, ds_img_pth, ignore=ignore_patterns('*.xml'))
    cp(dt_path, ds_ans_pth, ignore=ignore_patterns('*.jpg'))
Пример #14
0
 def setUp(self):
     cp(self.snapshot, self.file)
     try:
         rm(self.lockfile)
     except:
         pass
     try:
         rm(self.txtfile)
     except:
         pass
Пример #15
0
def moveFiles(src_file_path, desination_file_path, log_dest, run_num,
              index_seq):
    if os.path.isfile(src_file_path):
        cp(src_file_path, desination_file_path)
        log_dest = addForwardSlash(log_dest)
        log_file = os.path.join(log_dest, 'copy_log.tsv')
        with open(log_file, 'a+') as cp_log:
            cp_log.write('{}\t{}\t{}\t{}\n'.format(run_num, index_seq,
                                                   src_file_path,
                                                   desination_file_path))
 def setUp(self):
      cp(self.snapshot, self.file)
      try:
           rm(self.lockfile)
      except:
           pass
      try:
           rm(self.txtfile)
      except:
           pass
Пример #17
0
 def copy_file(self, file, local):
     try:
         cp(file, local)
     except FileNotFoundError as e:
         print(type(e))
         print('[WinError 3] O sistema não consegue encontrar o caminho especificado em:\n', file)
         print('Não foi possível copiar o arquivo para:\n', local)
     except PermissionError as e:
         print(type(e))
         print('Permisao de acesso ao diretorio negada')
Пример #18
0
def get(package, path):
    '''
    for this function, package is a package name and path is a directory to put it in
    '''
    # ensure the mountpoint is still mounted
    if not call(['mountpoint', '-q', config['mountpoint']]):
        call(['sshfs', '-oPort=' + config['port'], config['host'], config['mountpoint']])

    # copy the package directory to the new path
    cp(cpnfig['mountpoint'] + '/' + config['basedir'] + '/' + package, path)
def backup_files(directory, watchfile):
    # make the backup folder
    os.mkdir(directory)

    # copy the files to the backup folder
    openfile = open(watchfile, "r")
    files = openfile.read().strip("\n").split("\n")
    for file in files:
        cp(file, directory)
    openfile.close()
Пример #20
0
def copyList(listOfFiles,fromdir,todir):
  if not(listOfFiles): return
  if set(listOfFiles) == listOfFiles: 
    listOfFiles = setToList(listOfFiles)
    #listOfFiles = newListOfFiles
  for file in listOfFiles:
    sourcefile = os.path.join(fromdir,file)
    destfile = os.path.join(todir,file)
    destfolder = os.path.dirname(destfile)
    if not(os.path.isdir(destfolder)): mkdir_better(destfolder)
    cp(sourcefile,destfile)
Пример #21
0
def pickaduiofile():
    filepath = filedialog.askopenfilename(initialdir="~",
                                          title="Select file",
                                          filetypes=(("mp3 files", "*.mp3"),
                                                     ("wav files", "*.wav"),
                                                     ("all files", "*.*")))
    filename, file_extension = os.path.splitext(filepath)
    cp(filepath, "./alarm" + file_extension)
    if file_extension == ".mp3":
        sound = AudioSegment.from_mp3("./alarm.mp3")
        sound.export("./alarm.wav", format="wav")
Пример #22
0
def copy_file(oldpath, newpath, ext=''):
    """
    Copy file from oldpath to newpath.
    If file already exists, remove it first.
    """
    from shutil import copy as cp

    check_file_exists(oldpath + ext)

    if os.path.isfile(newpath + ext):
        os.remove(newpath + ext)

    cp(oldpath + ext, newpath + ext)
Пример #23
0
    def update_settings(key, value) -> None:
        """Creates a dict of settings set by the user and then sends them to envars."""
        s1: Path = pl.get_user_workspace()
        s2: Path = s1 / 'my_settings.yaml'
        cp(s2, s1 / 'my_settings_backup.yaml')
        pair = {key: value}

        with open(s2, 'r') as file_in:
            in_dict = sl(file_in)
        in_dict.update(pair)
        with open(s2, 'w') as file_out:
            dmp(in_dict, file_out)
        ev.setenv(in_dict)
Пример #24
0
 def MakeSeedDirectories(self, sim_dir, yml_file_dict, opts):
     for sn, s in zip(self.sd_names, self.values):
         sd_dir = os.path.join(sim_dir, sn)
         os.mkdir(sd_dir)
         self.obj_r.Set(s)
         CreateYamlFilesFromDict(sd_dir, yml_file_dict)
         if opts.fluid_config: #TODO depricate this for one below
             cp(opts.fluid_config, sd_dir)
         for f in opts.non_yaml:
             cp(f, sd_dir)
         if opts.states:
             for s in opts.states:
                 open(os.path.join(sd_dir, 'sim.{}'.format(s)), 'a')
def move_files(files, base_dir, output_dir):
    for filename in files:
        disaster = filename.split("_")[0]

        # If the output directory and disater name do not exist make the directory
        if not path.isdir(path.join(output_dir, disaster)):
            makedirs(path.join(output_dir, disaster))

        # Check if the images directory exists
        if not path.isdir(path.join(output_dir, disaster, "images")):
            # If not create it
            makedirs(path.join(output_dir, disaster, "images"))

        # Move the pre and post image to the images directory under the disaster name
        cp(path.join(base_dir, "images", filename),
           path.join(output_dir, disaster, "images", filename))
        post_file = filename.replace("_pre_", "_post_")
        cp(path.join(base_dir, "images", post_file),
           path.join(output_dir, disaster, "images", post_file))

        # Check if the label directory exists
        if not path.isdir(path.join(output_dir, disaster, "labels")):
            # If not create it
            makedirs(path.join(output_dir, disaster, "labels"))

        pre_label_file = filename.replace("png", "json")
        # Move the pre and post label files to the labels directory under the disaster name
        cp(path.join(base_dir, "labels", pre_label_file),
           path.join(output_dir, disaster, "labels", pre_label_file))
        post_label_file = pre_label_file.replace("_pre_", "_post_")
        cp(path.join(base_dir, "labels", post_label_file),
           path.join(output_dir, disaster, "labels", post_label_file))
Пример #26
0
def copyfile(src, dst, verbose=True, overwrite=False):
    from shutil import copyfile as cp
    from os.path import exists, realpath
    file_already_exists = exists(dst)
    overwrite = True if not file_already_exists else overwrite
    if (file_already_exists and overwrite) or (not file_already_exists):
        if verbose: alert('Copying: %s --> %s' % (magenta(src), magenta(dst)))
        if file_already_exists:
            alert(yellow('The file already exists and will be overwritten.'))
        cp(src, dst)
    elif file_already_exists and (not overwrite):
        warning(
            'File at %s already exists. Since you have not set the overwrite keyword to be True, nothing will be copied.'
            % red(dst))
Пример #27
0
def _initialize_templates(backup=False):
    default_templates = os.path.join(FIXEDPATHS.DEFAULTS, 'templates.py')
    user_templates = os.path.join(FIXEDPATHS.USERDIR, 'templates.py')
    if backup and os.path.isfile(user_templates):
        templates_bak = user_templates + '.bak'
        logging.info("Backing up %s to %s", user_templates, templates_bak)
        cp(user_templates, templates_bak)
    logging.info('Generating initial templates.py')
    cp(default_templates, user_templates)
    logging.info(
        "%s added. You may edit using python string.Template " +
        "notation:\n\thttps://docs.python.org/3/tutorial/" +
        "stdlib2.html#templating\n" +
        "See doc and comments in the file for details.", user_templates)
Пример #28
0
def _initialize_user_cfg(backup=False):
    user_cfg = os.path.join(FIXEDPATHS.DEFAULTS, 'user.cfg')
    hydrant_cfg = os.path.join(FIXEDPATHS.USERDIR, 'hydrant.cfg')
    if backup and os.path.isfile(hydrant_cfg):
        hydrant_bak = hydrant_cfg + '.bak'
        logging.info("Backing up %s to %s", hydrant_cfg, hydrant_bak)
        cp(hydrant_cfg, hydrant_bak)
    logging.info('Generating initial hydrant.cfg')
    cp(user_cfg, hydrant_cfg)
    logging.info(
        "%s added. You may edit using INI file structure and basic " +
        "interpolation as defined here:\n" +
        "\thttps://docs.python.org/3/library/configparser.html" +
        "#supported-ini-file-structure\nWorkspaces list may be " +
        "defined with commas (Workspaces=ws1,ws2,ws3).", hydrant_cfg)
Пример #29
0
def copy_templates_to_dirs(templates=None, root=None):
    '''
    copies html templates to the templates directory 
    in root from templates
	this creates structure as follows- 
	/app.py
	/templates
		/base.html
		/index.html    
    '''
    cp(join(templates, "app.py"), join(root, "app.py"))
    htmls = ["base.html", "index.html"]
    for html in htmls:
    	temp_path = join("templates", html)
    	cp(join(templates, html), join(root, temp_path))
Пример #30
0
def move_file(file, year, month, day):
	destination = destinationDir + slash + year + slash + month + slash + year + '-' + month + '-' + day + slash
	#print('I would move file %s to dir %s' % (file, destination))
	if not testMode:
		try:
			os.makedirs(destination)
		except Exception, e:
			if verbose:
				print ('error: %s' % e)
				raw_input()
		try:
			shutil.cp(file, destination)
		except Exception, e:
			if verbose:
				print ('error: %s' % e)
				raw_input()
Пример #31
0
def move_file(file, year, month, day):
    destination = destinationDir + slash + year + slash + month + slash + year + '-' + month + '-' + day + slash
    #print('I would move file %s to dir %s' % (file, destination))
    if not testMode:
        try:
            os.makedirs(destination)
        except Exception, e:
            if verbose:
                print('error: %s' % e)
                raw_input()
        try:
            shutil.cp(file, destination)
        except Exception, e:
            if verbose:
                print('error: %s' % e)
                raw_input()
 def _move_to_be_renamed(self, item):
     for file in item:
         for end_with in all_language_dict:
             src = sourece_folder_not_renamed_All + "\\" + file + end_with + ".pdf"
             dest = sourece_folder_renamed_all + "\\" + file + all_language_dict[
                 end_with] + ".pdf"
             try:
                 print(file + all_language_dict[end_with])
                 cp(src, dest)
                 os.remove(src)
             except BaseException:
                 print(file + all_language_dict[end_with])
                 src = sourece_folder_not_renamed_All + "\\" + file + all_language_dict[
                     end_with] + ".pdf"
                 cp(src, dest)
                 os.remove(src)
Пример #33
0
def start_score_evaluation_on_validation_experiment(temp_conf, exp_path, data_path):
    os.makedirs(exp_path, exist_ok=True)

    copytree(join(gitrepo_path, 'denoiseg'), join(exp_path, 'denoiseg'))
    cp(join(gitrepo_path, 'validation_evaluation.py'), exp_path)

    with open(join(exp_path, 'temp.json'), 'w') as f:
        json.dump(temp_conf, f)

    slurm_script = create_slurm_script(exp_path, data_path)
    with open(join(exp_path, 'slurm.job'), 'w') as f:
        for l in slurm_script:
            f.write(l)

    os.system('chmod -R 775 ' + exp_path)

    os.system('sbatch {}'.format(join(exp_path, "slurm.job")))
Пример #34
0
def cfg_user_add(p1: Path) -> None:
    """Add USERNAME and settings path to core_config file for script startup.

    The core_config.yaml file needs to be located in the config dir on the
    script install path.
    New users are added as key:value pairs with envar USERNAME as key,
    and settings dir as value.
    defpaths[0] = core_config.yaml
    defpaths[1] = default_config.yaml
    defpaths[2] = user's settings dir

    Args:
        p1 (path): Abs path to user's settings directory.
    """
    usr = {env['USERNAME']: str(p1)}
    cp(rootdirs['defconf'], (p1 / 'my_settings.yaml'))
    users_dict = safe_open_file(rootdirs['coreconf'])
    users_dict['USER_CFG'].update(usr)
    out = safe_write_file(rootdirs['coreconf'], users_dict)
Пример #35
0
    def start_experiment(exp_conf, exp_path, data_path):
        os.makedirs(exp_path, exist_ok=True)

        copytree(resources_path, exp_path)
        cp(join(resources_path, 'main.py'), exp_path)
        with open(join(exp_path, 'experiment.json'), 'w') as f:
            json.dump(exp_conf, f, sort_keys=True, indent=4)

        singularity_cmd = 'singularity exec -B {}:/notebooks -B {}:/data {} python3 /notebooks/main.py --exp_config ' \
                          '/notebooks/experiment.json'.format(exp_path, data_path, singularity_path)

        slurm_script = create_slurm_script(singularity_cmd)
        with open(join(exp_path, 'slurm.job'), 'w') as f:
            for l in slurm_script:
                f.write(l)
        os.system('chmod -R 775 ' + exp_path)

        # Submit the cluster-job via slurm-script
        os.system('sbatch {}'.format(join(exp_path, 'slurm.job')))
Пример #36
0
def getDefaultResolver():
    from shutil import copy as cp
    if not os.path.isfile("/etc/resolv.conf.orig"):
        cp("/etc/resolv.conf", "/etc/resolv.conf.orig")
    resolvFile = open("/etc/resolv.conf",'r')
    rv = ""
    for line in resolvFile:
        line = line.replace('\n','').strip()
        if line[0] == '#' or len(line) < len("nameserver "):
            continue
        if line[:11] == "nameserver ":
            rv = line[11:]
    resolvFile.close()
    if rv == "":
        log.error("Failed to get default resolver")
        exit(1)
    if rv == "127.0.0.1" or rv == "localhost":
        log.error("Default resolver is localhost: something went wrong")
        exit(1)
    return rv
Пример #37
0
def directoryLink(source_dir,target_dir,assumingLinksWork=True):
  # Some filesystems (FAT 32) do not support hardlinks.  If we're 
  # trying to make a snapshot on one of those drives, it's better
  # to use a real copy than fail utterly.

  for dirpath, dirnames, filenames in os.walk(source_dir):
    new_directory = os.path.join(target_dir,dirpath[1+len(source_dir):])
    if not(os.path.isdir(new_directory)): mkdir_better(new_directory)
    for file in filenames:
      if assumingLinksWork:
        try: os.link(os.path.join(dirpath,file),os.path.join(new_directory,file))
        except:
          # If we get here, then we tried to make a hardlink and could
          # not.  Ask the participant if they 
          assumingLinksWork = False
          if not(tkMessageBox.askyesno("Yes or No","Small snapshots are not possible on this disk. This can happen if the disk is formatted as FAT rather than NTFS. Would you like to make a snapshot anyway? (NOTE: this can take up a LOT of extra disk space.)")):
            return (False,False)
          cp(os.path.join(dirpath,file),os.path.join(new_directory,file))
      else:
        cp(os.path.join(dirpath,file),os.path.join(new_directory,file))
  return (assumingLinksWork,True)
Пример #38
0
def copy_data(pkgname, target):
    """ Copy files of package to target folder
    """
      
    with open(path.join(dpkg_info, pkgname + '.list')) as f:
        lst = f.readlines()
    
    for fn in lst:
        fn = fn.strip()
        if path.exists(fn):
            # file/folder of package exist
            if path.isdir(fn):
                if not path.exists(path.join(target, fn[1:])):
                    # create target folder if necessary
                    mkdir(path.join(target, fn[1:]))
            else:
                try:
                    cp(fn, path.join(target, fn[1:]))
                except OSError as e:
                    print e
                except IOError as e:
                    print e
        else:
            print 'path not found: %s' % fn
    
    if not path.exists(path.join(target, script_folder)):
        mkdir(path.join(target, script_folder))
    
    for fn in filter(lambda x: x.startswith(pkgname), listdir(dpkg_info)):
        try:
            if not fn.endswith('.list'):
                cp(path.join(dpkg_info, fn), path.join(target, script_folder, fn.split('.')[1]))
        except OSError as e:
            print e
        except IOError as e:
            print e

    # copy control information
    with open(path.join(target, script_folder, 'control'), 'w') as f:
        f.write(_extract_control(pkgname))
Пример #39
0
def store(path, PKGBUILD):
    '''
    This function takes a path and a PKGBUILD string and moves it to its proper place in
    the storage subsystem.
    '''
    # ensure the mountpoint is still mounted
    if not call(['mountpoint', '-q', config['mountpoint']]):
        call(['sshfs', '-oPort=' + config['port'], config['host'], config['mountpoint']])

    # delete whats already there
    if exists(config['mountpoint'] + '/' + config['basedir'] + '/' + path.split('/')[-1]):
        rm(config['mountpoint'] + '/' + config['basedir'])

    # move the new stuff over
    cp(path, config['mountpoint'] + '/' + config['basedir'] + '/' + path.split('/')[-1])

    # put the PKGBUILD in the new directory
    with open(config['mountpoint'] + '/' +  config['basedir'] + '/' + path.split('/')[-1] + '/' + 'PKGBUILD', 'w') as f:
        f.write(PKGBUILD)

    # process the PKGBUILD for name and version info
    procPkgInfo(PKGBUILD):
Пример #40
0
Файл: stag.py Проект: noah/stag
 def init(self, argv):
     mkdir_p(path.join( BASE_PATH, "_output"))
     mkdir_p(path.join( BASE_PATH, "_posts"))
     mkdir_p(path.join( BASE_PATH, "_assets"))
     mkdir_p(path.join( BASE_PATH, "_templates"))
     cp(path.join(STAG_PATH, "_templates", "index.html"), TEMPLATE_PATH)
     cp(path.join(STAG_PATH, "_templates", "archive.html"), TEMPLATE_PATH)
     cp(path.join(STAG_PATH, "_templates", "base.html"), TEMPLATE_PATH)
     cp(path.join(STAG_PATH, "_templates", "post.html"), TEMPLATE_PATH)
     cp(path.join(STAG_PATH, "_templates", "post.skel"), TEMPLATE_PATH)
     cp(path.join(STAG_PATH, "stag.default.cfg"), path.join(BASE_PATH, "stag.cfg"))
     open(path.join(TEMPLATE_PATH, "ga.js"), 'w')
Пример #41
0
	def cp(self, f): shutil.cp(self.path, f)
	
	def extract_columns(self, line, keys, dtype=unicode):
Пример #42
0
    buildclient.send(__yoursta__ + "\n")
    buildclient.send(__yourtown__ + "\n")
    buildclient.send(__yourcom__ + "\n")
    buildclient.send(__yourdep__ + "\n")
    buildclient.send("\n")  # Defaults to the keyname
    buildclient.send(__yourname__ + "\n")
    buildclient.send(__yourmail__ + "\n")
    buildclient.send(clients[client]["password"] + "\n")
    buildclient.send("\n")
    buildclient.send("y\n")
    buildclient.send("y\n")
    while buildclient.poll() is None:
        sleep(0.1)
    if not exists(getcwd() + "/keyboundles/client/" + client + "/"):
        makedirs(getcwd() + "/keyboundles/client/" + client + "/")
    cp(getcwd() + "/keys/ca.crt", cwd + "/keyboundles/client/" + client + "/")
    # cp(cwd + '/dh*', cwd + '/keyboundles/server/')
    cp(getcwd() + "/keys/" + client + ".crt", cwd + "/keyboundles/client/" + client + "/")
    cp(getcwd() + "/keys/" + client + ".key", cwd + "/keyboundles/client/" + client + "/")
    cp(getcwd() + "/ta.key", cwd + "/keyboundles/client/" + client + "/")

    cliconf["cert"] = client + ".crt"
    cliconf["key"] = client + ".key"
    cliconf["dev"] = "tap"
    cliconf["remote"] = server_addr + " 1194"
    if clients[client]["platform"] == "windows":
        cliconf["dev-node"] = '"Local Area Connection 2"'
    clientConf = packConf(cliconf)
    with open(cwd + "/keyboundles/client/" + client + "/client.ovpn", "w") as fh:
        fh.write(clientConf)
Пример #43
0
def main():
    """ Main routine """
    parser = argparse.ArgumentParser(description='Calculate the band structure of a vasp calculation.')
    parser.add_argument('-d', '--density', nargs='?', default=10, type=int,
                        help='k-point density of the bands (default: 10)')
    parser.add_argument('-s', '--sigma', nargs='?', default=0.04, type=float,
                        help='SIGMA value in eV (default: 0.04)')
    parser.add_argument('-l', '--linemode', nargs='?', default=None, type=str,
                        help='linemode file')
    parser.add_argument('-v', '--vasp', nargs='?', default='vasp', type=str,
                        help='vasp executable')
    args = parser.parse_args()
    
    line_density = args.density
    line_file = args.linemode

    # Check that required files exist
    _check('vasprun.xml')
    _check('INCAR')
    _check('POSCAR')
    _check('POTCAR')
    _check('CHGCAR')

    # Get IBZ from vasprun
    vasprun = Vasprun('vasprun.xml')
    ibz = HighSymmKpath(vasprun.final_structure)

    # Create a temp directory
    print('Create temporary directory ... ', end='')
    tempdir = mkdtemp()
    print(tempdir)

    # Edit the inputs
    print('Saving new inputs in temporary directory ... ')
    incar = Incar.from_file('INCAR')
    print('Making the following changes to the INCAR:')
    print('  ICHARG = 11')
    print('  ISMEAR = 0')
    print('  SIGMA = %f' % args.sigma)
    incar['ICHARG'] = 11  # Constant density
    incar['ISMEAR'] = 0  # Gaussian Smearing
    incar['SIGMA'] = args.sigma  # Smearing temperature
    incar.write_file(os.path.join(tempdir, 'INCAR'))
    # Generate line-mode kpoint file

    if line_file is None:
        print('Creating a new KPOINTS file:')
        kpoints = _automatic_kpoints(line_density, ibz)
        kpoints.write_file(os.path.join(tempdir, 'KPOINTS'))
        print('### BEGIN KPOINTS')
        print(kpoints)
        print('### END KPOINTS')
    else:
        cp(line_file, os.path.join(tempdir, 'KPOINTS'))
    
    # Copy other files (May take some time...)
    print('Copying POSCAR, POTCAR and CHGCAR to the temporary directory.')
    cp('POSCAR', os.path.join(tempdir, 'POSCAR'))
    cp('POTCAR', os.path.join(tempdir, 'POTCAR'))
    cp('CHGCAR', os.path.join(tempdir, 'CHGCAR'))

    # cd to temp directory and run vasp
    path = os.getcwd()
    os.chdir(tempdir)
    print('Running VASP in the temporary directory ...')
    try:
        check_call(args.vasp)
    except CalledProcessError:
        print('There was an error running VASP')
        _clean_exit(path, tempdir)

    # Read output
    vasprun = Vasprun('vasprun.xml')
    ibz = HighSymmKpath(vasprun.final_structure)
    _, _ = ibz.get_kpoints(line_density)
    bands = vasprun.get_band_structure()
    print('Success! Efermi = %f' % bands.efermi)
    
    # Backup vasprun.xml only
    print('Making a gzip backup of vasprun.xml called bands_vasprun.xml.gz')
    zfile = os.path.join(path, 'bands_vasprun.xml.gz')
    try:
        with gzip.open(zfile, 'wb') as gz, open('vasprun.xml', 'rb') as vr:
            gz.writelines(vr)
    except (OSError, IOError):
        print('There was an error with gzip')
        _clean_exit(path, tempdir)

    # Return to original path
    os.chdir(path)

    # Write band structure
    
    # There may be multiple bands due to spin or noncollinear.
    for key, item in bands.bands.items():
        print('Preparing bands_%s.csv' % key)
        
        kpts = []

        # Get list of kpoints
        for kpt in bands.kpoints:
            kpts.append(kpt.cart_coords)
        
        # Subtract fermi energy
        print('Shifting energies so Efermi = 0.')
        band = numpy.array(item) - bands.efermi

        # Prepend kpoint vector as label
        out = numpy.hstack([kpts, band.T])
        
        final = []
        lastrow = float('inf') * numpy.ones(3)
        for row in out:
            if numpy.linalg.norm(row[:3] - lastrow) > 1.e-12:
                final.append(row)
            lastrow = row[:3]

        # Write bands to csv file.
        print('Writing bands_%s.csv to disk' % key)
        with open('bands_%s.csv' % key, 'w+') as f:
            numpy.savetxt(f, numpy.array(final), delimiter=',', header=' kptx, kpty, kptz, band1, band2, ... ')

    # Delete temporary directory
    _clean_exit(path, tempdir, 0)
Пример #44
0
 def run(self):
     a=cpl(self.pyf)
     a=cp(a,a.replace('__pycache__\\', '').replace('.cpython-36',''))
     print(a)
     return input()
Пример #45
0
simulation_name = os.path.splitext(sys.argv[1])[0]

try:
    os.makedirs(simulation_name)
except OSError:
    print("directory {} already exists".format(os.path.splitext(sys.argv[1])[0]))

worker = os.path.join("worker.py")
shared = os.path.join("Shared_mixed_leaf_first.py")
go_oculus = os.path.join("..", "oculus", "go_oculus.sh")
oculus_alloc = os.path.join("..", "oculus", "oculus_alloc.sh")
go_arminius = os.path.join("..", "arminius", "go_arminius.sh")
arminius_alloc = os.path.join("..", "arminius", "arminius_alloc.sh")
go_pool = os.path.join("..", "pool", "go.sh")
pool_alloc = os.path.join("..", "pool", "pool_alloc.sh")
get_job = os.path.join("get_job_from_server.py")

cp(worker, os.path.join(simulation_name, "worker.py"))
cp(shared, os.path.join(simulation_name, "Shared.py"))
cp(go_oculus, os.path.join(simulation_name, "go_oculus.sh"))
cp(go_arminius, os.path.join(simulation_name, "go_arminius.sh"))
cp(go_pool, os.path.join(simulation_name, "go.sh"))
cp(oculus_alloc, os.path.join(simulation_name, "oculus_alloc.sh"))
cp(arminius_alloc, os.path.join(simulation_name, "arminius_alloc.sh"))
cp(pool_alloc, os.path.join(simulation_name, "pool_alloc.sh"))
cp(get_job, os.path.join(simulation_name, "get_job_from_server.py"))

cp(sys.argv[1], os.path.join(simulation_name, "ThisGame.py"))
os.makedirs(os.path.join(simulation_name, "outputs"))
Пример #46
0
def main(path,folder,modulation,ID) : # Explore all files contains in this folder and its subfolders and save them under the right name in the specified folder

    #pattern = re.compile(r"*"+re.escape(modulation.lower())+r"*")


    if (os.path.exists(path) and os.path.exists(folder)) :
        files = os.listdir(path)
        for elt in files :
            if os.path.isfile(path+"/"+elt) : # treat this file
                print("ELT",elt)
                
                if not (elt.endswith(".jpg") or elt.endswith(".bmp") or elt.endswith(".png") or elt.endswith(".wav") or elt.endswith(".iq") or elt.endswith(".data")) :
                    print("Unsupported format - Error.\n")
                    next

                elif elt[:9] == "info_freq":
                    print("Unsupported file because of axis - Error.\n")
                    next

                elif  re.match(r"(\w)*"+re.escape(modulation.lower())+"(\w)*",elt.lower()) is None :
                    print("Wrong modulation type: ignoring file - Error.\n")
                    next

                else :

                    name = str(modulation) # Start with the modulation information

                    ID+=1
                    name += "_"+"0"*(6-len(str(ID)))+str(ID) # Complete with updated ID

                    
                    freq = elt.split("_")
                    try :
                        freq = int(freq[0])
                        #print("Alright",freq)
                    except ValueError :
                        freq = "X"*4
                        u = "Hz"
                        print("Name format unknown - Error.\n")

                    if freq != "X"*4 :

                        if floor(freq/10**3) == 0 :
                            u = "Hz"
                        elif floor(freq/10**6) == 0 :
                            freq = floor(freq/10**3)
                            u = "kHz"
                        elif floor(freq/10**9) == 0 :
                            freq = floor(freq/10**6)
                            u = "MHz"
                        elif floor(freq/10**12) == 0 :
                            freq = floor(freq/10**9)
                            u = "GHz"
                        elif floor(freq/10**15) == 0 :
                            freq = floor(freq/10**12)
                            u = "THz"
                        else :
                            print("Unknown frequency - Error.\n")
                            next

                    name += "_"+str(freq)+u

                    E = path.split("/")
                    E = E[len(E)-1]
                    E = E.split("_") # We get environment description

                    if len(E) == 2 :

                        R = E[1]
                        E = E[0]

                        if E == "Mer" :
                            name += "_Me"
                        elif E == "Montagne" :
                            name += "_Mo"
                        elif E == "Rural" :
                            name += "_Ru"
                        elif E == "Urbain" :
                            name += "_Ur"
                        else :
                            print("Unknown environment - Error.\n")
                            next

                        if R == "Fixe" :
                            name += "F"
                        elif R == "Mobile" :
                            name += "M"
                        elif R == "Aerien" :
                            name += "A"
                        else :
                            print("Unknown receiver type - Error.\n")
                            next

                    else :
                        name += "_XxX"
                        print("Name format unknown - Error.\n")


                    F = elt.split(".") # And the format of the file
                    F = F[len(F)-1]
                    name += "."+F

                    cp(os.path.abspath(path)+"/"+elt,os.path.abspath(folder)+"/"+name) # Copying the file to the save folder with the new name
                    print("Renamed "+name+"\n")


            elif os.path.isdir(path+"/"+elt) : # explore this folder
                print("Exploring "+elt+"...")
                ID = main(path+"/"+elt,folder,modulation,ID)

    else :
        print("Wrong path - Error.\n")
        #sys.exit()

    return ID
Пример #47
0
def setup_copydata():
    cp('data/activity_level.csv', '.')
    cp('data/in_data.csv', '.')
    cp('data/tremor_score.csv', '.')
    cp('data/activity_times1.csv', '.')
    cp('data/activity_times2.csv', '.')
Пример #48
0
import os
import tarfile
import sys
import glob

from shutil import copyfile as cp
from time import time

if __name__ == '__main__':

    folderFiles = glob.glob(sys.argv[1] + '/*')
    start = time()
    tar = tarfile.open("tartest.tar", "w")
    for filename in folderFiles:
        tar.add(filename)
    tar.close()
    creation = time() - start
    cp(sys.argv[2], sys.argv[3])
    copyTime = time() - creation - start

    untar = tarfile.open("tartest.tar")
    untar.extractall()
    untar.close()

    extractTime = time() - copyfile - creation - start

    print(creation, copyTime, extractTime)
Пример #49
0
def main(folderToExplore,TrainPerc,TestPerc,ValidPerc) :

    if os.path.exists(folderToExplore) :

        if float(TrainPerc)+float(TestPerc)+float(ValidPerc) != float(1.0) :
            print("Wrong Percentages - Fatal Error.\n")
            sys.exit()
            return

        TrainFolder = folderToExplore+"Entrainement/"
        TestFolder = folderToExplore+"Test/"
        ValidFolder = folderToExplore+"Validation/"


        for elt in [TrainFolder,TestFolder,ValidFolder] :

            if not os.path.exists(elt) :
                os.mkdir(elt)
            


        files = os.listdir(folderToExplore)
        files2 = list()
        for elt in files :
            if len(elt) != 0 and (elt.endswith(".bmp") or elt.endswith(".jpg")):
                files2.append(elt)


        nbTraining = floor(float(TrainPerc)*len(files2))
        nbTest = floor(float(TestPerc)*len(files2))
        nbValidation = len(files2) - (nbTraining + nbTest)


        #treated = list()

        treated = 0
        indexes = list(range(0,len(files2)))
        shuffle(indexes)


        for k in range(0,3) :

            if k == 0 :
                N = nbTraining
                Folder = TrainFolder
            if k == 1 :
                N = nbTraining + nbTest
                Folder = TestFolder
            if k == 2 :
                N = nbTraining + nbTest + nbValidation
                Folder = ValidFolder

            """
            while len(treated) < N :
                
                TREATED = False
                i = randint(0,len(files2)-1)
                for elt in treated :
                    if elt == i :
                        TREATED = True

                while TREATED == True :
                    TREATED = False
                    i = randint(0,len(files2)-1)
                    for elt in treated :
                        if elt == i :
                            TREATED = True
               
                #print(i)

                cp(folderToExplore+"/"+files2[i],Folder+files2[i])

                treated.append(i)

                print(str(len(treated))+"/"+str(len(files2)))
                """            
                
            #treated = 0
            while (treated < N and len(indexes) != 0) :
                
                i = indexes.pop()
                cp(folderToExplore+"/"+files2[i],Folder+files2[i])
                treated += 1

                print(str(treated)+"/"+str(len(files2)))

    else :
        print("Wrong Path - Fatal Error.\n")
        sys.exit()

    return
Пример #50
0
            a = c.execute('INSERT INTO Game ("name", "description", "romCollectionId", "publisherId", "yearId", "developerId", "launchCount", "isFavorite") VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)', (title + title_addon + version, notes, str(collection_ids[collection_translation[platform]]), publisher_id, year_id, developer_id, 0, 0))
            conn.commit()
            commited = True
        except:
            counter = counter + 1
            version = " (Copy " + str(counter) + ")"
            print "failed"
        if counter > 25:
            break
    a = c.execute('SELECT id FROM Game WHERE name = ? and romCollectionId = ?', (title + title_addon + version, str(collection_ids[collection_translation[platform]])))
    game_id = c.fetchall()[0][0]
    a = c.execute('INSERT INTO File ("name", "fileTypeId", "parentId") VALUES ( ?, ?, ?)', (os.path.abspath(path), 0, game_id))
    for genre_id in genre_ids:
        a = c.execute('INSERT INTO GenreGame ("genreId", "gameId") VALUES ( ?, ?)', (genre_id, game_id))
    conn.commit()
    if not os.path.isdir(output_directory + "\\"  + platform_path):
        os.makedirs(output_directory + "\\"  + platform_path)
    for type in image_types:
        if not os.path.isdir(output_directory + "\\"  + platform_path + "\\" + type):
            os.makedirs(output_directory + "\\"  + platform_path + "\\" + type)
        if type == "Screenshot" or type == "Fanart":
            modifier = "-01"
        else:
            modifier = ""
        if os.path.isfile(images_path + platform_path + "\\" + type + "\\" + title_filename + modifier + ".jpg"):
            cp(images_path + platform_path + "\\" + type + "\\" + title_filename + modifier + ".jpg", output_directory + platform_path + "\\" + type + "\\" + os.path.splitext(rom_filename)[0] + ".jpg")
        if os.path.isfile(images_path + platform_path + "\\" + type + "\\" + title_filename + modifier + ".png"):
            cp(images_path + platform_path + "\\" + type + "\\" + title_filename + modifier + ".png", output_directory + platform_path + "\\" + type + "\\" + os.path.splitext(rom_filename)[0] + ".png")

conn.close()
Пример #51
0
#!/usr/bin/python
import os
from os import mkdir
from shutil import copy as cp
os.system("rm -rf gnome-panel-extensions-0.0.2")

mkdir("gnome-panel-extensions-0.0.2")


mkdir("gnome-panel-extensions-0.0.2/container")
cp("container/extension_container_applet.py","gnome-panel-extensions-0.0.2/container")
cp("container/GNOME_ExtensionContainer.server", "gnome-panel-extensions-0.0.2/container")
cp("container/extension_puzzle.svg", "gnome-panel-extensions-0.0.2/container")

mkdir("gnome-panel-extensions-0.0.2/container/panel_extension")
filenames = os.listdir("container/panel_extension")
for name in filenames:
    if name.endswith(".py"):
        cp("container/panel_extension/"+name,"gnome-panel-extensions-0.0.2/container/panel_extension")



mkdir("gnome-panel-extensions-0.0.2/mime")
cp("mime/gpe.xml", "gnome-panel-extensions-0.0.2/mime")
cp("mime/gpe-installer", "gnome-panel-extensions-0.0.2/mime")
cp("mime/gpe-installer.desktop","gnome-panel-extensions-0.0.2/mime")



mkdir("gnome-panel-extensions-0.0.2/gebb")
cp("gebb/gebb", "gnome-panel-extensions-0.0.2/gebb")
def crem(t,lbl,name,tid,pid,end):
    f_name = join(datadir, "_".join([name, tid, pid, end]))
    t_name = join(new_dir, t, lbl, "_".join([name, tid, pid, end]))
    cp(f_name, t_name)
Пример #53
0
dh = interact('./bs.sh build-dh')
while dh.poll() != 0:
	sleep(0.1)


cwd = getcwd()
keydir="/usr/share/doc/openvpn/examples/easy-rsa/2.0/keys"
if not exists(cwd + '/keys/server/'):
	makedirs(cwd + '/keys/server/')
if not exists(cwd + '/keys/client/logserver/'):
	makedirs(cwd + '/keys/client/logserver/')
if not exists(cwd + '/keys/client/logclient/'):
	makedirs(cwd + '/keys/client/logclient/')

cp(keydir + '/ca.crt', cwd + '/keys/server/')
cp(keydir + '/ca.key', cwd + '/keys/server/')
cp(keydir + '/dh1024.pem', cwd + '/keys/server/')
cp(keydir + '/vpnserver.crt', cwd + '/keys/server/')
cp(keydir + '/vpnserver.key', cwd + '/keys/server/')

cp(keydir + '/ca.crt', cwd + '/keys/server/')
#cp(keydir + '/dh*', cwd + '/keys/server/')
cp(keydir + '/logserver.crt', cwd + '/keys/client/logserver/')
cp(keydir + '/logserver.key', cwd + '/keys/client/logserver/')

cp(keydir + '/ca.crt', cwd + '/keys/server/')
#cp(keydir + '/dh*', cwd + '/keys/server/')
cp(keydir + '/logclient.crt', cwd + '/keys/client/logclient/')
cp(keydir + '/logclient.key', cwd + '/keys/client/logclient/')
Пример #54
0
    def __call__(self, z):
        """
        This is the  function which should be called  by the processes
        for mapping and so on If wanted it changes the current working
        directory/back  and copies  starting files,  when  called, the
        result is  given back as  a list and contain  only derivatives
        for the elements which are True in self.mask
        """
        num, x = z
        # of the current Process
        if not self.workhere:
            wx = "Geometrycalculation%s" % (str(num))

            if not path.exists(wx):
                mkdir(wx)
            chdir(wx)
            print "FWRAPPER: Entering working directory:", wx

        # if there  is a startingdirectory  named, now is the  time to
        # have a look, if there is something useful inside
        if self.start is not None and path.exists(self.start):
             wh = getcwd()
             # in RESTARTFILES are the names  of all the files for all
             # the quantum chemistry calculators useful for a restart
             for singfile in RESTARTFILES:
                # copy every  one of them,  which is available  to the
                # current directory
                try:
                   filename = self.start + "/" + singfile
                   cp(filename,wh)
                   print "FWRAPPER: Copying start file",filename
                except IOError:
                   pass

        # the actual call of the original function
        res = self.fun.fprime(x)
        res = (res.flatten()).tolist()

        # if  the  startingdirectory does  not  exist  yet  but has  a
        # resonable name, it now can be created
        if self.start is not None and not path.exists(self.start):
             try:
                 # Hopefully the next line is thread save
                 mkdir(self.start)
                 # if this  process was alowed to  create the starting
                 # directory it can also  put its restartfiles in, the
                 # same thing than above but in the other direction
                 wh = getcwd()
                 for singfile in RESTARTFILES:
                     try:
                          filename = wh + "/" + singfile
                          cp(filename, self.start)
                          print "FWRAPPER: Storing file",filename,"in start directory"
                          print self.start, "for further use"
                     except IOError:
                          pass
             except OSError:
                 print "FWRAPPER: not make new path", wx

        # it is safer to return  to the last working directory, so the
        # code does not affect too many things
        if not self.workhere:
            chdir(self.wopl)
        # the result of the function call:
        return res
Пример #55
0
	def cp(self, f): 
		shutil.cp(self.path, f)