Giter VIP home page Giter VIP logo

pushy's Introduction

What?

Pushy is an RPC (Remote Procedure Call) package for Python and Java. The key feature of Pushy is that it only requires Python and an SSH daemon on the "server". You don't need to install anything on the remote machine, which makes Pushy useful for controlling remote systems without installing custom software on them.

The core of Pushy is written in and for Python, and a Java API is provided that sits on top of this. The Java API allows developers to write Java code that interacts local or remote Python (plain old CPython, not Jython) interpreters, providing Java abstractions around Python modules, that will be more familiar to Java developers.

How?

First, install Pushy by one of several methods:

  • Using pip: pip install pushy
  • Grab the source archive from the PyPI page, and run the usual: python setup.py install
  • Java users only: Grab the jar file for Java and add it to your classpath. It's self-contained (Java and Python code together.)

Python Example

Now you're ready to create a Pushy connection. In the example below, we create a connection to a remote machine and list the directories in the home directory of the user 'me'. In accessing an attribute of a connection's "modules", you are effectively "importing" the remote module of that name. A proxy to that module is returned, and from then on you can (more or less) treat the module as if it were locally defined.

import pushy
    
with pushy.connect("ssh:remotehost", username="me", password="password") as conn:
    for (root,dirs,files) in conn.modules.os.walk("."):
        for d in dirs:
            print conn.modules.os.path.join(root, d)
        for f in files:
            print conn.modules.os.path.join(root, f)

Java Example

To do this from a Java program, you write code very similar to how you would if you were writing it for the local machine. The Pushy Java API provides a means of interrogating the remote system's properties, using a similar API to java.lang.System. This can be used to obtain the current working directory; with that in hand, pushy.io.File can be used in a similar way as java.io.File to list files.

import pushy.io.File;
import java.util.Properties;

public class ListFiles {
    public static void main(String[] args) throws Exception {
        Properties props = new Properties();
        props.setProperty("username", "me");
        props.setProperty("password", "password");
        pushy.Client client = new pushy.Client("ssh:remotehost", props);
        try {
            pushy.RemoteSystem system = client.getSystem();
            String cwd = system.getProperty("user.dir");
            java.io.File dir = new pushy.io.File(client, cwd);
            for (java.io.File file : dir.listFiles()) {
                System.out.println(file);
            }
        } finally {
            client.close();
        }
    }
}

Documentation

Further documentation can be found at http://packages.python.org/pushy/. If you can't find what you're looking for, please create an Issue.

pushy's People

Contributors

axw avatar alfredodeza avatar bendavis78 avatar

Watchers

James Cloos avatar acba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.