Skip to content

Commit

Permalink
Feet is now a rust program. This is for the bootloader, which unpacks…
Browse files Browse the repository at this point in the history
… the runtime. PyInstaller is no longer used.
  • Loading branch information
ironfroggy committed May 26, 2019
1 parent 003c0d0 commit befc62e
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 6 deletions.
136 changes: 136 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "feet"
version = "0.1.0"
authors = ["Calvin Spealman <ironfroggy@gmail.com>"]
edition = "2018"

[dependencies]
zip = "0.5.2"

[[bin]]
name = "feet"
path = "feet.rs"
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ FEET is a runner for Python. What does that mean?

It makes it easy to create Python scripts, programs, applications, or games
and package them up to send to friends, users, players, or whomever you want
to share your work with. FEET is really just a wrapper around the excellent
PyInstaller project and it is *mostly* for Windows users, because they have
the hardest time sharing Python code.
to share your work with. FEET is currently being built for Windows, but Linux
and Mac versions will hopefully arrive in the future!

FEET is just an executable, called `feet.exe`, that sits in a folder beside
your script that you name `main.py`. You can zip up this folder and send it
Expand All @@ -16,12 +15,19 @@ or package anything.

Just send them your files and the runner.

When users run your program via `feet.exe` the first time, it will unpack a
runtime to a `feet/` sub-folder. You can remove this at any time, especially
before zipping your program to share.

Note: Feet is a prototype, but please let me know if you find it useful and
file issues for any improvements that you feel would help make it less of an
experiment and more of a real thing.

## BUILDING

FEET includes a bootloader written in rust. Make sure you have a recent version
of the Rust compiler and Cargo tool installed.

To build feet, install the build dependencies and then run the build script.

pip install -r requirements.txt
Expand Down Expand Up @@ -85,5 +91,5 @@ Python Feet is a prototype. It definitely has bugs and will definitely have
breaking changes. However, if you find it useful, that's great! If you find
problems with it or if you want to help, please file issues on the [Github
page](https://github.com/ironfroggy/feet/issues) with all the details you
can include, or find me on Twitter [@ironfroggy](https://twitter.com/ironfroggy) to thank, complain to, or discuss Python
with.
can include, or find me on Twitter [@ironfroggy](https://twitter.com/ironfroggy)
to thank, complain to, or discuss Python with.
90 changes: 90 additions & 0 deletions feet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use std::env;
use std::process::{Command, Stdio};
use std::io::{BufRead, BufReader, Error, ErrorKind};
// use std::io::Error;
use std::path::Path;
use std::io;
use std::fs;

use std::io::{Seek, Read};
use zip::result::ZipResult;
use zip::read::{ZipFile, ZipArchive};
// use zip::write::{FileOptions, ZipWriter};
use std::fs::File;

fn browse_zip_archive<T, F, U>(buf: &mut T, browse_func: F) -> ZipResult<Vec<U>>
where T: Read + Seek,
F: Fn(&ZipFile) -> ZipResult<U>
{
let mut archive = ZipArchive::new(buf)?;
(0..archive.len())
.map(|i| archive.by_index(i).and_then(|file| browse_func(&file)))
.collect()
}

fn main() -> Result<(), Error> {
// let mut file = File::open("example.zip").expect("Couldn't open file");
// let files = browse_zip_archive(&mut file, |f| {
// Ok(format!("{}: {} -> {}", f.name(), f.size(), f.compressed_size()))
// });
// println!("{:?}", files);

if (!Path::new("./feet/").exists()) {
// let archive_path = "feetruntime.zip";
let archive_path = "./feet.exe";
let file = fs::File::open(&archive_path).unwrap();
let mut archive = zip::ZipArchive::new(file).unwrap();

for i in 0..archive.len() {
let mut file = archive.by_index(i).unwrap();
let outpath = file.sanitized_name();

{
let comment = file.comment();
if !comment.is_empty() {
println!("File {} comment: {}", i, comment);
}
}

if (&*file.name()).ends_with('/') {
println!("File {} extracted to \"{}\"", i, outpath.as_path().display());
fs::create_dir_all(&outpath).unwrap();
} else {
println!("File {} extracted to \"{}\" ({} bytes)", i, outpath.as_path().display(), file.size());
if let Some(p) = outpath.parent() {
if !p.exists() {
fs::create_dir_all(&p).unwrap();
}
}
let mut outfile = fs::File::create(&outpath).unwrap();
io::copy(&mut file, &mut outfile).unwrap();
}

// Get and Set permissions
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;

if let Some(mode) = file.unix_mode() {
fs::set_permissions(&outpath, fs::Permissions::from_mode(mode)).unwrap();
}
}
}
}

// Now, runtime is either extracted or already was, so run the commands

let mut args: Vec<String> = env::args().collect();
args.remove(0);

let mut child = Command::new("./feet/cpython/python")
.arg("./feet/feet.py")
.args(args)
.stderr(Stdio::inherit())
.stdout(Stdio::inherit())
.stdin(Stdio::inherit())
.spawn()?;

child.wait();
Ok(())
}
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

30 changes: 30 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import setuptools

with open("README.md", "r", encoding='utf8') as f:
long_description = f.read()

setuptools.setup(
name="feet",
version="0.0.3",
author="Calvin Spealman",
author_email="ironfroggy@gmail.com",
description="Feet makes Python run",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/ironfroggy/feet",
modules=['feetmaker'],
entry_points = {
'console_scripts': [
'mkfeet=feetmaker:main',
],
},
install_requires=[
'requirements-parser',
# 'pip==19.1.1',
],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: Windows",
],
)

0 comments on commit befc62e

Please sign in to comment.