Python os.system() Examples

The following are code examples for showing how to use os.system(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: pyblish-win   Author: pyblish   File: _osx_support.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def _read_output(commandstring):
    """Output from successful command execution or None"""
    # Similar to os.popen(commandstring, "r").read(),
    # but without actually using os.popen because that
    # function is not usable during python bootstrap.
    # tempfile is also not available then.
    import contextlib
    try:
        import tempfile
        fp = tempfile.NamedTemporaryFile()
    except ImportError:
        fp = open("/tmp/_osx_support.%s"%(
            os.getpid(),), "w+b")

    with contextlib.closing(fp) as fp:
        cmd = "%s 2>/dev/null >'%s'" % (commandstring, fp.name)
        return fp.read().strip() if not os.system(cmd) else None 
Example 2
Project: pyblish-win   Author: pyblish   File: mailcap.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def listmailcapfiles():
    """Return a list of all mailcap files found on the system."""
    # XXX Actually, this is Unix-specific
    if 'MAILCAPS' in os.environ:
        str = os.environ['MAILCAPS']
        mailcaps = str.split(':')
    else:
        if 'HOME' in os.environ:
            home = os.environ['HOME']
        else:
            # Don't bother with getpwuid()
            home = '.' # Last resort
        mailcaps = [home + '/.mailcap', '/etc/mailcap',
                '/usr/etc/mailcap', '/usr/local/etc/mailcap']
    return mailcaps


# Part 2: the parser. 
Example 3
Project: pyblish-win   Author: pyblish   File: mailcap.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def findmatch(caps, MIMEtype, key='view', filename="/dev/null", plist=[]):
    """Find a match for a mailcap entry.

    Return a tuple containing the command line, and the mailcap entry
    used; (None, None) if no match is found.  This may invoke the
    'test' command of several matching entries before deciding which
    entry to use.

    """
    entries = lookup(caps, MIMEtype, key)
    # XXX This code should somehow check for the needsterminal flag.
    for e in entries:
        if 'test' in e:
            test = subst(e['test'], filename, plist)
            if test and os.system(test) != 0:
                continue
        command = subst(e[key], MIMEtype, filename, plist)
        return command, e
    return None, None 
Example 4
Project: pyblish-win   Author: pyblish   File: mailcap.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test():
    import sys
    caps = getcaps()
    if not sys.argv[1:]:
        show(caps)
        return
    for i in range(1, len(sys.argv), 2):
        args = sys.argv[i:i+2]
        if len(args) < 2:
            print "usage: mailcap [MIMEtype file] ..."
            return
        MIMEtype = args[0]
        file = args[1]
        command, e = findmatch(caps, MIMEtype, 'view', file)
        if not command:
            print "No viewer found for", type
        else:
            print "Executing:", command
            sts = os.system(command)
            if sts:
                print "Exit status:", sts 
Example 5
Project: pyblish-win   Author: pyblish   File: os.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def popen4(cmd, mode="t", bufsize=-1):
            """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
            may be a sequence, in which case arguments will be passed directly to
            the program without shell intervention (as with os.spawnv()).  If 'cmd'
            is a string it will be passed to the shell (as with os.system()). If
            'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
            file objects (child_stdin, child_stdout_stderr) are returned."""
            import warnings
            msg = "os.popen4 is deprecated.  Use the subprocess module."
            warnings.warn(msg, DeprecationWarning, stacklevel=2)

            import subprocess
            PIPE = subprocess.PIPE
            p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring),
                                 bufsize=bufsize, stdin=PIPE, stdout=PIPE,
                                 stderr=subprocess.STDOUT, close_fds=True)
            return p.stdin, p.stdout 
Example 6
Project: flask-ci   Author: vicenteneto   File: run_nose.py    MIT License 6 votes vote down vote up
def run(self, settings, **options):
        args = list()

        if options[Nose.WITH_XUNIT]:
            args.append(Nose.WITH_XUNIT_PARAM)
            args.append('%s=%s' % (Nose.XUNIT_FILE_PARAM, options[Nose.XUNIT_FILE]))
        if options[Nose.COVER_XML] or options[Nose.COVER_HTML]:
            args.append(Nose.WITH_COVERAGE_PARAM)
            args.append('%s=%s' % (Nose.COVER_PACKAGE_PARAM, ','.join(getattr(settings, Settings.PROJECT_APPS, []))))
        if options[Nose.COVER_XML]:
            args.append(Nose.COVER_XML_PARAM)
            args.append('%s=%s' % (Nose.COVER_XML_FILE_PARAM, options[Nose.COVER_XML_FILE]))
        if options[Nose.COVER_HTML]:
            args.append(Nose.COVER_HTML_PARAM)
            args.append('%s=%s' % (Nose.COVER_HTML_DIR_PARAM, options[Nose.COVER_HTML_DIR]))
        if options[Nose.COVER_BRANCHES]:
            args.append(Nose.COVER_BRANCHES_PARAM)

        command = '%s %s' % (Nose.NOSE_TESTS, ' '.join(args))
        os.system(command)

        if Nose.WITH_COVERAGE_PARAM in args:
            os.remove(Nose.COVERAGE_FILE) 
Example 7
Project: arm_now   Author: nongiach   File: arm_now.py    MIT License 6 votes vote down vote up
def run_qemu(arch, kernel, dtb, rootfs, add_qemu_options):
    dtb = "" if not os.path.exists(dtb) else "-dtb {}".format(dtb)
    options = qemu_options[arch][1].format(arch=arch, kernel=kernel, rootfs=rootfs, dtb=dtb)
    arch = qemu_options[arch][0]
    print("Starting qemu-system-{}".format(arch))
    qemu_config = "-serial stdio -monitor null {add_qemu_options}".format(add_qemu_options=add_qemu_options)
    cmd = """stty intr ^]
       export QEMU_AUDIO_DRV="none"
       qemu-system-{arch} {options} \
               -m 256M \
               -nographic \
               {qemu_config} \
               {dtb} \
               -no-reboot
       stty intr ^c
    """.format(arch=arch, qemu_config=qemu_config, options=options, dtb=dtb)
    pgreen(cmd)
    os.system(cmd) 
Example 8
Project: arm_now   Author: nongiach   File: arm_now.py    MIT License 6 votes vote down vote up
def check_dependencies_or_exit():
    dependencies = [
            which("e2cp",
                ubuntu="apt-get install e2tools",
                arch="yaourt -S e2tools",
                darwin="brew install e2tools gettext e2fsprogs\nbrew unlink e2fsprogs && brew link e2fsprogs -f"),
            which("qemu-system-arm",
                  ubuntu="apt-get install qemu",
                  kali="apt-get install qemu-system",
                  arch="pacman -S qemu-arch-extra",
                  darwin="brew install qemu"),
            which("unzip",
                ubuntu="apt-get install unzip",
                arch="pacman -S unzip",
                darwin="brew install unzip")
            ]
    if not all(dependencies):
        print("requirements missing, plz install them", file=sys.stderr)
        sys.exit(1) 
Example 9
Project: GIG   Author: palash25   File: gig.py    MIT License 6 votes vote down vote up
def generate(self, arg):
        if not self.git_init():
            click.echo(
                click.style(
                    "[WARN] Git is not initialized yet", fg='yellow'))
            if click.confirm(
                    'Do you want to initialize GIT in this directory?',
                    abort=False):
                os.system('git init .')
            else:
                click.echo(
                    click.style(
                        "[INFO] GITIGNORE was not generated.", fg='blue'))
                quit()

        if self.gi_not_exists(self.__dest):
            self.process(arg)
        else:
            click.echo(
                click.style(
                    "[WARN] GITINGNORE already exists.", fg='yellow'))
            if click.confirm('Do you want to overwrite?', abort=False):
                self.process(arg) 
