def forward(self, bt):
     if self.dim == 1:
         return self.l1_norm(bt, self.reduction)
     if self.dim == 2:
         return self.l2_norm(bt, self.reduction, self.norm_axis,
                             self.apply_tanh)
     os.error("unknown dimension")
예제 #2
0
def CloneRepo(repo, username, password):
    try:
        git.exec_command('clone', '{}'.format(repo), 'repo', cwd="{}".format(new_repo_path))
    except Exception as e:
        os.error(e)
        print(e)
        exit(100) # 100 Error means failed to clone repo
예제 #3
0
 def get_wave_trig_pos(self, trig_delay, wave_length, count):
     ## 返回触发序列输出的触发的位置
     if trig_delay < 0 or trig_delay > 255:
         print('延时值越界:{}'.format(0))
         os.error('延时值越界:{}'.format(0))
     trig_pos = (count + trig_delay - 45) * 8
     return wave_length + trig_pos
예제 #4
0
def plot_physio_cmrr(time, trigger_start_times, trigger_end_times, physio_sig, acq_window, out_fname):

    if trigger_start_times.shape[0] != trigger_end_times.shape[0]:
        os.error("ERROR: Number of start and end times are different.")

    fig = plt.figure("CMRR physiolog signal", figsize=(30, 20))

    plt.plot(time, physio_sig, '+-', label='physio signal', color='b')

    # add vertical rectangle for each trigger signal and add acquisition window
    for i_trig in range(trigger_start_times.shape[0]):
        plt.axvspan(trigger_start_times[i_trig], trigger_start_times[i_trig] + acq_window, facecolor='orange', alpha=0.15, label='acquisition window' if i_trig == 0 else "_nolegend_")
        plt.axvspan(trigger_start_times[i_trig], trigger_end_times[i_trig], facecolor='g', alpha=0.25, label='trigger signal' if i_trig == 0 else "_nolegend_")

    # # add vertical lines for trigger start and end
    # for t_start, t_end in zip(trigger_start_times, trigger_end_times):
    #     plt.axvline(x=t_start, color='g')
    #     plt.axvline(x=t_end, color='r')
    #     plt.text(t_start, 1000, 'Trigger period = '+str(t_end-t_start)+'ms', rotation=90)

    plt.legend()
    plt.xlabel('Time (ms)')
    plt.ylabel('Physio signal')

    plt.show(block=False)

    fig.savefig(out_fname+'_plot.pdf')
def do_copy(source_filepath, dest_directory):
    source_list = glob.glob(source_filepath)

    if source_list == []:
        # [TODO] Change these to 'error:' to trigger Xcode build failurees.  Need more time to fix the failures - so warnings only now.
        print '  warning: Files were specified to copy, but the files did not exist.'
        print '  warning:   In script:'
        print '  warning:      ' + os.path.normpath(os.path.abspath(__file__))
        print '  warning:    Files that were not found:'
        print '  warning:      ' + source_filepath
        print ''
        os.error(-1)

    for source_item in source_list:

        # we globbed at the start so we could accept wildcard syntax (to get *.nib, *.framework, etc)
        # which in turn will product folders with contents, etc.
        if os.path.isdir(source_item):
            # get the leaf folder name so we can create it
            dest_dir_name = os.path.split(source_item)[1]
            dest_directory_plus_leaf_dir = os.path.join(
                dest_directory, dest_dir_name)
            makedirs(dest_directory_plus_leaf_dir)
            copy_all_in_directory(source_item, dest_directory_plus_leaf_dir)
        else:
            if not os.path.exists(source_item):
                print 'Error copying file or directory', source_fullpath
                os.error(-1)
            makedirs(dest_directory)
            source_filename = os.path.split(source_item)[1]
            dest_filepath = os.path.join(dest_directory, source_filename)
            do_copy_file(source_item, dest_filepath)
예제 #6
0
def write(my_tree):
    if isinstance(my_tree, etree._ElementTree):
        f = open("XMLD.xml", "wb")
        f.write(etree.tostring(my_tree, pretty_print=True))
        f.close()
    else:
        os.error("Given argument is not object of class etree")
예제 #7
0
def CreateBranch(branch_name):
    try:
        git.exec_command('checkout', '-B',  '{}'.format(branch_name), cwd="{}/repo".format(new_repo_path))
    except Exception as e:
        print(e)
        os.error(e)
        exit(200)
예제 #8
0
파일: pyerector.py 프로젝트: arcege/pwdb
 def run(self):
     from fnmatch import fnmatch
     from os.path import exists, join, isdir, normpath
     import os
     if self.args:
         srcdir, dstdir = self.args
     else:
         srcdir, dstdir = self.srcdir, self.dstdir
     if not srcdir or not exists(self.join(srcdir)):
         raise os.error(2, "No such file or directory: " + str(srcdir))
     elif not isdir(self.join(srcdir)):
         raise os.error(20, "Not a directory: " + str(srcdir))
     copy_t = Copy()
     mkdir_t = Mkdir()
     copy_t.noglob = True
     dirs = [os.curdir]
     while dirs:
         dir = dirs[0]
         del dirs[0]
         if self.check_exclusion(dir):
             mkdir_t(normpath(self.join(dstdir, dir)))
             for fname in os.listdir(self.join(srcdir, dir)):
                 if self.check_exclusion(fname):
                     spath = self.join(srcdir, dir, fname)
                     dpath = self.join(dstdir, dir, fname)
                     if isdir(spath):
                         dirs.append(join(dir, fname))
                     else:
                         copy_t(spath, dpath)
