Forum Archive

Hello m building a terminal emulator. And i wanna make my own pip script to install modules and libraries , but idnt knw how, can anyone help me?

MustaphaBen

iwanna make a simple script to download modules and libraries for my terminal emulator , if anyone could help that well very nice. thanks.

ccc

See pip.py in https://github.com/ywangd/stash

MustaphaBen

i knw but I dont know? how to put it on my script
look this is my code

import requests, urllib, urllib3, os, dialogs, ui, console
import sys, editor
import runpy


path = '/private/var/mobile/Containers/Shared/AppGroup/DDCB5D2A-91C1-4B79-BA39-E31DE9BF50C0/Pythonista3/Documents/'

def calcul():
  print("Calculator verion 0.0.1")

  n1 = int(input("num1: "))
  n2 = int(input("num2: "))

  print("Please enter a valid number")

  choices = ["x","/","+","-"]
  print(choices)
  choice = input("enter the operator : ")

  if choice == "x":
    result = n1 * n2
    print(result)
  if choice == "/":
    res = n1 / n2
    print(res)
  if choice == "-":
    re = n1-n2
    print(re)
  if choice == "+":
    r = n1+n2
    print(r)



def quick_note():
  note = dialogs.text_dialog()
  console.alert("Would you save this note.", "If you wanna save this note click 'ok' ", "ok")
  editor.make_new_file('note.txt',note)


def cpff():
  print("""cpf 
  copy any file with CPF version : 0.2

  """)
  file_name = input("file name: ")
  #if u wanna copy the file the sheller must be in the exact path of the file or change the file to the sheller directory then copy it
  dir_path = os.path.dirname(os.path.realpath(__file__))
  files = os.listdir(dir_path)
  for file in files:
    if file == file_name:
      o = open(file_name, 'r')
      content = o.read()
      new_name = "cpf-"+file_name
      editor.make_new_file(new_name, content)

#First make the setup
def simple_commands():
  print('''
  [?/$heller] Shell with no Experience
  1. make-folders
  2. create-file
  3. remove files
  4. cpf | copy files (only files)
  5. python3 ( name of the file )
  6. Calc ( a simple calculator with only 2 num )

  ''')
  while True:

    command = input(f'''[$heller] ''')

    if command == '1':
      fname = input("Folder name : ")
      os.makedirs(fname)
      console.hud_alert('Folder created')

    if command == '2':
      file_name = input("File name : ")

      content = dialogs.text_dialog('content')        
      editor.make_new_file(file_name, content)
      console.hud_alert('File created')


    if command == "exit":
      sys.exit()

    if command == '3':
      try:
        name = input("File-Folder name : ")
        os.remove(name)
        console.hud_alert('File removed')
      except:
        print("Error this file-folder does not exist in this directory")
        pass
    if command == 'clear':
      console.clear()  
    if command == "note":
      quick_note()
    if command == '4':
      cpff()
    try:
      if command == 'cd '+command.split(" ")[1]:
        d_name = command.split(" ")[1]
        p = path+d_name
        os.chdir(p)
    except:
      pass
    if command == 'cd?':
      current_directory = os.getcwd()
      print(current_directory)
    if command == 'ls':



      for subdir, dirs, files in os.walk('./'):
        for file in files:
          print(file)
    if command == "6":
      calcul()

    try:
      if command == 'python3 '+command.split(" ")[1]:
        file_path = command.split(" ")[1]
        runpy.run_path(file_path, run_name='__main__')
      else:
        pass
    except:
      pass


version = '0.0.3'
def setup():
  print(f"\nWelcome to sheller {version} its a new shell for pythonista its better than stash or shellista.")
  simple_commands()


def check():
  if sys.version[0] == 2:
    print("sorry you can't use this programme\n your current version is python",sys.version[0])
  else:
    setup()

check()





cvp

@MustaphaBen Sorry, I don't understand. Do you want that your script it-self downloads some module? If yes, from where?

MustaphaBen

look bro m making a terminal emulator just like stash.
I wanna make a script that download libraries from the pypi just like pip . i saw the pip.py file in stash but i dont know how to put it on my script

cvp

@MustaphaBen but if you want to use pip of stash, why not use stash completely ?

I did not check pip.py but if it-self uses other stash modules, thus....

MustaphaBen

right . i need to make my own pip but can you help me or can you give me ur email to contact you if ur interested

cvp

@MustaphaBen never private email in This forum but there are some stash specialists here, I hope they could help you. But I never has heard that somebody used stash modules outside of stash it-self.

MustaphaBen

hhhh lol. thanks man.

JonB

@MustaphaBen I think you are going to have a hard time making something "better" than stash. If you have improvements, submit a pull request.

Lots of thought went into stash's threading and user interface. You are not going to reproduce tab completion, history, etc using input. Various folks worked around various pythonista limitations to get a working pip. Etc.

If you are interested in this just as an exercise, that's cool. However, writing command line utilities should be done using the cmd module -- otherwise your code will quickly deteriorate into a giant morass of if/elif statements that will be impossible to read and harder to debug.

MustaphaBen

m doing this just for fun " better than stash " that was just a comment

JonB

Ok.

Seriously consider reading about thecmd module. It makes adding commands much easier.

To run external scripts, like pip.py, the runpy module let's you "run" a file. stash's pip as I recall makes use of some modified other modules (setuptools I think), so probably won't work out of the box.

MustaphaBen

Thank You, ofc ill read abt the cmd module