Example 10
Project: keras_mixnets   Author: titu1994   File: setup.py    MIT License 6 votes vote down vote up
def run(self):
        try:
            self.status('Removing previous builds...')
            rmtree(os.path.join(base_path, 'dist'))
        except OSError:
            pass

        self.status('Building Source and Wheel (universal) distribution...')
        os.system('{0} setup.py sdist bdist_wheel'.format(sys.executable))

        self.status('Pushing git tags...')
        os.system('git tag v{0}'.format(get_version()))
        os.system('git push --tags')

        try:
            self.status('Removing build artifacts...')
            rmtree(os.path.join(base_path, 'build'))
            rmtree(os.path.join(base_path, '{}.egg-info'.format(PACKAGE_NAME)))
        except OSError:
            pass

        sys.exit() 
Example 11
Project: Att-ChemdNER   Author: lingluodlut   File: utils.py    Apache License 2.0 6 votes vote down vote up
def get_perf(filename):
    ''' run conlleval.pl perl script to obtain
    precision/recall and F1 score '''
    _conlleval = PREFIX + 'conlleval'
    if not isfile(_conlleval):
        #download('http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl') 
        os.system('wget https://www.comp.nus.edu.sg/%7Ekanmy/courses/practicalNLP_2008/packages/conlleval.pl')
        chmod('conlleval.pl', stat.S_IRWXU) # give the execute permissions
    
    out = []
    proc = subprocess.Popen(["perl", _conlleval], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    stdout, _ = proc.communicate(open(filename).read())
    for line in stdout.split('\n'):
        if 'accuracy' in line:
            out = line.split()
            break
    
    # out = ['accuracy:', '16.26%;', 'precision:', '0.00%;', 'recall:', '0.00%;', 'FB1:', '0.00']
    precision = float(out[3][:-2])
    recall    = float(out[5][:-2])
    f1score   = float(out[7])

    return {'p':precision, 'r':recall, 'f1':f1score} 
Example 12
Project: Mzo-Cli   Author: jamesstidard   File: setup.py    MIT License 6 votes vote down vote up
def run(self):
        try:
            self.status('Removing previous builds…')
            rmtree(os.path.join(here, 'dist'))
        except OSError:
            pass

        self.status('Building Source and Wheel (universal) distribution…')
        os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable))

        self.status('Uploading the package to PyPi via Twine…')
        os.system('twine upload dist/*')

        self.status('Pushing git tags…')
        os.system('git tag v{0}'.format(about['__version__']))
        os.system('git push --tags')

        sys.exit()


# Where the magic happens: 
Example 13
Project: twitter-export-image-fill   Author: mwichary   File: twitter-export-image-fill.py    The Unlicense 6 votes vote down vote up
def download_video(url, local_filename):
  if not download_videos:
    return True

  try:
    local_filename_escaped = local_filename.replace(' ', '\ ')
    command = '%s -q --no-warnings %s --exec \'mv {} %s\' &>/dev/null' % \
        (youtube_dl_path, url, local_filename_escaped)
    if os.system(command) > 0:
      return False
    if os.path.isfile(local_filename):
      return True
    else:
      return False
  except:
    return False


# Downloads an avatar image for a tweet.
# @return Whether data was rewritten 
Example 14
Project: AutoDL   Author: tanguofu   File: param.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def reconfigure(self):
        param = self.param

        param.gpu_nums = gpu.get_nr_gpu()
        
        # TODO compute the minibatch by GPU MEM
        param.all_step = max(int(param.epoch * param.train_nums / param.minibatch), 10)
        param.step_per_epoch = max(int(param.train_nums / param.minibatch), 1)
        param.batch_size = max(int(param.minibatch / param.gpu_nums), 1)
        param.minibatch = param.batch_size*param.gpu_nums

        #this is nessary compute lr with epoch 
        param.train_nums = (param.train_nums // param.minibatch) * param.minibatch
    
        #update checkoint name for easy run mulitimes
        param.checkpoint = param.checkpoint + "/" + "_".join([ param.name, "batch"+str(param.minibatch), "layer"+str(param.resnet_layer)])
    
        if not os.path.exists(param.checkpoint):
             os.system("mkdir -p " + param.checkpoint)
        
        logging.info("reconfigure:"+repr(self.param)) 
Example 15
Project: Shellware   Author: NullArray   File: shellware.py    GNU General Public License v3.0 6 votes vote down vote up
def autorun(dir, fileName, run):
	# Copy to C:\Users
	os.system('copy %s %s'%(fileName, dir))

	# Queries Windows registry for the autorun key value
	# Stores the key values in runkey array
	key = OpenKey(HKEY_LOCAL_MACHINE, run)
	runkey =[]
	try:
		i = 0
		while True:
			subkey = EnumValue(key, i)
			runkey.append(subkey[0])
			i += 1
	except WindowsError:
		pass

	# Set key
	if 'foobar' not in runkey:
		try:
			key= OpenKey(HKEY_LOCAL_MACHINE, run,0,KEY_ALL_ACCESS)
			SetValueEx(key ,'foobar',0,REG_SZ,r"C:\Users\shellware.exe")
			key.Close()
		except WindowsError:
			pass 
Example 16
Project: CACConsole   Author: foospidy   File: CloudAtCostConsole.py    GNU General Public License v2.0 6 votes vote down vote up
def do_ping(self, serverid):
		"""ping: Ping a server. Usage: ping [<serverid>|all] """
		if not self.using:
			self.sendLine('No account selected! Type: help use')
			return
		
		servers = self.cac.get_server_info()

		for i in range(0, len(servers)):
			server_data = servers[i]
			sid         = server_data['sid'].encode('UTF-8')
			ip          = server_data['ip'].encode('UTF-8')
			
			if 'all' == serverid:
				response = os.system('ping -c 3 ' + ip)
			elif serverid == sid:
				response = os.system('ping -c 3 ' + ip) 
Example 17
Project: mycode   Author: gmraabe   File: usopen.py    GNU General Public License v3.0 5 votes vote down vote up
def ping_router(hostname):

    response = os.system("ping -c 1 " + hostname)

    #and then check the response...
    if response == 0:
        return True
    else:
        return False

## Check interfaces - Issue "show ip init brief" 
Example 18
Project: mycode   Author: gmraabe   File: r2-d2.py    GNU General Public License v3.0 5 votes vote down vote up
def ping_router(hostname):
    response = os.system("ping -c 1 " + hostname)
    #and then check the response...
    if response == 0:
        return True
    else:
        return False

## Check interfaces - Issue "show ip init brief" 
Example 19
Project: malcode   Author: moonsea   File: filtersamemd5.py    GNU General Public License v3.0 5 votes vote down vote up
def genAsm(filepath, total, asmpath):
    ExecStr = "ndisasm -a -u '" + filepath + "' > " + asmpath
    # print ExecStr
    res = os.system(ExecStr)
    log('asming', filepath + '(' + asmpath + ') :' + str(res), subpath='ndisasm')

    return total + 1 
Example 20
Project: malcode   Author: moonsea   File: wingenasm.py    GNU General Public License v3.0 5 votes vote down vote up
def genAsm(filepath, total):
    ExecStr = idalPath + " -c -A -S" + idcPath + " '" + filepath + "'"
    # print ExecStr
    os.system(ExecStr)

    return total + 1 
Example 21
Project: malcode   Author: moonsea   File: virusgenasm.py    GNU General Public License v3.0 5 votes vote down vote up
def genAsm(filepath, total, asmpath):
    ExecStr = "ndisasm -a -u '" + filepath + "' > " + asmpath
    # print ExecStr
    res = os.system(ExecStr)
    log('asming', filepath + '(' + asmpath + ') :' + str(res), subpath='ndisasm')

    return total + 1 
Example 22
Project: malcode   Author: moonsea   File: winfailgenasm.py    GNU General Public License v3.0 5 votes vote down vote up
def genAsm(filepath):
    ExecStr = idalPath + " -c -A -S" + idcPath + " " + filepath
    # print ExecStr
    os.system(ExecStr) 
Example 23
Project: malcode   Author: moonsea   File: dosgenasm.py    GNU General Public License v3.0 5 votes vote down vote up
def genAsm(filepath, total):
    ExecStr = idalPath + " -c -A -S" + idcPath + " \"" + filepath + "\""
    # print ExecStr
    os.system(ExecStr)

    return total + 1 
Example 24
Project: photometry-sans-frustration   Author: mnicholl   File: queryPS1.py    MIT License 5 votes vote down vote up
def PS1cutouts(ra,dec,filt):

    print '\nSearching for PS1 images of field...\n'

    ps1_url = 'http://ps1images.stsci.edu/cgi-bin/ps1filenames.py?'

    ps1_url += '&ra='+str(ra)
    ps1_url += '&dec='+str(dec)
    ps1_url += '&filters='+filt

    ps1_im = requests.get(ps1_url)

    try:
        image_name = ps1_im.text.split()[17]

        print 'Image found: ' + image_name + '\n'

        cutout_url = 'http://ps1images.stsci.edu/cgi-bin/fitscut.cgi?&filetypes=stack&size=2500'

        cutout_url += '&ra='+str(ra)
        cutout_url += '&dec='+str(dec)
        cutout_url += '&filters='+filt
        cutout_url += '&format=fits'
        cutout_url += '&red='+image_name

        dest_file = filt + '_template.fits'

        cmd = 'wget -O %s "%s"' % (dest_file, cutout_url)

        os.system(cmd)

        print 'Template downloaded as ' + dest_file + '\n'

    except:
        print '\nPS1 template search failed!\n' 
Example 25
Project: pyblish-win   Author: pyblish   File: xxci.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def go(args):
    for file in args:
        print file + ':'
        if differing(file):
            showdiffs(file)
            if askyesno('Check in ' + file + ' ? '):
                sts = os.system('rcs -l ' + file) # ignored
                sts = os.system('ci -l ' + file) 
Example 26
Project: pyblish-win   Author: pyblish   File: xxci.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def differing(file):
    cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file
    sts = os.system(cmd)
    return sts != 0 
Example 27
Project: pyblish-win   Author: pyblish   File: xxci.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def showdiffs(file):
    cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}'
    sts = os.system(cmd) 