예제 #9
0
def CommitChanges(branch_name):
    try:
        git.exec_command('add', '.', cwd="{}/repo".format(new_repo_path))
        git.exec_command('commit','-m "Updating Instance type via automation"', cwd="{}/repo".format(new_repo_path), env=commit_env)
    except Exception as e:
        os.error(e)
        exec(300)
예제 #10
0
def chdir(patch, path):
    """Change the current working directory to path."""
    global CWD
    ap = os.path.abspath(os.path.join(CWD, path))
    manager = get_manager()
    fsi, relpath, readonly = manager.get_fsi(ap)
    if fsi is None:
        if not os.path.exists(ap):
            raise os.error(
                "[Errno 2] No such file or directory: '/{p}/'".format(p=path))
        elif not os.path.isdir(ap):
            raise os.error("[Errno 20] Not a directory: '{p}'".format(p=path))
        else:
            CWD = ap
            _org_chdir(ap)
            # reset paths
            for p, fs, readonly in manager.get_mounts():
                try:
                    fs.cd("/")
                except:
                    pass
    else:
        try:
            fsi.cd(relpath)
            CWD = ap
        except IsFile:
            raise os.error("[Errno 20] Not a directory: '{p}'".format(p=path))
        except OperationFailure:
            raise os.error(
                "[Errno 2] No such file or directory: '/{p}/'".format(p=path))
예제 #11
0
def remove(patch, path):
    """
	Remove (delete) the file path.
	If path is a directory, OSError is raised; see rmdir() below to remove
	a directory.
	This is identical to the unlink() function documented below.
	On Windows, attempting to remove a file that is in use causes an
	exception to be raised; on Unix, the directory entry is removed but the
	storage allocated to the file is not made available until the original
	file is no longer in use.
	"""
    ap = os.path.abspath(os.path.join(CWD, path))
    manager = get_manager()
    fsi, relpath, readonly = manager.get_fsi(ap)
    if fsi is None:
        return _org_remove(relpath)
    elif readonly:
        raise IOError("[Errno 1] Operation not permitted: '{p}'".format(p=ap))
    else:
        # FSI.remove() works on both files and dirs, we need to check
        # this before and raise an Exception if required
        if os.path.isdir(relpath):
            raise os.error(
                "OSError: [Errno 21] Is a directory: '{p}'".format(p=ap))
        try:
            return fsi.remove(relpath)
        except OperationFailure as e:
            raise os.error(e.message)