Example 28
Project: pyblish-win   Author: pyblish   File: pytree_idempotency.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def diff(fn, tree):
    f = open("@", "w")
    try:
        f.write(str(tree))
    finally:
        f.close()
    try:
        return os.system("diff -u %s @" % fn)
    finally:
        os.remove("@") 
Example 29
Project: pyblish-win   Author: pyblish   File: _osx_support.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _get_system_version():
    """Return the OS X system version as a string"""
    # Reading this plist is a documented way to get the system
    # version (see the documentation for the Gestalt Manager)
    # We avoid using platform.mac_ver to avoid possible bootstrap issues during
    # the build of Python itself (distutils is used to build standard library
    # extensions).

    global _SYSTEM_VERSION

    if _SYSTEM_VERSION is None:
        _SYSTEM_VERSION = ''
        try:
            f = open('/System/Library/CoreServices/SystemVersion.plist')
        except IOError:
            # We're on a plain darwin box, fall back to the default
            # behaviour.
            pass
        else:
            try:
                m = re.search(r'<key>ProductUserVisibleVersion</key>\s*'
                              r'<string>(.*?)</string>', f.read())
            finally:
                f.close()
            if m is not None:
                _SYSTEM_VERSION = '.'.join(m.group(1).split('.')[:2])
            # else: fall back to the default behaviour

    return _SYSTEM_VERSION 
Example 30
Project: pyblish-win   Author: pyblish   File: _osx_support.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _supports_universal_builds():
    """Returns True if universal builds are supported on this system"""
    # As an approximation, we assume that if we are running on 10.4 or above,
    # then we are running with an Xcode environment that supports universal
    # builds, in particular -isysroot and -arch arguments to the compiler. This
    # is in support of allowing 10.4 universal builds to run on 10.3.x systems.

    osx_version = _get_system_version()
    if osx_version:
        try:
            osx_version = tuple(int(i) for i in osx_version.split('.'))
        except ValueError:
            osx_version = ''
    return bool(osx_version >= (10, 4)) if osx_version else False 
Example 31
Project: pyblish-win   Author: pyblish   File: _osx_support.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _remove_unsupported_archs(_config_vars):
    """Remove any unsupported archs from config vars"""
    # Different Xcode releases support different sets for '-arch'
    # flags. In particular, Xcode 4.x no longer supports the
    # PPC architectures.
    #
    # This code automatically removes '-arch ppc' and '-arch ppc64'
    # when these are not supported. That makes it possible to
    # build extensions on OSX 10.7 and later with the prebuilt
    # 32-bit installer on the python.org website.

    # skip checks if the compiler was overriden with a CC env variable
    if 'CC' in os.environ:
        return _config_vars

    if re.search('-arch\s+ppc', _config_vars['CFLAGS']) is not None:
        # NOTE: Cannot use subprocess here because of bootstrap
        # issues when building Python itself
        status = os.system(
            """echo 'int main{};' | """
            """'%s' -c -arch ppc -x c -o /dev/null /dev/null 2>/dev/null"""
            %(_config_vars['CC'].replace("'", "'\"'\"'"),))
        if status:
            # The compile failed for some reason.  Because of differences
            # across Xcode and compiler versions, there is no reliable way
            # to be sure why it failed.  Assume here it was due to lack of
            # PPC support and remove the related '-arch' flags from each
            # config variables not explicitly overriden by an environment
            # variable.  If the error was for some other reason, we hope the
            # failure will show up again when trying to compile an extension
            # module.
            for cv in _UNIVERSAL_CONFIG_VARS:
                if cv in _config_vars and cv not in os.environ:
                    flags = _config_vars[cv]
                    flags = re.sub('-arch\s+ppc\w*\s', ' ', flags)
                    _save_modified_value(_config_vars, cv, flags)

    return _config_vars 
Example 32
Project: pyblish-win   Author: pyblish   File: _osx_support.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def customize_config_vars(_config_vars):
    """Customize Python build configuration variables.

    Called internally from sysconfig with a mutable mapping
    containing name/value pairs parsed from the configured
    makefile used to build this interpreter.  Returns
    the mapping updated as needed to reflect the environment
    in which the interpreter is running; in the case of
    a Python from a binary installer, the installed
    environment may be very different from the build
    environment, i.e. different OS levels, different
    built tools, different available CPU architectures.

    This customization is performed whenever
    distutils.sysconfig.get_config_vars() is first
    called.  It may be used in environments where no
    compilers are present, i.e. when installing pure
    Python dists.  Customization of compiler paths
    and detection of unavailable archs is deferred
    until the first extension module build is
    requested (in distutils.sysconfig.customize_compiler).

    Currently called from distutils.sysconfig
    """

    if not _supports_universal_builds():
        # On Mac OS X before 10.4, check if -arch and -isysroot
        # are in CFLAGS or LDFLAGS and remove them if they are.
        # This is needed when building extensions on a 10.3 system
        # using a universal build of python.
        _remove_universal_flags(_config_vars)

    # Allow user to override all archs with ARCHFLAGS env var
    _override_all_archs(_config_vars)

    # Remove references to sdks that are not found
    _check_for_unavailable_sdk(_config_vars)

    return _config_vars 
Example 33
Project: pyblish-win   Author: pyblish   File: popen2.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, cmd, capturestderr=False, bufsize=-1):
        """The parameter 'cmd' is the shell command to execute in a
        sub-process.  On UNIX, 'cmd' may be a sequence, in which case arguments
        will be passed directly to the program without shell intervention (as
        with os.spawnv()).  If 'cmd' is a string it will be passed to the shell
        (as with os.system()).   The 'capturestderr' flag, if true, specifies
        that the object should capture standard error output of the child
        process.  The default is false.  If the 'bufsize' parameter is
        specified, it specifies the size of the I/O buffers to/from the child
        process."""
        _cleanup()
        self.cmd = cmd
        p2cread, p2cwrite = os.pipe()
        c2pread, c2pwrite = os.pipe()
        if capturestderr:
            errout, errin = os.pipe()
        self.pid = os.fork()
        if self.pid == 0:
            # Child
            os.dup2(p2cread, 0)
            os.dup2(c2pwrite, 1)
            if capturestderr:
                os.dup2(errin, 2)
            self._run_child(cmd)
        os.close(p2cread)
        self.tochild = os.fdopen(p2cwrite, 'w', bufsize)
        os.close(c2pwrite)
        self.fromchild = os.fdopen(c2pread, 'r', bufsize)
        if capturestderr:
            os.close(errin)
            self.childerr = os.fdopen(errout, 'r', bufsize)
        else:
            self.childerr = None 
Example 34
Project: pyblish-win   Author: pyblish   File: popen2.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def popen2(cmd, bufsize=-1, mode='t'):
        """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may
        be a sequence, in which case arguments will be passed directly to the
        program without shell intervention (as with os.spawnv()). If 'cmd' is a
        string it will be passed to the shell (as with os.system()). If
        'bufsize' is specified, it sets the buffer size for the I/O pipes. The
        file objects (child_stdout, child_stdin) are returned."""
        w, r = os.popen2(cmd, mode, bufsize)
        return r, w 
Example 35
Project: pyblish-win   Author: pyblish   File: popen2.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def popen4(cmd, bufsize=-1, mode='t'):
        """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may
        be a sequence, in which case arguments will be passed directly to the
        program without shell intervention (as with os.spawnv()). If 'cmd' is a
        string it will be passed to the shell (as with os.system()). If
        'bufsize' is specified, it sets the buffer size for the I/O pipes. The
        file objects (child_stdout_stderr, child_stdin) are returned."""
        w, r = os.popen4(cmd, mode, bufsize)
        return r, w 
Example 36
Project: pyblish-win   Author: pyblish   File: popen2.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def popen2(cmd, bufsize=-1, mode='t'):
        """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may
        be a sequence, in which case arguments will be passed directly to the
        program without shell intervention (as with os.spawnv()). If 'cmd' is a
        string it will be passed to the shell (as with os.system()). If
        'bufsize' is specified, it sets the buffer size for the I/O pipes. The
        file objects (child_stdout, child_stdin) are returned."""
        inst = Popen3(cmd, False, bufsize)
        return inst.fromchild, inst.tochild 
Example 37
Project: pyblish-win   Author: pyblish   File: popen2.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def popen3(cmd, bufsize=-1, mode='t'):
        """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may
        be a sequence, in which case arguments will be passed directly to the
        program without shell intervention (as with os.spawnv()). If 'cmd' is a
        string it will be passed to the shell (as with os.system()). If
        'bufsize' is specified, it sets the buffer size for the I/O pipes. The
        file objects (child_stdout, child_stdin, child_stderr) are returned."""
        inst = Popen3(cmd, True, bufsize)
        return inst.fromchild, inst.tochild, inst.childerr 
Example 38
Project: pyblish-win   Author: pyblish   File: popen2.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def popen4(cmd, bufsize=-1, mode='t'):
        """Execute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may
        be a sequence, in which case arguments will be passed directly to the
        program without shell intervention (as with os.spawnv()). If 'cmd' is a
        string it will be passed to the shell (as with os.system()). If
        'bufsize' is specified, it sets the buffer size for the I/O pipes. The
        file objects (child_stdout_stderr, child_stdin) are returned."""
        inst = Popen4(cmd, bufsize)
        return inst.fromchild, inst.tochild 
Example 39
Project: pyblish-win   Author: pyblish   File: os.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def popen2(cmd, mode="t", bufsize=-1):
            """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
            may be a sequence, in which case arguments will be passed directly to
            the program without shell intervention (as with os.spawnv()).  If 'cmd'
            is a string it will be passed to the shell (as with os.system()). If
            'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
            file objects (child_stdin, child_stdout) are returned."""
            import warnings
            msg = "os.popen2 is deprecated.  Use the subprocess module."
            warnings.warn(msg, DeprecationWarning, stacklevel=2)

            import subprocess
            PIPE = subprocess.PIPE
            p = subprocess.Popen(cmd, shell=isinstance(cmd, basestring),
                                 bufsize=bufsize, stdin=PIPE, stdout=PIPE,
                                 close_fds=True)
            return p.stdin, p.stdout 
Example 40
Project: pyblish-win   Author: pyblish   File: pydoc.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def getpager():
    """Decide what method to use for paging through text."""
    if type(sys.stdout) is not types.FileType:
        return plainpager
    if not hasattr(sys.stdin, "isatty"):
        return plainpager
    if not sys.stdin.isatty() or not sys.stdout.isatty():
        return plainpager
    if 'PAGER' in os.environ:
        if sys.platform == 'win32': # pipes completely broken in Windows
            return lambda text: tempfilepager(plain(text), os.environ['PAGER'])
        elif os.environ.get('TERM') in ('dumb', 'emacs'):
            return lambda text: pipepager(plain(text), os.environ['PAGER'])
        else:
            return lambda text: pipepager(text, os.environ['PAGER'])
    if os.environ.get('TERM') in ('dumb', 'emacs'):
        return plainpager
    if sys.platform == 'win32' or sys.platform.startswith('os2'):
        return lambda text: tempfilepager(plain(text), 'more <')
    if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
        return lambda text: pipepager(text, 'less')

    import tempfile
    (fd, filename) = tempfile.mkstemp()
    os.close(fd)
    try:
        if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:
            return lambda text: pipepager(text, 'more')
        else:
            return ttypager
    finally:
        os.unlink(filename) 
Example 41
Project: pyblish-win   Author: pyblish   File: pydoc.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def tempfilepager(text, cmd):
    """Page through text by invoking a program on a temporary file."""
    import tempfile
    filename = tempfile.mktemp()
    file = open(filename, 'w')
    file.write(_encode(text))
    file.close()
    try:
        os.system(cmd + ' "' + filename + '"')
    finally:
        os.unlink(filename) 
Example 42
Project: pyblish-win   Author: pyblish   File: mhlib.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test():
    global mh, f
    os.system('rm -rf $HOME/Mail/@test')
    mh = MH()
    def do(s): print s; print eval(s)
    do('mh.listfolders()')
    do('mh.listallfolders()')
    testfolders = ['@test', '@test/test1', '@test/test2',
                   '@test/test1/test11', '@test/test1/test12',
                   '@test/test1/test11/test111']
    for t in testfolders: do('mh.makefolder(%r)' % (t,))
    do('mh.listsubfolders(\'@test\')')
    do('mh.listallsubfolders(\'@test\')')
    f = mh.openfolder('@test')
    do('f.listsubfolders()')
    do('f.listallsubfolders()')
    do('f.getsequences()')
    seqs = f.getsequences()
    seqs['foo'] = IntSet('1-10 12-20', ' ').tolist()
    print seqs
    f.putsequences(seqs)
    do('f.getsequences()')
    for t in reversed(testfolders): do('mh.deletefolder(%r)' % (t,))
    do('mh.getcontext()')
    context = mh.getcontext()
    f = mh.openfolder(context)
    do('f.getcurrent()')
    for seq in ('first', 'last', 'cur', '.', 'prev', 'next',
                'first:3', 'last:3', 'cur:3', 'cur:-3',
                'prev:3', 'next:3',
                '1:3', '1:-3', '100:3', '100:-3', '10000:3', '10000:-3',
                'all'):
        try:
            do('f.parsesequence(%r)' % (seq,))
        except Error, msg:
            print "Error:", msg
        stuff = os.popen("pick %r 2>/dev/null" % (seq,)).read()
        list = map(int, stuff.split())
        print list, "<-- pick" 