예제 #12
0
def daddent(img, dp, daddr, name, addr):
    flag = False
    addrs = 0
    j = 0
    daddr = (IB + daddr // IPB) * 1024 + (daddr % IPB) * 64
    for i in range(0,
                   int.from_bytes(dp[8:12], "little") + SIZE_DE - 1, SIZE_DE):
        addrs, de = iread(img, dp, daddr, SIZE_DE, i)
        for j in range(0, BSIZE, SIZE_DE):
            if int.from_bytes(de[j:2 + j], "little") == 0:
                flag = True
                break
            if (name.replace('\x00', "") == de[2 + j:16 + j].decode().replace(
                    '\x00', "")):
                os.error("daddent: {0}: exists".format(name))
                return -1
        if flag:
            break
    for i in range(14 - len(name)):
        name += "\0"
    j //= SIZE_DE
    img[daddr + 8:daddr +
        12] = (int.from_bytes(img[daddr + 8:daddr + 12], "little") +
               16).to_bytes(4, "little")
    img[addrs * BSIZE + j * SIZE_DE + 2:addrs * BSIZE + j * SIZE_DE +
        16] = name.encode()
    img[addrs * BSIZE + j * SIZE_DE:addrs * BSIZE + j * SIZE_DE +
        2] = addr.to_bytes(2, "little")

    if name.replace('\x00', "") != ".":
        addr = (IB + addr // IPB) * 1024 + (addr % IPB) * 64
        img[addr + 6:addr +
            8] = (int.from_bytes(img[addr + 6:addr + 8], "little") +
                  1).to_bytes(2, "little")
    return 0
예제 #13
0
 def plot_each_series_misfit(self,logfile,**args):
     #Check to see if a cutoff has been specified in the function's arguments
     try: cutoff = args['cutoff']
     except KeyError: cutoff = 2   # if there is no 'cutoff' key, then use the default (2)
     try: cseries = args['series']
     except KeyError: os.error('Missing "series" arg\n')   # if there is no 'seris' key, then error out
     try: subf = args['subf']
     except KeyError: os.error('Missing "subf" arg\n')   # if there is no 'subf' key, then error out
     logfile.write('\n############\n#Running {0} with cutoff of {1}\n############\n'.format(cseries,cutoff))
     logfile.write('Figures in folder --> {0}/\n'.format(subf))
     if os.path.exists(os.path.join(os.getcwd(),subf)) == False:
         os.mkdir(os.path.join(os.getcwd(),subf))
     allcat = self.indat[cseries]
     eunich = np.unique(allcat)
     i = 0
     for cs in eunich:
         i+=1
         inds = np.nonzero(allcat==cs)[0]
         print 'running {0} of {1} --> {2}: {3} samples included'.format(i,len(eunich),cs,len(inds))
         
         if len(inds) > cutoff:
             if allcat[0] == 'SpC':
                 figtitle = self.CommonName[inds][0] + ": " + self.Cut[inds][0]
             else:
                 figtitle = str(cs)
             figname = figtitle.replace(' ','_')
             figname = figname.replace(":","")
             figname = figname.replace('/','_')
             R2 = resid_plotter(self.Hgmod[inds],self.Hgobs[inds],self.DL[inds],self.logFlag,figtitle,figname,subf)
             logfile.write('%s.pdf:%d of %d -->  %d samples included:  R^2 = %f\n' %(figname,i,len(eunich),len(inds),R2))
         else:
             logfile.write('   NOT PRINTED: %d of %d --> %s: N = %d samples --> N < cutoff\n' %(i,len(eunich),cs,len(inds)))
예제 #14
0
def ex1_windowing_solution(data, frame_length, hop_size, windowing_function):
    data = np.array(data)
    number_of_frames = 1 + np.int(
        np.floor((len(data) - frame_length) / hop_size)
    )  #Calculate the number of frames using the presented formula
    frame_matrix = np.zeros((frame_length, number_of_frames))

    if windowing_function == 'rect':
        window = np.ones((frame_length, 1))  # Implement this
    elif windowing_function == 'hann':
        window = np.hanning(frame_length)  # Implement this
    elif windowing_function == 'cosine':
        window = np.sqrt(np.hanning(frame_length))  # Implement this
    elif windowing_function == 'hamming':
        window = np.hamming(frame_length)  # Implement this
    else:
        os.error('Windowing function not supported')

    ## Copy each frame segment from data to the corresponding column of frame_matrix.
    ## If the end sample of the frame segment is larger than data length,
    ## zero-pad the remainder to achieve constant frame length.
    ## Remember to apply the chosen windowing function to the frame!
    for i in range(number_of_frames):
        start = i * hop_size
        stop = np.minimum(start + frame_length, len(data))

        frame = np.zeros(frame_length)

        frame[0:stop - start] = data[start:stop]
        frame_matrix[:, i] = np.multiply(window, frame)
    return frame_matrix
예제 #15
0
    def _thread_copy(torrent_id, video_folder, subtitle_folder, files):
        path_pairs = []
        for filename in files:
            try:
                old_file_path = os.path.join(subtitle_folder, filename)
                new_file_path = os.path.join(video_folder, filename)

                # check that this file exists at the current location
                # if not os.path.exists(old_file_path):
                #     log.debug("COPYSUBTITLES: %s was not downloaded. Skipping." % f["path"])
                #     break

                # check that this file doesn't already exist at the new location
                if os.path.exists(new_file_path):
                    log.info(
                        "COPYSUBTITLES: %s already exists in the destination. Skipping."
                        % f["path"])
                    break

                log.info("COPYSUBTITLES: Copying %s to %s" %
                         (old_file_path, new_file_path))

                # ensure dirs up to this exist
                if not os.path.exists(os.path.dirname(new_file_path)):
                    os.makedirs(os.path.dirname(new_file_path))

                # copy the file
                shutil.copy2(old_file_path, new_file_path)
                path_pairs.append((old_file_path, new_file_path))

            except Exception, e:
                os.error("COPYSUBTITLES: Could not copy file.\n%s" % str(e))
예제 #16
0
    def __init__(self, uri):
        self.uri = urlparse.urlparse(uri.strip())
        self.uriquery = dict(urlparse.parse_qsl(self.uri.query))

        self.protocol = self.uri.scheme.lower()
        if self.protocol == 'tcp':
            try:
                _port = int(self.uri.port)
            except ValueError:
                raise RuntimeError(
                    "Invalid port number in socket URI {0}".format(uri))

            if self.uri.path != '':
                raise RuntimeError(
                    "Path has to be empty in socket URI {0}".format(uri))

        elif self.protocol == 'unix':
            if sys.platform == 'win32':
                os.error("UNIX sockets are not supported on this plaform")
                raise RuntimeError(
                    "UNIX sockets are not supported on this plaform ({0})".
                    format(uri))
            if self.uri.netloc != '':
                # Special case of situation when netloc is not empty (path is relative)
                self.uri = self.uri._replace(netloc='',
                                             path=self.uri.netloc +
                                             self.uri.path)

        else:
            raise RuntimeError(
                "Unknown/unsupported protocol '{0}' in socket URI {1}".format(
                    self.protocol, uri))
예제 #17
0
def bmap(img, ip, baddr, n):
    if n < NDIRECT:
        addr = int.from_bytes(ip[12 + 4 * n:12 + 4 * (n + 1)], "little")

        if addr == 0:
            addr = balloc(img)
            img[baddr + 12 + n * 4:baddr + 12 + (n + 1) * 4] = addr.to_bytes(
                4, "little")
        return addr

    else:
        k = n - NDIRECT
        if (k >= NINDIRECT):
            os.error("invalid index number")
        iaddr = int.from_bytes(ip[12 + 4 * NDIRECT:12 + 4 * (NDIRECT + 1)],
                               "little")

        if iaddr == 0:
            addr = balloc(img)
            img[baddr + 12 + NDIRECT * 4:baddr + 12 +
                (NDIRECT + 1) * 4] = iaddr.to_bytes(4, "little")
        dp = int.from_bytes(
            img[iaddr * BSIZE + k * 4:iaddr * BSIZE + (k + 1) * 4], "little")

        if dp == 0:
            dp = balloc(img)
            img[iaddr * BSIZE + k * 4:iaddr * BSIZE +
                (k + 1) * 4] = dp.to_bytes(4, "little")
        return dp
예제 #18
0
def do_copy(source_filepath, dest_directory):
	source_list = glob.glob(source_filepath)	
	
	if source_list == [ ]:
		# [TODO] Change these to 'error:' to trigger Xcode build failurees.  Need more time to fix the failures - so warnings only now.
		print '  warning: Files were specified to copy, but the files did not exist.'
		print '  warning:   In script:'
		print '  warning:      ' + os.path.normpath(os.path.abspath(__file__))
		print '  warning:    Files that were not found:'
		print '  warning:      ' + source_filepath
		print ''
		os.error(-1)
	
	for source_item in source_list:

		# we globbed at the start so we could accept wildcard syntax (to get *.nib, *.framework, etc)
		# which in turn will product folders with contents, etc.
		if os.path.isdir(source_item):
			# get the leaf folder name so we can create it
			dest_dir_name = os.path.split(source_item)[1]
			dest_directory_plus_leaf_dir = os.path.join(dest_directory, dest_dir_name)
			makedirs(dest_directory_plus_leaf_dir)
			copy_all_in_directory(source_item, dest_directory_plus_leaf_dir)
		else:
			if not os.path.exists(source_item):
					print 'Error copying file or directory', source_fullpath
					os.error(-1)
			makedirs(dest_directory)
			source_filename = os.path.split(source_item)[1]
			dest_filepath = os.path.join(dest_directory, source_filename)
			do_copy_file(source_item, dest_filepath)
예제 #19
0
def initialize_proxy(dest):
    """

    :param dest: ip dest of the proxy server
    :return: void
    """
    github_repositoy = "https://github.com/matthrx/FinancialAlgo.git"
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(dest,
                    username='******',
                    key_filename="C://Users/matth/.ssh/id_rsa.pub")
        _, stdout, _ = ssh.exec_command(
            "git clone {}".format(github_repositoy))
        clone_status = stdout.channel.recv_exit_status()
        if clone_status == 0:
            _, _, _ = ssh.exec_command(
                "sh FinancialAlgo/back/proxy/server_config.sh")
        else:
            print("Clone impossible")
            os.error()
        ssh.close()
    except paramiko.ssh_exception.BadHostKeyException:
        print("Erreur lors de la connection SSH : {}".format(
            paramiko.ssh_exception))
예제 #20
0
def o_ls(img, args):
    if len(args) != 1:
        print("usage: img_file ls path")
        return 1
    path = args[0]
    root_inodes = iget(img, root_inode_number)
    addr, ip = ilookup(img, root_inodes, root_inode_number, path)
    if ip == None:
        os.error("ls: {0}: no such file or directory".format(path))
        return 1
    if int.from_bytes(ip[:2], "little") == T_DIR:
        for i in range(0, int.from_bytes(ip[8:12], "little"), BSIZE):
            flag, de = iread(img, ip, addr, SIZE_DE, i)
            if int.from_bytes(de[:2], "little") == 0:
                continue
            for j in range(0, int.from_bytes(ip[8:12], "little"), SIZE_DE):
                p = iget(img, int.from_bytes(de[j:2 + j], "little"))
                if p == None:
                    continue
                print("{0} {1} {2} {3}".format(
                    de[2 + j:16 + j].decode().replace('\x00', ""),
                    int.from_bytes(p[:2], "little"),
                    int.from_bytes(de[j:2 + j], "little"),
                    int.from_bytes(p[8:12], "little")))
    else:
        print("{0} {1} {2} {3}".format(path, int.from_bytes(ip[:2],
                                                            "little"), addr,
                                       int.from_bytes(ip[8:12], "little")))
예제 #21
0
 def __init__(self, log_dir, trace_dir, level_size):
     if not os.path.isdir(log_dir):
         os.error("no such log directory")
     if not os.path.isdir(trace_dir):
         os.error("no such trace directory")
     self.log_dir = log_dir
     self.trace_dir = trace_dir
     self.level_size = level_size
예제 #22
0
def universal_sys_call(cmd,
                       log,
                       out_filename=None,
                       err_filename=None,
                       cwd=None):
    '''
    Runs cmd and redirects stdout to out_filename (if specified), stderr to err_filename (if specified), or to log otherwise
    '''
    import shlex
    import subprocess
    if isinstance(cmd, list):
        cmd_list = cmd
    else:
        cmd_list = shlex.split(cmd)
    if out_filename:
        stdout = open(out_filename, 'w')
    else:
        stdout = subprocess.PIPE
    if err_filename:
        stderr = open(err_filename, 'w')
    else:
        stderr = subprocess.PIPE

    proc = subprocess.Popen(cmd_list, stdout=stdout, stderr=stderr, cwd=cwd)

    if log and (not out_filename or not err_filename):
        while not proc.poll():
            if not out_filename:
                line = process_readline(proc.stdout.readline()).rstrip()
                if line:
                    log.info(line)
            if not err_filename:
                line = process_readline(proc.stderr.readline()).rstrip()
                if line:
                    log.info(line)
            if proc.returncode is not None:
                break

        if not out_filename:
            for line in proc.stdout.readlines():
                if line != '':
                    log.info(process_readline(line).rstrip())
        if not err_filename:
            for line in proc.stderr.readlines():
                if line != '':
                    log.info(process_readline(line).rstrip())
    else:
        proc.wait()

    if out_filename:
        stdout.close()
    if err_filename:
        stderr.close()
    if proc.returncode:
        os.error(
            'system call for: "%s" finished abnormally, err code: %d' %
            (cmd, proc.returncode), log)
예제 #23
0
def get_driver_path(driver):
    supported = ["Darwin", "Linux"]
    op = platform.platform().split("-")
    if "x86_64" not in op:
        os.error("32-bit is not supported at the moment")

    if op[0] in supported:
        relative_path = "../drivers/mac/{}".format(driver)
    return relative_path
예제 #24
0
    def _thread_copy(torrent_id, video_folder, subtitle_folder, files, forced):
        """
        copy files

        :param torrent_id:
        :param video_folder: destination folder
        :param subtitle_folder: source folder
        :param files: list of source files combined with language ('a.ass', 'ru')
        :param forced: append forced suffix
        :type torrent_id: int
        :type video_folder: str
        :type subtitle_folder: str
        :type files: list
        :type forced: boolean
        :return:
        """
        path_pairs = []
        for filename, lang in files:
            try:
                old_file_path = os.path.join(subtitle_folder, filename)
                filename, file_extension = os.path.splitext(filename)
                suffixes = filename.lower().split('.')

                if lang and lang not in suffixes:
                    filename += '.' + lang
                if forced and 'forced' not in suffixes:
                    filename += '.forced'

                new_file_path = os.path.join(
                    video_folder, ''.join((filename, file_extension)))

                # check that this file exists at the current location
                # if not os.path.exists(old_file_path):
                #     log.debug("COPYSUBTITLES: %s was not downloaded. Skipping." % f["path"])
                #     break

                # check that this file doesn't already exist at the new location
                if os.path.exists(new_file_path):
                    log.info(
                        "COPYSUBTITLES: %s already exists in the destination. Skipping."
                        % new_file_path)
                    continue

                log.info("COPYSUBTITLES: Copying %s to %s" %
                         (old_file_path, new_file_path))

                # ensure dirs up to this exist
                if not os.path.exists(os.path.dirname(new_file_path)):
                    os.makedirs(os.path.dirname(new_file_path))

                # copy the file
                shutil.copy2(old_file_path, new_file_path)
                path_pairs.append((old_file_path, new_file_path))

            except Exception, e:
                os.error("COPYSUBTITLES: Could not copy file.\n%s" % str(e))
def create_directory():
    try:
        today = datetime.now()
        print("Today's Date :",today)
        filename = today.strftime('%Y-%m-%d_%H%M%S')
        print("File Name: ", filename)
        os.mkdir(filename)
        print("File created")
    except:
        os.error("Unable to Create Directory")
예제 #26
0
def nextUnused(existing, candidates):
    lock = Lock()
    lock.acquire()
    for i in candidates:
        if i not in existing:
            existing.append(i)
            lock.release()
            return i

    lock.release()
    os.error("Depleted: running dry!")
예제 #27
0
 def restartIfNeeded(self):
     """ Restart our daemon, if it's required. 
     TODO: If it's not already running, do nothing. 
     """
     if self.rsyslogNeedsRestart:
         log.debug("Going to restart rsyslogd")
         rc = os.system("/usr/bin/service rsyslog restart")
         if rc != 0:
             os.error("Failed to restart the rsyslog daemon. Got a return code of %r", rc)
     else:
         log.debug("Not going to restart rsyslogd")
예제 #28
0
 def define_site(self, site):
     if site == 0:
         self.dlog_data = self.dlog_data_site0
     elif site == 1:
         self.dlog_data = self.dlog_data_site1
     elif site == 2:
         self.dlog_data = self.dlog_data_site2
     elif site == 3:
         self.dlog_data = self.dlog_data_site3
     else:
         os.error("SITE NOT ACTIVE")
예제 #29
0
    def _create_crx(self, out_path):
        print('Creating .CRX process...')
        abs_path = os.path.abspath(out_path + '/resources/')
        abs_path = abs_path.replace('\\', '/') + '/'
        appdata = os.getenv('APPDATA')
        appdata = appdata.split('\\')
        appdata = appdata[:len(appdata) - 1]
        appdata = '\\'.join(appdata)

        if self.browser_path:
            folder_chrome = self.browser_path
            if not os.path.exists(folder_chrome):
                try:
                    raise FileNotFoundError("Folder not found: ", folder_chrome)
                except:
                    raise os.error('Error: check browser path', folder_chrome)
        else:
            folder_chrome = appdata + '/Local/Google/Chrome/Application'
            if not os.path.exists(folder_chrome):
                folder_chrome = appdata + '/Local/Google/Chrome SxS/Application'
            else:
                try:
                    raise FileNotFoundError('Folder Chrome-browser not found. Please select your directory.')
                except:
                    raise os.error('Error: check browser path', folder_chrome)
        try:
            commad_line = '"' + folder_chrome + '/chrome" --pack-extension="' + abs_path + '" --no-message-box'
            retcode = subprocess.call(commad_line, shell=True)
        except OSError as e:
            print(sys.stderr, "\tExecution failed:", e)
        finally:
            old_file_crx = out_path + self.params.theme_name + '.crx'
            old_file_pem = out_path + self.params.theme_name + '.pem'
            if os.path.exists(old_file_crx):
                os.remove(old_file_crx)
            if os.path.exists(old_file_pem):
                os.remove(old_file_pem)

            new_file_crx = out_path + '/resources.crx'
            new_file_pem = out_path + '/resources.pem'
            created_crx_ok, created_pem_ok = False, False
            if os.path.exists(new_file_crx):
                os.rename(out_path + 'resources.crx',
                    out_path + self.params.theme_name + '.crx')
                created_crx_ok = True
            else: print('Ops. Not found "resources.crx" file. Try another Python version.')
            if os.path.exists(new_file_pem):
                os.rename(out_path + '/resources.pem',
                    out_path + self.params.theme_name + '.pem')
                created_pem_ok = True
            else: print('Ops. Not found "resources.pem" file. Try another Python version.')
            if created_crx_ok and created_pem_ok: print('Creating .CRX and .PEM files success')
            else: print('Creating .CRX or .PEM files failed. Sorry. Please, try again!')
def do_copy_file(source_filepath, dest_filepath):
    dest_dir = os.path.split(dest_filepath)[0]
    if not os.path.exists(dest_dir):
        print 'The destination directory', dest_dir, ' does not yet exist!'
        os.error(-1)

    if os.path.exists(dest_filepath) is True:
        if filecmp.cmp(source_filepath, dest_filepath) is True:
            return
        os.chmod(dest_filepath, 0777)
        os.remove(dest_filepath)
    shutil.copy2(source_filepath, os.path.split(dest_filepath)[0])
예제 #31
0
def do_copy_file(source_filepath, dest_filepath):
	dest_dir = os.path.split(dest_filepath)[0]
	if not os.path.exists(dest_dir):
		print 'The destination directory', dest_dir, ' does not yet exist!'
		os.error(-1)

	if os.path.exists(dest_filepath) is True:
		if filecmp.cmp(source_filepath, dest_filepath) is True:
			return
		os.chmod(dest_filepath, 0777)
		os.remove(dest_filepath)
	shutil.copy2(source_filepath, os.path.split(dest_filepath)[0])
예제 #32
0
def execute(argc, args):
    "This function runs the command"
    pid = os.fork()
    if (pid == -1):
        os.error("fork")
        print '  (failed to execute command)'
    elif pid == 0:  # we are in child
        if (-1 == os.execvp(args[0], args)):
            os.error('execvp')
            print "   (couldn't find command)"
        sys.exit(1)
    else:  # we are in parent
        os.waitpid(pid, 0)  # wait until child process finishes
예제 #33
0
def calc_vessel_hydrodynamics(vesselgroup,
                              calc_hematocrit=False,
                              return_flags=False,
                              override_hematocrit=None,
                              bloodflowparams=dict(),
                              storeCalculationInHDF=False):
    if 'CLASS' in vesselgroup.attrs:
        return calc_vessel_hydrodynamics_(vesselgroup, calc_hematocrit,
                                          return_flags, override_hematocrit,
                                          bloodflowparams,
                                          storeCalculationInHDF)
    else:
        os.error('Unknown vessel structure!')
예제 #34
0
def do_examine(args):
    debug(f"Trying to examine: {args}")
    if not args:
        error("What do you want to examine?")
        return
    name = args[0].lower()
    if not current_place_has(name) and not player_has(name):
        error(f"Sorry, idk what this is: {name}")
        return
    if name not in ITEMS:
        abort(f"Welp! The info about {name} isn't here, my dear.")
    item = ITEMS[name]
    header(item["name"])
    wrap(item["description"])
예제 #35
0
def shell_launch_bg(arguments):
    pid = os.fork()
    if pid == 0:
        print(os.getpid())
        os.setpgid(0,0)
        try:
            res = os.execvp(arguments[0], arguments)
            if res == -1:
                print(os.error().strerror())
        except FileNotFoundError:
            print("%s not found in path" % arguments[0])
    elif pid < 0:
        print(os.error().strerror())
    return 1
예제 #36
0
    def _thread_copy(torrent_id, old_path, new_path, files, umask):
        # apply different umask if available
        if umask:
            log.debug("COPYCOMPLETED: Applying new umask of octal %s" % umask)
            mask = umask[1:4]
            new_umask = int(mask, 8)
            old_umask = os.umask(new_umask)

        path_pairs = [ ]
        for f in files:
            try:
                old_file_path = os.path.join(old_path, f["path"])
                new_file_path = os.path.join(new_path, f["path"])

                # check that this file exists at the current location
                if not os.path.exists(old_file_path):
                    log.debug("COPYCOMPLETED: %s was not downloaded. Skipping." % f["path"])
                    break

                # check that this file doesn't already exist at the new location
                if os.path.exists(new_file_path):
                    log.info("COPYCOMPLETED: %s already exists in the destination. Skipping." % f["path"])
                    break

                log.info("COPYCOMPLETED: Copying %s to %s" % (old_file_path, new_file_path))

                # ensure dirs up to this exist
                if not os.path.exists(os.path.dirname(new_file_path)):
                    os.makedirs(os.path.dirname(new_file_path))

                # copy the file
                shutil.copy2(old_file_path, new_file_path)

                # amend file mode with umask if specified
                if umask:
                    # choose 0666 so execute bit is not set for files
                    os.chmod(new_file_path, (~new_umask & 0o666))

                path_pairs.append(( old_file_path, new_file_path ))

            except Exception as e:
                os.error("COPYCOMPLETED: Could not copy file.\n%s" % str(e))

        # revert new umask
        if umask:
            log.debug("COPYCOMPLETED: reverting umask to original")
            os.umask(old_umask)

        component.get("EventManager").emit(TorrentCopiedEvent(torrent_id, old_path, new_path, path_pairs))
예제 #37
0
    def __init__(self, path ):
 
        self.log=logging.getLogger(__name__)
        if os.path.exists(path):
            self.parse(path)
        else:
            raise os.error(" sample sheet cannot be found at {0}".format(path))
예제 #38
0
    def __init__(self):
        path = os.getenv("PATH")
        if path is None:
            path = os.getenv("path")
        if path is None:
            path = os.defpath

        dirs = path.split(os.pathsep)

        # Modify path for our use.
        usrlocal = "/usr/local/bin"
        if usrlocal not in dirs:
            dirs.append(usrlocal)

        self.command = None
        for d in dirs:
            curr = os.path.join(d, RTCMIX_COMMAND)
            if os.path.isfile(curr):
                self.command = curr
                break

        if self.command is None:
            raise os.error("Could not find RTcmix command '%s'" % RTCMIX_COMMAND)

        self.totalTime = None
        self.rtcmix = None
        self.rtcmixout = None
예제 #39
0
파일: costhome.py 프로젝트: iled/gsimcli
def match_sub(path, sub, level=3):
    """Try to fetch the matching `sub` station in a given submission.

    Parameters
    ----------
    path : string
        Station file path.
    sub : string
        Intended corresponding station.
    level : int, default 3
        Number of levels in the directory tree to go up.

    Returns
    -------
    match : string
        Path to the matching station.

    """
    subpath, signalpath = ut.path_up(path, level)
    benchpath, subm = os.path.split(subpath)  # @UnusedVariable
    match = os.path.join(benchpath, sub, signalpath)
    if not os.path.exists(match):
        # try to match by station id
        dirname, basename = os.path.split(match)
        os.chdir(dirname)
        match = os.path.join(dirname, glob.glob('*' + str(basename[2:]))[0])
        if not os.path.isfile(match):
            raise os.error('no such file: \'{0}\''.format(match))

    return match
예제 #40
0
파일: costhome.py 프로젝트: iled/gsimcli
    def load_outliers(self, path=None):
        """List the dates with detected outliers.

        Parameters
        ----------
        path : string, optional
            Breakpoints file path.

        Returns
        -------
        Sets attribute `outliers`

        outliers : pandas.Series
            Dates with detected outliers.

        Notes
        -----
        The `breakpoints` file name must end with *detected.txt*.

        """
        if path is not None and os.path.isfile(path):
            detected_file = path
        else:
            path = os.path.dirname(self.path)
            os.chdir(path)
            try:
                detected_file = glob.glob('*detected.txt')[0]
            except:
                raise os.error('breakpoints file not found in directory {0}'.
                               format(path))

        detected = pc.breakpointsfile(detected_file)
        select_station = detected["Station"].map(lambda x: self.id in x)
        select_outlier = detected["Type"] == "OUTLIE"
        self.outliers = detected[select_station & select_outlier].ix[:, 2:]
예제 #41
0
파일: platform.py 프로젝트: Debug-Orz/Sypy
def _syscmd_ver(system='',release='',version='',

               supported_platforms=('win32','win16','dos','os2'),
               ver_output=re.compile('(?:([\w ]+) ([\w.]+) '
                                     '.*'
                                     'Version ([\d.]+))')):

    """ Tries to figure out the OS version used and returns
        a tuple (system,release,version).
        
        It uses the "ver" shell command for this which is known
        to exists on Windows, DOS and OS/2. XXX Others too ?

        In case this fails, the given parameters are used as
        defaults.

    """
    if sys.platform not in supported_platforms:
        return system,release,version

    # Try some common cmd strings
    for cmd in ('ver','command /c ver','cmd /c ver'):
        try:
            pipe = popen(cmd)
            info = pipe.read()
            if pipe.close():
                raise os.error('command failed')
            # XXX How can I supress shell errors from being written
            #     to stderr ?
        except os.error,why:
            #print 'Command %s failed: %s' % (cmd,why)
            continue
        except IOError,why:
            #print 'Command %s failed: %s' % (cmd,why)
            continue
예제 #42
0
 def __init__(self, path ):
     if os.path.exists(path):
         self.path=path
         self.result={}
         self.parse()
     else:
         raise os.error("Demultiplexing folder cannot be found at {0}".format(path))
예제 #43
0
 def __init__(self, path):
     if os.path.exists(path):
         self.path = path
         self.cycles = []
         self.parse()
     else:
         raise os.error("file {0} cannot be found".format(path))
예제 #44
0
 def __stat(fn: str) -> object:
     try:
         f = open(fn)
     except IOError:
         raise _os.error()
     f.close()
     return None
예제 #45
0
 def back(self):
     if not self._dirstack:
         raise os.error("empty directory stack")
     dir, ignore = self._dirstack[-1]
     os.chdir(dir)
     del self._dirstack[-1]
     self._ignore = ignore
예제 #46
0
def _syscmd_ver(system='', release='', version='', supported_platforms=('win32', 'win16', 'dos', 'os2')):
    if sys.platform not in supported_platforms:
        return (system, release, version)
    for cmd in ('ver', 'command /c ver', 'cmd /c ver'):
        try:
            pipe = popen(cmd)
            info = pipe.read()
            while pipe.close():
                raise os.error('command failed')
        except os.error as why:
            continue
        except IOError as why:
            continue
        break
    return (system, release, version)
    info = info.strip()
    m = _ver_output.match(info)
    if m is not None:
        (system, release, version) = m.groups()
        if release[-1] == '.':
            release = release[:-1]
        if version[-1] == '.':
            version = version[:-1]
        version = _norm_version(version)
    return (system, release, version)
예제 #47
0
 def __init__(self, path):
     if os.path.exists(path):
         self.log=logging.getLogger(__name__)
         self.path=path
         self.parse()
         self.create_db_obj()
     else:
         raise os.error(" flowcell cannot be found at {0}".format(path))
예제 #48
0
 def touch(self, filename, mtime=None):
   typecheck(filename, basestring)
   if filename not in self.__files:
     raise os.error("File not found: " + filename)
   if mtime is None:
     mtime = time.time()
   oldtime, content = self.__files[filename]
   self.__files[filename] = (mtime, content)
예제 #49
0
 def __init__(self, path):
     if os.path.exists(path):
         self.path=path
         self.result={}
         self.TOTAL = {}
         self.parse()
     else:
         raise os.error("DemuxSummary folder {0} cannot be found".format(path))
예제 #50
0
  def mkdir(self, filename):
    typecheck(filename, basestring)

    if filename in self.__files:
      raise os.error("Can't make directory because file exists: %s" % filename)
    if filename != "":
      self.mkdir(os.path.dirname(filename))
      self.__dirs.add(filename)
예제 #51
0
파일: posix.py 프로젝트: DawidvC/felix
 def create_directory(self,dir):
   if not self.os.path.isdir(dir):
     try: self.os.mkdir(dir)
     except os.error as data:
       if data.errno != self.errno.EEXIST: # File Exists is OK, everything else is fatal
         raise os.error(data.errno,data+': directory "'+dir+'"')
   if not self.os.path.isdir(dir):
     raise self.os.error(self.errno.ENOENT, 'Created a directory '+dir+', but it is not there!')
예제 #52
0
 def __init__(self, path ):
     self.data={}
     self.recipe=None
     self.path=path
     if os.path.exists(path):
         self.parse()
     else:
         raise os.error("RunParameters file cannot be found at {0}".format(path))
예제 #53
0
파일: test_walk.py 프로젝트: salexkidd/box
 def setUp(self):
     self.addCleanup(patch.stopall)
     patch.object(component.os, 'listdir', new=self.mock_listdir).start()
     patch.object(component.os.path, 'islink', new=self.mock_islink).start()
     patch.object(component.os.path, 'isfile', new=self.mock_isfile).start()
     patch.object(component.os.path, 'isdir', new=self.mock_isdir).start()
     self.error = os.error()
     self.pwalk = partial(component.enhanced_walk, sorter=sorted)
예제 #54
0
 def __init__(self, path ):
     self.data={}
     self.recipe=None
     self.path=path
     if os.path.exists(path):
         self.parse()
     else:
         raise os.error("XTen run info cannot be found at {0}".format(path))
예제 #55
0
파일: sync.py 프로젝트: hkupty/bookkeeper
def sync_file(file_path, target_path):
    """Sync file on target path."""
    if os.path.exists(target_path) and not os.path.islink(target_path):
        raise os.error("File exists: {}".format(file_path))
    elif os.path.islink(target_path):
        pass
    else:
        os.symlink(file_path, target_path)
예제 #56
0
def create_rsvp(data, path):
    if os.path.isdir(path):
        _m = md5.md5(data['email']).hexdigest()
        _f = open(os.path.join(path, _m), 'w+')
        csv.writer(_f).writerow((data['name'], data['email']))
        _f.close()
    else:
        raise os.error('RSVP path does not exist: %s' % path)
예제 #57
0
def check_paths(paths):
    # Checks a list of file paths to ensure they are valid.
    if len(paths) == 0:
        raise IndexError('Your list of file paths is empty.')
    for f in paths:
        if not os.path.isfile(f):
            raise os.error('File path does not exist: \'{}\''.format(f))
    return
예제 #58
0
def isLarge(file_path):
    Bigjudge = 2000000
    filesize = os.path.getsize(file_path)
    if os.path.isfile(file_path) == False:
        raise os.error("There is no this file")
    if(filesize > Bigjudge):
        return filesize
    else:
        return 0
예제 #59
0
파일: 2.py 프로젝트: jimodb/codes
def checkIsLargeFile(file_path):
    Bigjudge = 10 * 1024 * 1024
    filesize = os.path.getsize(file_path)
    if os.path.isfile(file_path) == False:
        raise os.error("File not found")
    if(filesize > Bigjudge):
        print file_path, filesize
    else:
        pass