Example 43
Project: pyblish-win   Author: pyblish   File: pdb.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def help():
    for dirname in sys.path:
        fullname = os.path.join(dirname, 'pdb.doc')
        if os.path.exists(fullname):
            sts = os.system('${PAGER-more} '+fullname)
            if sts: print '*** Pager exit status:', sts
            break
    else:
        print 'Sorry, can\'t find the help file "pdb.doc"',
        print 'along the Python search path' 
Example 44
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self,cmd,mode='r',bufsize=None):

        if mode != 'r':
            raise ValueError,'popen()-emulation only supports read mode'
        import tempfile
        self.tmpfile = tmpfile = tempfile.mktemp()
        os.system(cmd + ' > %s' % tmpfile)
        self.pipe = open(tmpfile,'rb')
        self.bufsize = bufsize
        self.mode = mode 
Example 45
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _syscmd_ver(system='', release='', version='',

               supported_platforms=('win32','win16','dos','os2')):

    """ 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 suppress 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 
Example 46
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def _platform(*args):

    """ Helper to format the platform string in a filename
        compatible format e.g. "system-version-machine".
    """
    # Format the platform string
    platform = string.join(
        map(string.strip,
            filter(len, args)),
        '-')

    # Cleanup some possible filename obstacles...
    replace = string.replace
    platform = replace(platform,' ','_')
    platform = replace(platform,'/','-')
    platform = replace(platform,'\\','-')
    platform = replace(platform,':','-')
    platform = replace(platform,';','-')
    platform = replace(platform,'"','-')
    platform = replace(platform,'(','-')
    platform = replace(platform,')','-')

    # No need to report 'unknown' information...
    platform = replace(platform,'unknown','')

    # Fold '--'s and remove trailing '-'
    while 1:
        cleaned = replace(platform,'--','-')
        if cleaned == platform:
            break
        platform = cleaned
    while platform[-1] == '-':
        platform = platform[:-1]

    return platform 
Example 47
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def system():

    """ Returns the system/OS name, e.g. 'Linux', 'Windows' or 'Java'.

        An empty string is returned if the value cannot be determined.

    """
    return uname()[0] 
Example 48
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def release():

    """ Returns the system's release, e.g. '2.2.0' or 'NT'

        An empty string is returned if the value cannot be determined.

    """
    return uname()[2] 
Example 49
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def version():

    """ Returns the system's release version, e.g. '#3 on degas'

        An empty string is returned if the value cannot be determined.

    """
    return uname()[3] 
Example 50
Project: pyblish-win   Author: pyblish   File: test_xpickle.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def have_python_version(name):
    """Check whether the given name is a valid Python binary and has
    test.test_support.

    This respects your PATH.

    Args:
        name: short string name of a Python binary such as "python2.4".

    Returns:
        True if the name is valid, False otherwise.
    """
    return os.system(name + " -c 'import test.test_support'") == 0 
Example 51
Project: DnD4py   Author: bacook17   File: setup.py    MIT License 5 votes vote down vote up
def run(self):
        os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info') 
Example 52
Project: GIG   Author: palash25   File: cli.py    MIT License 5 votes vote down vote up
def cli(lang):
    ob = GIG()
    if lang == 'None':
        click.echo(click.style("[INFO] Empty GITIGNORE generated,"
                               "since lang argument is empty.", fg='blue'))
        os.system('touch .gitignore')
    else:
        ob.generate(lang) 
Example 53
Project: convseg   Author: chqiwang   File: cws.py    MIT License 5 votes vote down vote up
def evaluator(data, output_dir, output_flag):
    """
    Evaluate presion, recall and F1.
    """
    seqs, gold_stags, pred_stags = data
    assert len(seqs) == len(gold_stags) == len(pred_stags)
    # Create and open temp files.
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    ref_path = os.path.join(output_dir, '%s.ref' % output_flag)
    pred_path = os.path.join(output_dir, '%s.pred' % output_flag)
    score_path = os.path.join(output_dir, '%s.score' % output_flag)
    # Empty words file.
    temp_path = os.path.join(output_dir, '%s.temp' % output_flag)

    ref_file = codecs.open(ref_path, 'w', 'utf8')
    pred_file = codecs.open(pred_path, 'w', 'utf8')
    for l in create_output(seqs, gold_stags):
        print(l, file=ref_file)
    for i, l in enumerate(create_output(seqs, pred_stags)):
        print(l, file=pred_file)
    ref_file.close()
    pred_file.close()

    os.system('echo > %s' % temp_path)
    os.system('%s  %s %s %s > %s' % ('./score.perl', temp_path, ref_path, pred_path, score_path))
    # Sighan evaluation results
    os.system('tail -n 7 %s > %s' % (score_path, temp_path))
    eval_lines = [l.rstrip() for l in codecs.open(temp_path, 'r', 'utf8')]
    # Remove temp files.
    os.remove(ref_path)
    os.remove(pred_path)
    os.remove(score_path)
    os.remove(temp_path)
    # Precision, Recall and F1 score
    return (float(eval_lines[1].split(':')[1]),
            float(eval_lines[0].split(':')[1]),
            float(eval_lines[2].split(':')[1])) 
Example 54
Project: pyserverchan   Author: GanjinZero   File: pyserver.py    MIT License 5 votes vote down vote up
def __init__(self, url=""):
        path = os.path.expanduser("~") + "/.pyserverchan"
        if url == "":
            if os.path.isfile(path):
                with open(path, 'r') as f:
                    self.url = f.read()
            else:
                print(".pyserverchan doesn\'t exist, please initialize with a url.")
        else:
            self.url = url
            if not os.path.isfile(path):
                os.system("touch ~/.pyserverchan")
            with open(path, 'w') as f:
                f.write(self.url) 
Example 55
Project: AutoDL   Author: tanguofu   File: sync.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def sync(files, dest_dir, dest_host, dest_port='36000', dest_user='root'):
     
     for f in files:
        dest_path = dest_dir + f
        cmd = "scp -P {port} '{files}' '{user}@{ip}:{path}'" \
                  .format(port=dest_port, files=f, user=dest_user, ip=dest_host, path=dest_path)
        ret = os.system(cmd)
        #print("cmd:%s, ret:%d" %(cmd, ret))
        if ret != 0:
           print("copy failed")
           sys.exit(-1) 
Example 56
Project: petuk.corp   Author: fnugrahendi   File: installer.py    GNU General Public License v2.0 5 votes vote down vote up
def InstallBin_Act(self):
		self.aatime.stop()
		archiveBin = self.BasePath+"archive/bin.grvz"
		
		installpath = str(self.le_InstallDir.text())
		if not os.path.exists(installpath): os.makedirs(installpath)
		os.system(self.BasePath+"7z.exe -y x "+archiveBin+" -o"+installpath+" -pnyungsep")
		#~ self.tb_InstallBin_Next.show()
		self.InstallMysql()
		os.makedirs(installpath+"\data") 
Example 57
Project: petuk.corp   Author: fnugrahendi   File: installer.py    GNU General Public License v2.0 5 votes vote down vote up
def InstallMysql_Act(self):
		self.aatime.stop()
		archiveBin = self.BasePath+"archive/mysql32.grvz"
		if self.arc==64:
			archiveBin = self.BasePath+"archive/mysql64.grvz"
			
		
		installpath = str(self.le_InstallDir.text())
		if not os.path.exists(installpath): os.makedirs(installpath)
		os.system(self.BasePath+"7z.exe -y x "+archiveBin+" -o"+installpath+" -pnyungsep")
		self.InstallConfig() 
Example 58
Project: petuk.corp   Author: fnugrahendi   File: installer.py    GNU General Public License v2.0 5 votes vote down vote up
def InstallConfig_MysqlUser(self):
		self.aatime.stop()
		querytambahuser = 	"""	CREATE USER 'gd_user_akunting'@'localhost' IDENTIFIED BY 'nyungsep';
								GRANT ALL PRIVILEGES ON *.* TO 'gd_user_akunting'@'localhost' IDENTIFIED BY 'nyungsep' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
							"""
		f = open("querytambahuser.md","w")
		f.write(querytambahuser)
		f.close()
		print "jalankan",(str(self.le_InstallDir.text())+"\\mysql\\bin\\mysql --port=44559 -u root test < querytambahuser.md")
		os.system(str(self.le_InstallDir.text())+"\\mysql\\bin\\mysql --port=44559 -u root test < querytambahuser.md")
		self.Install_StartMenu() 
Example 59
Project: assignment-maker   Author: harsimrans   File: evaluate.py    GNU General Public License v3.0 5 votes vote down vote up
def clear_compiled_files(path):
    ''' Clears all the output and class files
        generated duruing the evaluation process
    '''
    print "Clearing compiled files generated during evaluating...\n"
    files = os.listdir(path)
    for file in files:
        ext = file.split(".")
        if len(ext) == 1:
            os.system("rm " + path + "/" +  file)
        elif ext[-1] == 'class' or ext[-1] == 'output':
            os.system("rm " + path + "/" +  file) 
Example 60
Project: CACConsole   Author: foospidy   File: CloudAtCostConsole.py    GNU General Public License v2.0 5 votes vote down vote up
def do_bash(self):
		"""bash: Drop to bash shell. Type 'exit' to return to CACConsole"""
		response = os.system('/bin/bash')
				
	### power #################### 
Example 61
Project: ups-utils   Author: Ricks-Lab   File: UPSmodule.py    GNU General Public License v3.0 5 votes vote down vote up
def check_ip(self, tups=None):
        """ check the IP address value for the target UPS or active UPS if target is None.
        :param tups:  The target ups dictionary from list or None.
        :type tups: dict
        :return:  True if the given IP address is pingable, else False
        :rtype: bool
        """
        if not tups:
            tups = self.active_ups
        if not os.system('ping -c 1 {} > /dev/null'.format(tups['ups_IP'])):
            return True
        return False 
Example 62
Project: Lexeme   Author: kdelwat   File: Interface.py    MIT License 5 votes vote down vote up
def clearScreen():
    os.system("cls" if os.name == "nt" else "clear")
    lexeme = """
 _
| |    _____  _____ _ __ ___   ___
| |   / _ \ \/ / _ | '_ ` _ \ / _ |
| |__|  __/>  |  __| | | | | |  __/
|_____\___/_/\_\___|_| |_| |_|\___|
                                                """
    print(lexeme) 
Example 63
Project: Tacotron   Author: ElwynWang   File: build_tr_ev_db.py    GNU General Public License v3.0 5 votes vote down vote up
def file_cp(idx):
	for item in ['wavs', 'mels', 'mags']:
		suffix = 'wav' if item == 'wavs' else 'npy'
		comm = "cp data/all/{0}/{1}.{2} data/{3}/{0}/".format(item, tags[idx], suffix, mode)
		os.system(comm) 
Example 64
Project: django-template   Author: liip   File: post_gen_project.py    MIT License 5 votes vote down vote up
def install_drifter():
    os.system('git init .')
    os.system('curl -sS https://raw.githubusercontent.com/liip/drifter/master/install.sh | /bin/bash') 
Example 65
Project: Turku-neural-parser-pipeline   Author: TurkuNLP   File: train_models.py    Apache License 2.0 5 votes vote down vote up
def train_all(args):

    # tokenizer --- TODO

    # Tagger
    if args.tagger:
        print("Training a tagger", file=sys.stderr)
        status = os.system("python3 {workdir}/../Parser-v2/main.py --save_dir models_{name}/Tagger train --config_file models_{name}/tagger.cfg".format(workdir=thisdir, name=args.name))
        if status != 0:
            print("Tagger status:", status, "Training failed.", file=sys.stderr)
            sys.exit()

    # Parser
    if args.parser:
        print("Training a parser")
        status = os.system("python3 {workdir}/../Parser-v2/main.py --save_dir models_{name}/Parser train --config_file models_{name}/parser.cfg".format(workdir=thisdir, name=args.name))
        if status != 0:
            print("Parser status:", status, "Training failed.", file=sys.stderr)
            sys.exit()

    # Lemmatizer
    if args.lemmatizer == True:
        print("Training a lemmatizer")
        status = os.system("python3 {workdir}/../universal-lemmatizer/train_lemmatizer.py --treebank default --config models_{name}/lemmatizer.yaml".format(workdir=thisdir, name=args.name))
        if status != 0:
            print("Lemmatizer status:", status, "Training failed.", file=sys.stderr)
            sys.exit()

        copy_lemmatizer(args) # copy the latest lemmatizer under correct name

        status = os.system("cat {train} | python3 {workdir}/../build_lemma_cache.py > models_{name}/Lemmatizer/lemma_cache.tsv".format(train=args.train_file, workdir=thisdir, name=args.name)) # build lemma cache
        if status != 0:
            print("Lemma cache status:", status, "Training failed.", file=sys.stderr)
            sys.exit()

    print("Training done", file=sys.stderr) 
Example 66
Project: VisualNN   Author: angelhunt   File: startup.py    GNU General Public License v3.0 5 votes vote down vote up
def run():
    for key, layer in config.config.iteritems():
        os.system('cp ' + BASE_DIR + '/keras_app/custom_layers/' + layer['filename'] + ' '
                  + BASE_DIR + '/media') 
Example 67
Project: VisualNN   Author: angelhunt   File: export_graphdef.py    GNU General Public License v3.0 5 votes vote down vote up
def export_to_tensorflow(request):
    # Note : Remove the views for export by adding unittest for celery tasks
    response = export_json(request, is_tf=True)
    if isinstance(response, JsonResponse):
        return response
    randomId = response['randomId']
    customLayers = response['customLayers']
    os.chdir(BASE_DIR + '/tensorflow_app/views/')
    os.system('KERAS_BACKEND=tensorflow python json2pbtxt.py -input_file ' +
              randomId + '.json -output_file ' + randomId)
    return JsonResponse({'result': 'success',
                         'id': randomId,
                         'name': randomId + '.pbtxt',
                         'url': '/media/' + randomId + '.pbtxt',
                         'customLayers': customLayers}) 
Example 68
Project: RandomFourierFeatures   Author: tiskw   File: download_and_convert_mnist.py    MIT License 5 votes vote down vote up
def download_MNIST(filepath):

    if os.path.exists(filepath):
        print("File '%s' already exists. Skip it." % filepath)
        return

    url = "http://yann.lecun.com/exdb/mnist/%s" % filepath
    cmd = "wget %s ." % url
    os.system(cmd)


### Convert MNIST image data to npy format. 
Example 69
Project: sbo-templates   Author: dslackw   File: main.py    GNU General Public License v3.0 5 votes vote down vote up
def menu(self):
        """Dialog.menu(text, height=None, width=None, menu_height=None,
        choices=[], **kwargs)
        Display a menu dialog box.
        """
        self.__templatesInit()  # reset all data
        code, tag = self.d.menu("Choose an option or press ESC or <Cancel> to "
                                "Exit.", height=20, width=70,
                                menu_height=len(self.choises),
                                choices=self.choises)
        if code == self.d.CANCEL or code == self.d.ESC or tag[0] == "0":
            os.system("clear")
            sys.exit(0)
        case = {
            "Info": self.infoFile,
            "Slack desc": self.slackDesc,
            "Desktop": self.desktopFile,
            "Doinst.sh": self.doinst_sh,
            "SlackBuild": self.SlackBuild,
            "README": self.README,
            "Chmod": self.chmod,
            "Download": self.download,
            "MD5SUM": self.MD5SUM,
            "Maintainer": self.maintainerData,
            "Directory": self.__updateDirectory,
            "Help": self.getHelp,
            "Exit": self.exit,
        }
        case[tag]() 
Example 70
Project: sbo-templates   Author: dslackw   File: main.py    GNU General Public License v3.0 5 votes vote down vote up
def exit(self):
        os.system("clear")
        sys.exit(0) 
Example 71
Project: photometry-sans-frustration   Author: mnicholl   File: psf.py    MIT License 4 votes vote down vote up
def PS1cutouts(ra,dec,filt):

    print('\nSearching for PS1 images of field...\n')

    ps1_url = 'http://ps1images.stsci.edu/cgi-bin/ps1filenames.py?'

    ps1_url += '&ra='+str(ra)
    ps1_url += '&dec='+str(dec)
    ps1_url += '&filters='+filt

    ps1_im = requests.get(ps1_url)

    try:
        image_name = ps1_im.text.split()[16]

        print('Image found: ' + image_name + '\n')

        cutout_url = 'http://ps1images.stsci.edu/cgi-bin/fitscut.cgi?&filetypes=stack&size=2500'

        cutout_url += '&ra='+str(ra)
        cutout_url += '&dec='+str(dec)
        cutout_url += '&filters='+filt
        cutout_url += '&format=fits'
        cutout_url += '&red='+image_name

        dest_file = filt + '_template.fits'

        cmd = 'wget -O %s "%s"' % (dest_file, cutout_url)

        os.system(cmd)

        print('Template downloaded as ' + dest_file + '\n')

    except:
        print('\nPS1 template search failed!\n')


##################################




# Try to match header keyword to a known filter automatically: 
Example 72
Project: pyblish-win   Author: pyblish   File: which.py    GNU Lesser General Public License v3.0 4 votes vote down vote up
def main():
    pathlist = os.environ['PATH'].split(os.pathsep)

    sts = 0
    longlist = ''

    if sys.argv[1:] and sys.argv[1][:2] == '-l':
        longlist = sys.argv[1]
        del sys.argv[1]

    for prog in sys.argv[1:]:
        ident = ()
        for dir in pathlist:
            filename = os.path.join(dir, prog)
            try:
                st = os.stat(filename)
            except os.error:
                continue
            if not S_ISREG(st[ST_MODE]):
                msg(filename + ': not a disk file')
            else:
                mode = S_IMODE(st[ST_MODE])
                if mode & 0111:
                    if not ident:
                        print filename
                        ident = st[:3]
                    else:
                        if st[:3] == ident:
                            s = 'same as: '
                        else:
                            s = 'also: '
                        msg(s + filename)
                else:
                    msg(filename + ': not executable')
            if longlist:
                sts = os.system('ls ' + longlist + ' ' + filename)
                if sts: msg('"ls -l" exit status: ' + repr(sts))
        if not ident:
            msg(prog + ': not found')
            sts = 1

    sys.exit(sts) 
Example 73
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 4 votes vote down vote up
def linux_distribution(distname='', version='', id='',

                       supported_dists=_supported_dists,
                       full_distribution_name=1):

    """ Tries to determine the name of the Linux OS distribution name.

        The function first looks for a distribution release file in
        /etc and then reverts to _dist_try_harder() in case no
        suitable files are found.

        supported_dists may be given to define the set of Linux
        distributions to look for. It defaults to a list of currently
        supported Linux distributions identified by their release file
        name.

        If full_distribution_name is true (default), the full
        distribution read from the OS is returned. Otherwise the short
        name taken from supported_dists is used.

        Returns a tuple (distname,version,id) which default to the
        args given as parameters.

    """
    try:
        etc = os.listdir('/etc')
    except os.error:
        # Probably not a Unix system
        return distname,version,id
    etc.sort()
    for file in etc:
        m = _release_filename.match(file)
        if m is not None:
            _distname,dummy = m.groups()
            if _distname in supported_dists:
                distname = _distname
                break
    else:
        return _dist_try_harder(distname,version,id)

    # Read the first line
    f = open('/etc/'+file, 'r')
    firstline = f.readline()
    f.close()
    _distname, _version, _id = _parse_release_file(firstline)

    if _distname and full_distribution_name:
        distname = _distname
    if _version:
        version = _version
    if _id:
        id = _id
    return distname, version, id

# To maintain backwards compatibility: 
Example 74
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 4 votes vote down vote up
def system_alias(system,release,version):

    """ Returns (system,release,version) aliased to common
        marketing names used for some systems.

        It also does some reordering of the information in some cases
        where it would otherwise cause confusion.

    """
    if system == 'Rhapsody':
        # Apple's BSD derivative
        # XXX How can we determine the marketing release number ?
        return 'MacOS X Server',system+release,version

    elif system == 'SunOS':
        # Sun's OS
        if release < '5':
            # These releases use the old name SunOS
            return system,release,version
        # Modify release (marketing release = SunOS release - 3)
        l = string.split(release,'.')
        if l:
            try:
                major = int(l[0])
            except ValueError:
                pass
            else:
                major = major - 3
                l[0] = str(major)
                release = string.join(l,'.')
        if release < '6':
            system = 'Solaris'
        else:
            # XXX Whatever the new SunOS marketing name is...
            system = 'Solaris'

    elif system == 'IRIX64':
        # IRIX reports IRIX64 on platforms with 64-bit support; yet it
        # is really a version and not a different platform, since 32-bit
        # apps are also supported..
        system = 'IRIX'
        if version:
            version = version + ' (64bit)'
        else:
            version = '64bit'

    elif system in ('win32','win16'):
        # In case one of the other tricks
        system = 'Windows'

    return system,release,version

### Various internal helpers 
Example 75
Project: pyblish-win   Author: pyblish   File: platform.py    GNU Lesser General Public License v3.0 4 votes vote down vote up
def _syscmd_file(target,default=''):

    """ Interface to the system's file command.

        The function uses the -b option of the file command to have it
        ommit the filename in its output and if possible the -L option
        to have the command follow symlinks. It returns default in
        case the command should fail.

    """

    # We do the import here to avoid a bootstrap issue.
    # See c73b90b6dadd changeset.
    #
    # [..]
    # ranlib libpython2.7.a
    # gcc   -o python \
    #        Modules/python.o \
    #        libpython2.7.a -lsocket -lnsl -ldl    -lm
    # Traceback (most recent call last):
    #  File "./setup.py", line 8, in <module>
    #    from platform import machine as platform_machine
    #  File "[..]/build/Lib/platform.py", line 116, in <module>
    #    import sys,string,os,re,subprocess
    #  File "[..]/build/Lib/subprocess.py", line 429, in <module>
    #    import select
    # ImportError: No module named select

    import subprocess

    if sys.platform in ('dos','win32','win16','os2'):
        # XXX Others too ?
        return default
    target = _follow_symlinks(target)
    try:
        proc = subprocess.Popen(['file', target],
                stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

    except (AttributeError,os.error):
        return default
    output = proc.communicate()[0]
    rc = proc.wait()
    if not output or rc:
        return default
    else:
        return output

### Information about the used architecture

# Default values for architecture; non-empty strings override the
# defaults given as parameters 
Example 76
Project: prediction-constrained-topic-models   Author: dtak   File: utils_snapshots.py    MIT License 4 votes vote down vote up
def download_snapshot(
        snapshot_path=None,
        rsync_path=None,
        local_path=None,
        remote_path=None,
        ):
    if local_path is None:
        try:
            local_path = os.environ['XHOST_LOCAL_PATH']
        except KeyError:
            raise ValueError("Bad value for local_path: %s" % local_path)
    if remote_path is None:
        try:
            remote_path = os.environ['XHOST_REMOTE_PATH']
        except KeyError:
            raise ValueError("Bad value for remote_path: %s" % remote_path)
    if rsync_path is None:
        try:
            rsync_path = os.environ['XHOST_RSYNC_PATH']
        except KeyError:
            rsync_path = os.path.expandvars("$PC_REPO_DIR/scripts/rsync_tools/")
    if not os.path.exists(rsync_path):
        raise ValueError("Bad value for rsync_path: %s" % rsync_path)

    local_path = os.path.abspath(local_path)
    remote_path = os.path.abspath(remote_path)
    if snapshot_path.count(local_path):
        local_snapshot_path = snapshot_path
        remote_snapshot_path = snapshot_path.replace(local_path, remote_path)
    elif snapshot_path.count(remote_path):
        remote_snapshot_path = snapshot_path
        local_snapshot_path = snapshot_path.replace(remote_path, local_path)
    else:
        raise ValueError("Bad snapshot_path:\n%s" % snapshot_path)

    old_path = os.getcwd()
    print("cd %s" % rsync_path)
    os.chdir(rsync_path)
    cmd_str = "bash rsync_specific_snapshot.sh %s" % remote_snapshot_path
    print("ATTEMPTING DOWNLOAD via CUSTOM RSYNC CMD:")
    print(cmd_str)
    ans = os.system(cmd_str)
    print("cd %s" % old_path)
    os.chdir(old_path)
    if int(str(ans)) != 0:
        raise ValueError("BAD DOWNLOAD: ANSWER CODE %s" % ans)
    return True 
Example 77
Project: ssh-aad   Author: TheNetworg   File: ssh-aad_pam.py    MIT License 4 votes vote down vote up
def pam_sm_authenticate(pamh, flags, argv):
    """
    pam_python implementation of the pam_sm_authenticate method of PAM modules
    This function handles and returns the authentication of a PAM module
    :param pamh: PAM handle from python_pam module
    :param flags: configuration flags given to the module
    :param argv: arguments given to the PAM module in pam.d configuration
    :return: flag indicating the success or error of the authentication
    """
    try:
        local_username = get_local_username(pamh)
        # DEBUG
        # local_username = 'hajekj'
        if local_username == '':
            return pamh.PAM_USER_UNKNOWN
        
        username = local_username
        usernameParts = username.split('@')
        usernameSanitized = '_'.join(usernameParts)

        alias = None
        domain = None
        if len(usernameParts) == 2:
            alias = usernameParts[0]
            domain = usernameParts[1]
        else:
            # Username is not UPN, fail PAM authentication.
            return pamh.PAM_USER_UNKNOWN
        
        cnf = load_config(DEFAULT_GLOBAL_CONFIG_PATH)
        setup_adal(cnf)

        code = get_device_code(cnf)

        pamh.conversation(pamh.Message(4, str(code['message'])))
        pamh.conversation(pamh.Message(pamh.PAM_PROMPT_ECHO_ON, '<Press ENTER once finished>'))

        token = wait_for_token(code, cnf)

        if username != token['userId']:
            # Username coming from AAD is different from the supplied username
            return pamh.PAM_USER_UNKNOWN

        try:
            pwd.getpwnam(username)
        except KeyError:
            log('user doesn\'t exist create new')
            # https://askubuntu.com/questions/94060/run-adduser-non-interactively
            os.system('adduser --disabled-password --gecos "" --force-badname '+username)
            os.system('addgroup --force-badname '+username+' sudo')

        # TODO: Check if user exists, if not, create one

        if pamh is not None:
            if token is not None:
                return pamh.PAM_SUCCESS
            else:
                return pamh.PAM_USER_UNKNOWN
    except Exception as e:
        print ('Exception found:', e)
        log(str(e)) 
Example 78
Project: assignment-maker   Author: harsimrans   File: evaluate.py    GNU General Public License v3.0 4 votes vote down vote up
def compile_files(path, filename):
    ''' Compiles and runs user solution and tells
        if the output matches the master solution

        returns
            True: If the files match
            False: If the output files don't match
    '''
    name, extension = filename.split(".")
    print "Compiling: ", filename

    if extension == 'c':
        input_file = os.path.join(path, filename)
        output_file = os.path.join(path, name)

        command = COMPILE_C + ' ' + input_file + " -o " + output_file
        os.system(command)

        command = output_file + " < " + os.path.join(os.path.abspath(MASTER_INPUT),  name + ".input") + " > " + os.path.join(os.path.abspath(USER_SOLUTIONS), name + ".output")
        os.system(command)

        # compare the output
        return filecmp.cmp(os.path.join(os.path.abspath(MASTER_SOLUTION) , name + ".output"),  os.path.join(os.path.abspath(USER_SOLUTIONS) , name + ".output"), shallow=False)


    elif extension == 'cpp':
        input_file = os.path.join(path, filename)
        output_file = os.path.join(path, name)

        command = COMPILE_CPP + ' ' + input_file + " -o " + output_file
        os.system(command)

        command = output_file + " < " + os.path.join(os.path.abspath(MASTER_INPUT),  name + ".input") + " > " + os.path.join(os.path.abspath(USER_SOLUTIONS), name + ".output")
        os.system(command)

        # compare the output
        return filecmp.cmp(os.path.join(os.path.abspath(MASTER_SOLUTION) , name + ".output"),  os.path.join(os.path.abspath(USER_SOLUTIONS) , name + ".output"), shallow=False)


    elif extension == 'java':
        input_file = os.path.join(path, filename)
        output_file = os.path.join(path, name)

        command = COMPILE_JAVA + ' ' + input_file
        os.system(command)

        command = RUN_JAVA + " -cp " + path + " " + name + " < " + os.path.join(os.path.abspath(MASTER_INPUT) , name + ".input") + " > " + os.path.join(os.path.abspath(USER_SOLUTIONS) , name + ".output")
        os.system(command)

        # compare the output
        return filecmp.cmp(os.path.join(os.path.abspath(MASTER_SOLUTION) , name + ".output"),  os.path.join(os.path.abspath(USER_SOLUTIONS) , name + ".output"), shallow=False)

    else:
        print "Unsupported file format"
        return False 
Example 79
Project: VisualNN   Author: angelhunt   File: views.py    GNU General Public License v3.0 4 votes vote down vote up
def start_training(request):
    if request.method == 'GET':
        try:
            print("start training...")
            home_path = os.environ['HOME']
            # get current model path
            index_file_path = home_path + "/VisualNN/media/randomIndex.txt"
            f = open(index_file_path, 'r')
            cur_model_name = f.readlines()[-1][:-1] + '.json'
            model_path = home_path + "/VisualNN/media/" + cur_model_name
            print("Current model file path: %s"%(model_path))

            # get current data file path
            data_index_file_path = home_path + "/.VisualNN/data/dataIndex.txt"
            ff = open(data_index_file_path, 'r')
            cur_data_file_name = ff.readlines()[-1][:-1]
            data_path = home_path + "/.VisualNN/data/" + cur_data_file_name
            print("Current data file path: %s"%(data_path))

            # get result file path
            result_path = home_path + "/.VisualNN/result"
            folder = os.path.exists(result_path)
            if not folder:
                os.makedirs(result_path)
            result_file_path = result_path + "/" + cur_data_file_name.split(".")[0] + ".h5"
            print("Current result file path: %s"%(result_file_path))

            #command = "python run.py"
            #command = "python train.py ~/.VisualNN/model/mnist.json ~/.VisualNN/data/mnist.npz result.h5"
            #os.system(command)
            
            # call training function 
            Train.trainModel(model_path, data_path, result_file_path)

            return JsonResponse({
                'result': 'success'
            })
        except Exception, e:
            print("Error in start training!")
            return JsonResponse({
                'result': 'error',
                'error': 'Fail to start training'
            }) 
Example 80
Project: django-rest-polymorphic   Author: apirobot   File: setup.py    MIT License 3 votes vote down vote up
def run(self):
        try:
            self.status('Removing previous builds…')
            rmtree(os.path.join(here, 'dist'))
        except OSError:
            pass

        self.status('Building Source and Wheel (universal) distribution…')
        os.system('{0} setup.py sdist bdist_wheel --universal'.format(
            sys.executable
        ))

        self.status('Uploading the package to PyPi via Twine…')
        os.system('twine upload dist/*')

        sys.exit()